|
1 from test import test_support |
|
2 |
|
3 import symtable |
|
4 import unittest |
|
5 |
|
6 |
|
7 ## XXX |
|
8 ## Test disabled because symtable module needs to be rewritten for new compiler |
|
9 |
|
10 ##vereq(symbols[0].name, "global") |
|
11 ##vereq(len([ste for ste in symbols.values() if ste.name == "f"]), 1) |
|
12 |
|
13 ### Bug tickler: SyntaxError file name correct whether error raised |
|
14 ### while parsing or building symbol table. |
|
15 ##def checkfilename(brokencode): |
|
16 ## try: |
|
17 ## _symtable.symtable(brokencode, "spam", "exec") |
|
18 ## except SyntaxError, e: |
|
19 ## vereq(e.filename, "spam") |
|
20 ## else: |
|
21 ## raise TestFailed("no SyntaxError for %r" % (brokencode,)) |
|
22 ##checkfilename("def f(x): foo)(") # parse-time |
|
23 ##checkfilename("def f(x): global x") # symtable-build-time |
|
24 |
|
25 class SymtableTest(unittest.TestCase): |
|
26 def test_invalid_args(self): |
|
27 self.assertRaises(TypeError, symtable.symtable, "42") |
|
28 self.assertRaises(ValueError, symtable.symtable, "42", "?", "") |
|
29 |
|
30 def test_eval(self): |
|
31 symbols = symtable.symtable("42", "?", "eval") |
|
32 |
|
33 def test_single(self): |
|
34 symbols = symtable.symtable("42", "?", "single") |
|
35 |
|
36 def test_exec(self): |
|
37 symbols = symtable.symtable("def f(x): return x", "?", "exec") |
|
38 |
|
39 |
|
40 def test_main(): |
|
41 test_support.run_unittest(SymtableTest) |
|
42 |
|
43 if __name__ == '__main__': |
|
44 test_main() |