diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-06-30 15:01:21 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-06-30 15:01:21 (GMT) |
commit | ec19d95f5152701fee9fa249dc60f98718dd99d7 (patch) | |
tree | 8ac1948f79d5b9216eb166d30fd73896c8baf3ec /Lib/test/test_compile.py | |
parent | 9aa04c4e83fed2cb9615b97049caf65c8e38f724 (diff) | |
download | cpython-ec19d95f5152701fee9fa249dc60f98718dd99d7.zip cpython-ec19d95f5152701fee9fa249dc60f98718dd99d7.tar.gz cpython-ec19d95f5152701fee9fa249dc60f98718dd99d7.tar.bz2 |
now that exec is a function, we can use the shorter assertRaises to test
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r-- | Lib/test/test_compile.py | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 2462269..2b978eb 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -18,21 +18,9 @@ class TestSpecifics(unittest.TestCase): self.assertRaises(SyntaxError, eval, 'lambda a,a:0') self.assertRaises(SyntaxError, eval, 'lambda a,a=1:0') self.assertRaises(SyntaxError, eval, 'lambda a=1,a=1:0') - try: - exec('def f(a, a): pass') - self.fail("duplicate arguments") - except SyntaxError: - pass - try: - exec('def f(a = 0, a = 1): pass') - self.fail("duplicate keyword arguments") - except SyntaxError: - pass - try: - exec('def f(a): global a; a = 1') - self.fail("variable is global and local") - except SyntaxError: - pass + self.assertRaises(SyntaxError, exec, 'def f(a, a): pass') + self.assertRaises(SyntaxError, exec, 'def f(a = 0, a = 1): pass') + self.assertRaises(SyntaxError, exec, 'def f(a): global a; a = 1') def test_syntax_error(self): self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec") @@ -41,11 +29,7 @@ class TestSpecifics(unittest.TestCase): self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec") def test_duplicate_global_local(self): - try: - exec('def f(a): global a; a = 1') - self.fail("variable is global and local") - except SyntaxError: - pass + self.assertRaises(SyntaxError, exec, 'def f(a): global a; a = 1') def test_exec_with_general_mapping_for_locals(self): @@ -76,23 +60,13 @@ class TestSpecifics(unittest.TestCase): self.assertEqual(m.results, ('z', g)) exec('z = locals()', g, m) self.assertEqual(m.results, ('z', m)) - try: - exec('z = b', m) - except TypeError: - pass - else: - self.fail('Did not validate globals as a real dict') + self.assertRaises(TypeError, exec, 'z = b', m) class A: "Non-mapping" pass m = A() - try: - exec('z = a', g, m) - except TypeError: - pass - else: - self.fail('Did not validate locals as a mapping') + self.assertRaises(TypeError, exec, 'z = a', g, m) # Verify that dict subclasses work as well class D(dict): @@ -129,11 +103,7 @@ def f(x): self.assertEqual(g['f'](5), 0) def test_argument_order(self): - try: - exec('def f(a=1, b): pass') - self.fail("non-default args after default") - except SyntaxError: - pass + self.assertRaises(SyntaxError, exec, 'def f(a=1, b): pass') def test_float_literals(self): # testing bad float literals |