blob: 74a7c8559a66699db9f4137b975a564b4d53e6c6 [file] [log] [blame]
Neal Norwitzcd3e2192006-01-23 07:49:36 +00001from test import test_support
Jeremy Hylton5e7cb242001-02-02 18:24:26 +00002
Neal Norwitz89886ab2005-11-25 03:15:49 +00003import symtable
Neal Norwitzcd3e2192006-01-23 07:49:36 +00004import unittest
Jeremy Hylton5e7cb242001-02-02 18:24:26 +00005
Jeremy Hylton5e7cb242001-02-02 18:24:26 +00006
Jeremy Hyltonbc2a62f2005-10-20 14:27:21 +00007## XXX
8## Test disabled because symtable module needs to be rewritten for new compiler
Jeremy Hylton42d90162003-07-15 20:24:27 +00009
Jeremy Hyltonbc2a62f2005-10-20 14:27:21 +000010##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 Norwitzcd3e2192006-01-23 07:49:36 +000024
25class 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
40def test_main():
41 test_support.run_unittest(SymtableTest)
42
43if __name__ == '__main__':
44 test_main()