Brett Cannon | 6192df1 | 2008-05-10 02:58:26 +0000 | [diff] [blame] | 1 | import test.test_support |
| 2 | compiler = test.test_support.import_module('compiler', deprecated=True) |
Neil Schemenauer | f369470 | 2005-06-02 05:55:20 +0000 | [diff] [blame] | 3 | from compiler.ast import flatten |
Neal Norwitz | 07c6071 | 2006-04-13 06:34:59 +0000 | [diff] [blame] | 4 | import os, sys, time, unittest |
Raymond Hettinger | ed20ad8 | 2004-09-04 20:09:13 +0000 | [diff] [blame] | 5 | from random import random |
Eric Smith | 14cae96 | 2008-03-19 03:13:34 +0000 | [diff] [blame] | 6 | from StringIO import StringIO |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 7 | |
Neal Norwitz | 07c6071 | 2006-04-13 06:34:59 +0000 | [diff] [blame] | 8 | # How much time in seconds can pass before we print a 'Still working' message. |
| 9 | _PRINT_WORKING_MSG_INTERVAL = 5 * 60 |
| 10 | |
Georg Brandl | ab49684 | 2007-01-27 17:43:02 +0000 | [diff] [blame] | 11 | class TrivialContext(object): |
| 12 | def __enter__(self): |
| 13 | return self |
| 14 | def __exit__(self, *exc_info): |
| 15 | pass |
| 16 | |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 17 | class CompilerTest(unittest.TestCase): |
| 18 | |
| 19 | def testCompileLibrary(self): |
| 20 | # A simple but large test. Compile all the code in the |
| 21 | # standard library and its test suite. This doesn't verify |
| 22 | # that any of the code is correct, merely the compiler is able |
| 23 | # to generate some kind of code for it. |
Tim Peters | 2841af4 | 2006-01-07 23:20:46 +0000 | [diff] [blame] | 24 | |
Neal Norwitz | 07c6071 | 2006-04-13 06:34:59 +0000 | [diff] [blame] | 25 | next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL |
Ezio Melotti | 7999dea | 2010-04-02 21:43:10 +0000 | [diff] [blame] | 26 | # warning: if 'os' or 'test_support' are moved in some other dir, |
| 27 | # they should be changed here. |
| 28 | libdir = os.path.dirname(os.__file__) |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 29 | testdir = os.path.dirname(test.test_support.__file__) |
| 30 | |
Benjamin Peterson | 72949bd | 2012-02-20 22:33:33 -0500 | [diff] [blame] | 31 | for dir in [testdir]: |
| 32 | for basename in "test_os.py",: |
Neal Norwitz | 07c6071 | 2006-04-13 06:34:59 +0000 | [diff] [blame] | 33 | # Print still working message since this test can be really slow |
| 34 | if next_time <= time.time(): |
| 35 | next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL |
| 36 | print >>sys.__stdout__, \ |
| 37 | ' testCompileLibrary still working, be patient...' |
Neal Norwitz | dd28d1c | 2006-04-28 04:34:43 +0000 | [diff] [blame] | 38 | sys.__stdout__.flush() |
Neal Norwitz | 07c6071 | 2006-04-13 06:34:59 +0000 | [diff] [blame] | 39 | |
Tim Peters | 2a5f656 | 2004-08-08 16:37:37 +0000 | [diff] [blame] | 40 | if not basename.endswith(".py"): |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 41 | continue |
Guido van Rossum | 5bde08d | 2006-03-02 04:24:01 +0000 | [diff] [blame] | 42 | if not TEST_ALL and random() < 0.98: |
Raymond Hettinger | ed20ad8 | 2004-09-04 20:09:13 +0000 | [diff] [blame] | 43 | continue |
Tim Peters | 2a5f656 | 2004-08-08 16:37:37 +0000 | [diff] [blame] | 44 | path = os.path.join(dir, basename) |
Tim Peters | b6ecc16 | 2004-08-08 16:32:54 +0000 | [diff] [blame] | 45 | if test.test_support.verbose: |
Tim Peters | 2a5f656 | 2004-08-08 16:37:37 +0000 | [diff] [blame] | 46 | print "compiling", path |
Michael W. Hudson | 29589a0 | 2004-10-11 15:34:31 +0000 | [diff] [blame] | 47 | f = open(path, "U") |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 48 | buf = f.read() |
| 49 | f.close() |
Neal Norwitz | f895065 | 2005-10-24 00:01:37 +0000 | [diff] [blame] | 50 | if "badsyntax" in basename or "bad_coding" in basename: |
Tim Peters | 0955f29 | 2004-08-08 16:43:59 +0000 | [diff] [blame] | 51 | self.assertRaises(SyntaxError, compiler.compile, |
| 52 | buf, basename, "exec") |
| 53 | else: |
Martin v. Löwis | 15bfc3b | 2006-03-01 21:11:49 +0000 | [diff] [blame] | 54 | try: |
| 55 | compiler.compile(buf, basename, "exec") |
| 56 | except Exception, e: |
Martin v. Löwis | d9bfeac | 2006-03-01 23:24:34 +0000 | [diff] [blame] | 57 | args = list(e.args) |
Christian Heimes | c5f05e4 | 2008-02-23 17:40:11 +0000 | [diff] [blame] | 58 | args.append("in file %s]" % basename) |
| 59 | #args[0] += "[in file %s]" % basename |
Martin v. Löwis | d9bfeac | 2006-03-01 23:24:34 +0000 | [diff] [blame] | 60 | e.args = tuple(args) |
Martin v. Löwis | 15bfc3b | 2006-03-01 21:11:49 +0000 | [diff] [blame] | 61 | raise |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 62 | |
Brett Cannon | f418991 | 2005-04-09 02:30:16 +0000 | [diff] [blame] | 63 | def testNewClassSyntax(self): |
| 64 | compiler.compile("class foo():pass\n\n","<string>","exec") |
Tim Peters | e890682 | 2005-04-20 17:45:13 +0000 | [diff] [blame] | 65 | |
Guido van Rossum | 5bde08d | 2006-03-02 04:24:01 +0000 | [diff] [blame] | 66 | def testYieldExpr(self): |
| 67 | compiler.compile("def g(): yield\n\n", "<string>", "exec") |
| 68 | |
Amaury Forgeot d'Arc | 67f24f1 | 2008-08-20 00:08:47 +0000 | [diff] [blame] | 69 | def testKeywordAfterStarargs(self): |
| 70 | def f(*args, **kwargs): |
| 71 | self.assertEqual((args, kwargs), ((2,3), {'x': 1, 'y': 4})) |
| 72 | c = compiler.compile('f(x=1, *(2, 3), y=4)', '<string>', 'exec') |
| 73 | exec c in {'f': f} |
| 74 | |
| 75 | self.assertRaises(SyntaxError, compiler.parse, "foo(a=1, b)") |
| 76 | self.assertRaises(SyntaxError, compiler.parse, "foo(1, *args, 3)") |
| 77 | |
Georg Brandl | f57c54d | 2006-06-22 14:46:46 +0000 | [diff] [blame] | 78 | def testTryExceptFinally(self): |
| 79 | # Test that except and finally clauses in one try stmt are recognized |
Ezio Melotti | dde5b94 | 2010-02-03 05:37:26 +0000 | [diff] [blame] | 80 | c = compiler.compile("try:\n 1//0\nexcept:\n e = 1\nfinally:\n f = 1", |
Georg Brandl | f57c54d | 2006-06-22 14:46:46 +0000 | [diff] [blame] | 81 | "<string>", "exec") |
| 82 | dct = {} |
| 83 | exec c in dct |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 84 | self.assertEqual(dct.get('e'), 1) |
| 85 | self.assertEqual(dct.get('f'), 1) |
Georg Brandl | f57c54d | 2006-06-22 14:46:46 +0000 | [diff] [blame] | 86 | |
Georg Brandl | 1bb6230 | 2006-05-03 18:18:32 +0000 | [diff] [blame] | 87 | def testDefaultArgs(self): |
| 88 | self.assertRaises(SyntaxError, compiler.parse, "def foo(a=1, b): pass") |
| 89 | |
Georg Brandl | edd9b0d | 2006-07-29 09:33:26 +0000 | [diff] [blame] | 90 | def testDocstrings(self): |
| 91 | c = compiler.compile('"doc"', '<string>', 'exec') |
Ezio Melotti | aa98058 | 2010-01-23 23:04:36 +0000 | [diff] [blame] | 92 | self.assertIn('__doc__', c.co_names) |
Georg Brandl | edd9b0d | 2006-07-29 09:33:26 +0000 | [diff] [blame] | 93 | c = compiler.compile('def f():\n "doc"', '<string>', 'exec') |
| 94 | g = {} |
| 95 | exec c in g |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 96 | self.assertEqual(g['f'].__doc__, "doc") |
Georg Brandl | edd9b0d | 2006-07-29 09:33:26 +0000 | [diff] [blame] | 97 | |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 98 | def testLineNo(self): |
| 99 | # Test that all nodes except Module have a correct lineno attribute. |
| 100 | filename = __file__ |
Georg Brandl | b2afe85 | 2006-06-09 20:43:48 +0000 | [diff] [blame] | 101 | if filename.endswith((".pyc", ".pyo")): |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 102 | filename = filename[:-1] |
| 103 | tree = compiler.parseFile(filename) |
| 104 | self.check_lineno(tree) |
| 105 | |
| 106 | def check_lineno(self, node): |
| 107 | try: |
| 108 | self._check_lineno(node) |
| 109 | except AssertionError: |
| 110 | print node.__class__, node.lineno |
| 111 | raise |
| 112 | |
| 113 | def _check_lineno(self, node): |
| 114 | if not node.__class__ in NOLINENO: |
Ezio Melotti | b0f5adc | 2010-01-24 16:58:36 +0000 | [diff] [blame] | 115 | self.assertIsInstance(node.lineno, int, |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 116 | "lineno=%s on %s" % (node.lineno, node.__class__)) |
Benjamin Peterson | 5c8da86 | 2009-06-30 22:57:08 +0000 | [diff] [blame] | 117 | self.assertTrue(node.lineno > 0, |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 118 | "lineno=%s on %s" % (node.lineno, node.__class__)) |
| 119 | for child in node.getChildNodes(): |
| 120 | self.check_lineno(child) |
| 121 | |
Neil Schemenauer | f369470 | 2005-06-02 05:55:20 +0000 | [diff] [blame] | 122 | def testFlatten(self): |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 123 | self.assertEqual(flatten([1, [2]]), [1, 2]) |
| 124 | self.assertEqual(flatten((1, (2,))), [1, 2]) |
Neil Schemenauer | f369470 | 2005-06-02 05:55:20 +0000 | [diff] [blame] | 125 | |
Neil Schemenauer | 06ded09 | 2006-08-04 16:20:30 +0000 | [diff] [blame] | 126 | def testNestedScope(self): |
| 127 | c = compiler.compile('def g():\n' |
| 128 | ' a = 1\n' |
| 129 | ' def f(): return a + 2\n' |
| 130 | ' return f()\n' |
| 131 | 'result = g()', |
| 132 | '<string>', |
| 133 | 'exec') |
| 134 | dct = {} |
| 135 | exec c in dct |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 136 | self.assertEqual(dct.get('result'), 3) |
Neil Schemenauer | 06ded09 | 2006-08-04 16:20:30 +0000 | [diff] [blame] | 137 | |
Neil Schemenauer | 4c6b0d5 | 2006-08-16 23:38:05 +0000 | [diff] [blame] | 138 | def testGenExp(self): |
| 139 | c = compiler.compile('list((i,j) for i in range(3) if i < 3' |
| 140 | ' for j in range(4) if j > 2)', |
| 141 | '<string>', |
| 142 | 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 143 | self.assertEqual(eval(c), [(0, 3), (1, 3), (2, 3)]) |
Neil Schemenauer | 4c6b0d5 | 2006-08-16 23:38:05 +0000 | [diff] [blame] | 144 | |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 145 | def testSetLiteral(self): |
| 146 | c = compiler.compile('{1, 2, 3}', '<string>', 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 147 | self.assertEqual(eval(c), {1,2,3}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 148 | c = compiler.compile('{1, 2, 3,}', '<string>', 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 149 | self.assertEqual(eval(c), {1,2,3}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 150 | |
| 151 | def testDictLiteral(self): |
| 152 | c = compiler.compile('{1:2, 2:3, 3:4}', '<string>', 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 153 | self.assertEqual(eval(c), {1:2, 2:3, 3:4}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 154 | c = compiler.compile('{1:2, 2:3, 3:4,}', '<string>', 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 155 | self.assertEqual(eval(c), {1:2, 2:3, 3:4}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 156 | |
| 157 | def testSetComp(self): |
| 158 | c = compiler.compile('{x for x in range(1, 4)}', '<string>', 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 159 | self.assertEqual(eval(c), {1, 2, 3}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 160 | c = compiler.compile('{x * y for x in range(3) if x != 0' |
| 161 | ' for y in range(4) if y != 0}', |
| 162 | '<string>', |
| 163 | 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 164 | self.assertEqual(eval(c), {1, 2, 3, 4, 6}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 165 | |
| 166 | def testDictComp(self): |
| 167 | c = compiler.compile('{x:x+1 for x in range(1, 4)}', '<string>', 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 168 | self.assertEqual(eval(c), {1:2, 2:3, 3:4}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 169 | c = compiler.compile('{(x, y) : y for x in range(2) if x != 0' |
| 170 | ' for y in range(3) if y != 0}', |
| 171 | '<string>', |
| 172 | 'eval') |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 173 | self.assertEqual(eval(c), {(1, 2): 2, (1, 1): 1}) |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 174 | |
Georg Brandl | ab49684 | 2007-01-27 17:43:02 +0000 | [diff] [blame] | 175 | def testWith(self): |
| 176 | # SF bug 1638243 |
| 177 | c = compiler.compile('from __future__ import with_statement\n' |
| 178 | 'def f():\n' |
| 179 | ' with TrivialContext():\n' |
| 180 | ' return 1\n' |
| 181 | 'result = f()', |
| 182 | '<string>', |
| 183 | 'exec' ) |
| 184 | dct = {'TrivialContext': TrivialContext} |
| 185 | exec c in dct |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 186 | self.assertEqual(dct.get('result'), 1) |
Georg Brandl | ab49684 | 2007-01-27 17:43:02 +0000 | [diff] [blame] | 187 | |
| 188 | def testWithAss(self): |
| 189 | c = compiler.compile('from __future__ import with_statement\n' |
| 190 | 'def f():\n' |
| 191 | ' with TrivialContext() as tc:\n' |
| 192 | ' return 1\n' |
| 193 | 'result = f()', |
| 194 | '<string>', |
| 195 | 'exec' ) |
| 196 | dct = {'TrivialContext': TrivialContext} |
| 197 | exec c in dct |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 198 | self.assertEqual(dct.get('result'), 1) |
Georg Brandl | ab49684 | 2007-01-27 17:43:02 +0000 | [diff] [blame] | 199 | |
Georg Brandl | 944f684 | 2009-05-25 21:02:56 +0000 | [diff] [blame] | 200 | def testWithMult(self): |
| 201 | events = [] |
| 202 | class Ctx: |
| 203 | def __init__(self, n): |
| 204 | self.n = n |
| 205 | def __enter__(self): |
| 206 | events.append(self.n) |
| 207 | def __exit__(self, *args): |
| 208 | pass |
| 209 | c = compiler.compile('from __future__ import with_statement\n' |
| 210 | 'def f():\n' |
| 211 | ' with Ctx(1) as tc, Ctx(2) as tc2:\n' |
| 212 | ' return 1\n' |
| 213 | 'result = f()', |
| 214 | '<string>', |
| 215 | 'exec' ) |
| 216 | dct = {'Ctx': Ctx} |
| 217 | exec c in dct |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 218 | self.assertEqual(dct.get('result'), 1) |
| 219 | self.assertEqual(events, [1, 2]) |
Georg Brandl | 944f684 | 2009-05-25 21:02:56 +0000 | [diff] [blame] | 220 | |
Neil Schemenauer | f8741ea | 2009-02-07 18:35:16 +0000 | [diff] [blame] | 221 | def testGlobal(self): |
| 222 | code = compiler.compile('global x\nx=1', '<string>', 'exec') |
| 223 | d1 = {'__builtins__': {}} |
| 224 | d2 = {} |
| 225 | exec code in d1, d2 |
| 226 | # x should be in the globals dict |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 227 | self.assertEqual(d1.get('x'), 1) |
Tim Peters | b1ccc4d | 2006-08-04 22:00:35 +0000 | [diff] [blame] | 228 | |
Eric Smith | 14cae96 | 2008-03-19 03:13:34 +0000 | [diff] [blame] | 229 | def testPrintFunction(self): |
| 230 | c = compiler.compile('from __future__ import print_function\n' |
| 231 | 'print("a", "b", sep="**", end="++", ' |
| 232 | 'file=output)', |
| 233 | '<string>', |
| 234 | 'exec' ) |
| 235 | dct = {'output': StringIO()} |
| 236 | exec c in dct |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 237 | self.assertEqual(dct['output'].getvalue(), 'a**b++') |
Eric Smith | 14cae96 | 2008-03-19 03:13:34 +0000 | [diff] [blame] | 238 | |
Martin v. Löwis | a513619 | 2007-09-04 14:19:28 +0000 | [diff] [blame] | 239 | def _testErrEnc(self, src, text, offset): |
| 240 | try: |
| 241 | compile(src, "", "exec") |
| 242 | except SyntaxError, e: |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 243 | self.assertEqual(e.offset, offset) |
| 244 | self.assertEqual(e.text, text) |
Martin v. Löwis | a513619 | 2007-09-04 14:19:28 +0000 | [diff] [blame] | 245 | |
| 246 | def testSourceCodeEncodingsError(self): |
| 247 | # Test SyntaxError with encoding definition |
| 248 | sjis = "print '\x83\x70\x83\x43\x83\x5c\x83\x93', '\n" |
| 249 | ascii = "print '12345678', '\n" |
| 250 | encdef = "#! -*- coding: ShiftJIS -*-\n" |
| 251 | |
| 252 | # ascii source without encdef |
| 253 | self._testErrEnc(ascii, ascii, 19) |
| 254 | |
| 255 | # ascii source with encdef |
| 256 | self._testErrEnc(encdef+ascii, ascii, 19) |
| 257 | |
| 258 | # non-ascii source with encdef |
| 259 | self._testErrEnc(encdef+sjis, sjis, 19) |
| 260 | |
| 261 | # ShiftJIS source without encdef |
| 262 | self._testErrEnc(sjis, sjis, 19) |
| 263 | |
| 264 | |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 265 | NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard) |
| 266 | |
| 267 | ############################################################################### |
| 268 | # code below is just used to trigger some possible errors, for the benefit of |
| 269 | # testLineNo |
| 270 | ############################################################################### |
| 271 | |
| 272 | class Toto: |
| 273 | """docstring""" |
| 274 | pass |
| 275 | |
| 276 | a, b = 2, 3 |
| 277 | [c, d] = 5, 6 |
| 278 | l = [(x, y) for x, y in zip(range(5), range(5,10))] |
| 279 | l[0] |
| 280 | l[3:4] |
Georg Brandl | f57c54d | 2006-06-22 14:46:46 +0000 | [diff] [blame] | 281 | d = {'a': 2} |
| 282 | d = {} |
Alexandre Vassalotti | b646547 | 2010-01-11 22:36:12 +0000 | [diff] [blame] | 283 | d = {x: y for x, y in zip(range(5), range(5,10))} |
| 284 | s = {x for x in range(10)} |
Alexandre Vassalotti | ee936a2 | 2010-01-09 23:35:54 +0000 | [diff] [blame] | 285 | s = {1} |
Georg Brandl | f57c54d | 2006-06-22 14:46:46 +0000 | [diff] [blame] | 286 | t = () |
| 287 | t = (1, 2) |
| 288 | l = [] |
| 289 | l = [1, 2] |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 290 | if l: |
| 291 | pass |
| 292 | else: |
| 293 | a, b = b, a |
| 294 | |
| 295 | try: |
| 296 | print yo |
| 297 | except: |
| 298 | yo = 3 |
| 299 | else: |
| 300 | yo += 3 |
Tim Peters | 0e9980f | 2004-09-12 03:49:31 +0000 | [diff] [blame] | 301 | |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 302 | try: |
| 303 | a += b |
| 304 | finally: |
| 305 | b = 0 |
Tim Peters | 0e9980f | 2004-09-12 03:49:31 +0000 | [diff] [blame] | 306 | |
Michael W. Hudson | e0b855f | 2004-11-08 16:46:02 +0000 | [diff] [blame] | 307 | from math import * |
| 308 | |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame] | 309 | ############################################################################### |
| 310 | |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 311 | def test_main(): |
Raymond Hettinger | ed20ad8 | 2004-09-04 20:09:13 +0000 | [diff] [blame] | 312 | global TEST_ALL |
Antoine Pitrou | d989f82 | 2010-10-14 15:43:25 +0000 | [diff] [blame] | 313 | TEST_ALL = test.test_support.is_resource_enabled("cpu") |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 314 | test.test_support.run_unittest(CompilerTest) |
| 315 | |
| 316 | if __name__ == "__main__": |
| 317 | test_main() |