Neal Norwitz | cd3e219 | 2006-01-23 07:49:36 +0000 | [diff] [blame] | 1 | from test import test_support |
Jeremy Hylton | 5e7cb24 | 2001-02-02 18:24:26 +0000 | [diff] [blame] | 2 | |
Neal Norwitz | 89886ab | 2005-11-25 03:15:49 +0000 | [diff] [blame] | 3 | import symtable |
Neal Norwitz | cd3e219 | 2006-01-23 07:49:36 +0000 | [diff] [blame] | 4 | import unittest |
Jeremy Hylton | 5e7cb24 | 2001-02-02 18:24:26 +0000 | [diff] [blame] | 5 | |
Jeremy Hylton | 5e7cb24 | 2001-02-02 18:24:26 +0000 | [diff] [blame] | 6 | |
Jeremy Hylton | bc2a62f | 2005-10-20 14:27:21 +0000 | [diff] [blame] | 7 | ## XXX |
| 8 | ## Test disabled because symtable module needs to be rewritten for new compiler |
Jeremy Hylton | 42d9016 | 2003-07-15 20:24:27 +0000 | [diff] [blame] | 9 | |
Jeremy Hylton | bc2a62f | 2005-10-20 14:27:21 +0000 | [diff] [blame] | 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 |
Neal Norwitz | cd3e219 | 2006-01-23 07:49:36 +0000 | [diff] [blame] | 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() |