Changeset 391 for python/trunk/Lib/test/test_compile.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_compile.py
r2 r391 3 3 import _ast 4 4 from test import test_support 5 import textwrap 5 6 6 7 class TestSpecifics(unittest.TestCase): 8 9 def test_no_ending_newline(self): 10 compile("hi", "<test>", "exec") 11 compile("hi\r", "<test>", "exec") 12 13 def test_empty(self): 14 compile("", "<test>", "exec") 15 16 def test_other_newlines(self): 17 compile("\r\n", "<test>", "exec") 18 compile("\r", "<test>", "exec") 19 compile("hi\r\nstuff\r\ndef f():\n pass\r", "<test>", "exec") 20 compile("this_is\rreally_old_mac\rdef f():\n pass", "<test>", "exec") 7 21 8 22 def test_debug_assignment(self): … … 47 61 except SyntaxError: 48 62 pass 63 64 def test_exec_functional_style(self): 65 # Exec'ing a tuple of length 2 works. 66 g = {'b': 2} 67 exec("a = b + 1", g) 68 self.assertEqual(g['a'], 3) 69 70 # As does exec'ing a tuple of length 3. 71 l = {'b': 3} 72 g = {'b': 5, 'c': 7} 73 exec("a = b + c", g, l) 74 self.assertNotIn('a', g) 75 self.assertEqual(l['a'], 10) 76 77 # Tuples not of length 2 or 3 are invalid. 78 with self.assertRaises(TypeError): 79 exec("a = b + 1",) 80 81 with self.assertRaises(TypeError): 82 exec("a = b + 1", {}, {}, {}) 83 84 # Can't mix and match the two calling forms. 85 g = {'a': 3, 'b': 4} 86 l = {} 87 with self.assertRaises(TypeError): 88 exec("a = b + 1", g) in g 89 with self.assertRaises(TypeError): 90 exec("a = b + 1", g, l) in g, l 49 91 50 92 def test_exec_with_general_mapping_for_locals(self): … … 130 172 def test_complex_args(self): 131 173 174 with test_support.check_py3k_warnings( 175 ("tuple parameter unpacking has been removed", SyntaxWarning)): 176 exec textwrap.dedent(''' 132 177 def comp_args((a, b)): 133 178 return a,b … … 147 192 self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3)) 148 193 self.assertEqual(comp_args(), (2, 3, 4)) 194 ''') 149 195 150 196 def test_argument_order(self): … … 235 281 else: 236 282 self.fail("How many bits *does* this machine have???") 237 # Verify treatment of con tant folding on -(sys.maxint+1)283 # Verify treatment of constant folding on -(sys.maxint+1) 238 284 # i.e. -2147483648 on 32 bit platforms. Should return int, not long. 239 self.assert True(isinstance(eval("%s" % (-sys.maxint - 1)), int))240 self.assert True(isinstance(eval("%s" % (-sys.maxint - 2)), long))285 self.assertIsInstance(eval("%s" % (-sys.maxint - 1)), int) 286 self.assertIsInstance(eval("%s" % (-sys.maxint - 2)), long) 241 287 242 288 if sys.maxint == 9223372036854775807: … … 253 299 for variable in self.test_32_63_bit_values.func_code.co_consts: 254 300 if variable is not None: 255 self.assert True(isinstance(variable, int))301 self.assertIsInstance(variable, int) 256 302 257 303 def test_sequence_unpacking_error(self): … … 271 317 'for None in range(10): pass', 272 318 'def f(None): pass', 319 'import None', 320 'import x as None', 321 'from x import None', 322 'from x import y as None' 273 323 ] 274 324 for stmt in stmts: … … 276 326 self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single') 277 327 self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') 328 # This is ok. 329 compile("from None import x", "tmp", "exec") 330 compile("from x import None as y", "tmp", "exec") 331 compile("import None as x", "tmp", "exec") 278 332 279 333 def test_import(self): … … 333 387 self.assertNotEqual(id(f1.func_code), id(f2.func_code)) 334 388 389 def test_lambda_doc(self): 390 l = lambda: "foo" 391 self.assertIsNone(l.__doc__) 392 335 393 def test_unicode_encoding(self): 336 394 code = u"# -*- coding: utf-8 -*-\npass\n" … … 358 416 self.assertEqual(d[1], 2) 359 417 del d[1] 360 self.assert Equal(1 in d, False)418 self.assertNotIn(1, d) 361 419 # Tuple of indices 362 420 d[1, 1] = 1 … … 365 423 self.assertEqual(d[1, 1], 2) 366 424 del d[1, 1] 367 self.assert Equal((1, 1) in d, False)425 self.assertNotIn((1, 1), d) 368 426 # Simple slice 369 427 d[1:2] = 1 … … 372 430 self.assertEqual(d[1:2], 2) 373 431 del d[1:2] 374 self.assert Equal(slice(1, 2) in d, False)432 self.assertNotIn(slice(1, 2), d) 375 433 # Tuple of simple slices 376 434 d[1:2, 1:2] = 1 … … 379 437 self.assertEqual(d[1:2, 1:2], 2) 380 438 del d[1:2, 1:2] 381 self.assert Equal((slice(1, 2), slice(1, 2)) in d, False)439 self.assertNotIn((slice(1, 2), slice(1, 2)), d) 382 440 # Extended slice 383 441 d[1:2:3] = 1 … … 386 444 self.assertEqual(d[1:2:3], 2) 387 445 del d[1:2:3] 388 self.assert Equal(slice(1, 2, 3) in d, False)446 self.assertNotIn(slice(1, 2, 3), d) 389 447 # Tuple of extended slices 390 448 d[1:2:3, 1:2:3] = 1 … … 393 451 self.assertEqual(d[1:2:3, 1:2:3], 2) 394 452 del d[1:2:3, 1:2:3] 395 self.assert Equal((slice(1, 2, 3), slice(1, 2, 3)) in d, False)453 self.assertNotIn((slice(1, 2, 3), slice(1, 2, 3)), d) 396 454 # Ellipsis 397 455 d[...] = 1 … … 400 458 self.assertEqual(d[...], 2) 401 459 del d[...] 402 self.assert Equal(Ellipsis in d, False)460 self.assertNotIn(Ellipsis, d) 403 461 # Tuple of Ellipses 404 462 d[..., ...] = 1 … … 407 465 self.assertEqual(d[..., ...], 2) 408 466 del d[..., ...] 409 self.assert Equal((Ellipsis, Ellipsis) in d, False)467 self.assertNotIn((Ellipsis, Ellipsis), d) 410 468 411 469 def test_mangling(self): … … 417 475 import __package__.module 418 476 419 self.assert _("_A__mangled" inA.f.func_code.co_varnames)420 self.assert _("__not_mangled__" inA.f.func_code.co_varnames)421 self.assert _("_A__mangled_mod" inA.f.func_code.co_varnames)422 self.assert _("__package__" inA.f.func_code.co_varnames)477 self.assertIn("_A__mangled", A.f.func_code.co_varnames) 478 self.assertIn("__not_mangled__", A.f.func_code.co_varnames) 479 self.assertIn("_A__mangled_mod", A.f.func_code.co_varnames) 480 self.assertIn("__package__", A.f.func_code.co_varnames) 423 481 424 482 def test_compile_ast(self): … … 443 501 co1 = compile(code, '%s1' % fname, 'exec') 444 502 ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST) 445 self.assert _(type(ast) == _ast.Module)503 self.assertTrue(type(ast) == _ast.Module) 446 504 co2 = compile(ast, '%s3' % fname, 'exec') 447 505 self.assertEqual(co1, co2)
Note:
See TracChangeset
for help on using the changeset viewer.