Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(250175)

Side by Side Diff: Lib/test/test_compile.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_compileall.py ('k') | Lib/test/test_complex.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 import sys 2 import sys
3 import _ast 3 import _ast
4 import types 4 import types
5 from test import support 5 from test import support
6 6
7 class TestSpecifics(unittest.TestCase): 7 class TestSpecifics(unittest.TestCase):
8 8
9 def compile_single(self, source): 9 def compile_single(self, source):
10 compile(source, "<single>", "single") 10 compile(source, "<single>", "single")
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 ['<assign>', 'x = 5'], 415 ['<assign>', 'x = 5'],
416 ['<ifblock>', """if True:\n pass\n"""], 416 ['<ifblock>', """if True:\n pass\n"""],
417 ['<forblock>', """for n in [1, 2, 3]:\n print(n)\n"""], 417 ['<forblock>', """for n in [1, 2, 3]:\n print(n)\n"""],
418 ['<deffunc>', """def foo():\n pass\nfoo()\n"""], 418 ['<deffunc>', """def foo():\n pass\nfoo()\n"""],
419 [fname, fcontents], 419 [fname, fcontents],
420 ] 420 ]
421 421
422 for fname, code in sample_code: 422 for fname, code in sample_code:
423 co1 = compile(code, '%s1' % fname, 'exec') 423 co1 = compile(code, '%s1' % fname, 'exec')
424 ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST) 424 ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST)
425 self.assertTrue(type(ast) == _ast.Module) 425 self.assertEqual(type(ast), _ast.Module)
426 co2 = compile(ast, '%s3' % fname, 'exec') 426 co2 = compile(ast, '%s3' % fname, 'exec')
427 self.assertEqual(co1, co2) 427 self.assertEqual(co1, co2)
428 # the code object's filename comes from the second compilation step 428 # the code object's filename comes from the second compilation step
429 self.assertEqual(co2.co_filename, '%s3' % fname) 429 self.assertEqual(co2.co_filename, '%s3' % fname)
430 430
431 # raise exception when node type doesn't match with compile mode 431 # raise exception when node type doesn't match with compile mode
432 co1 = compile('print(1)', '<string>', 'exec', _ast.PyCF_ONLY_AST) 432 co1 = compile('print(1)', '<string>', 'exec', _ast.PyCF_ONLY_AST)
433 self.assertRaises(TypeError, compile, co1, '<ast>', 'eval') 433 self.assertRaises(TypeError, compile, co1, '<ast>', 'eval')
434 434
435 # raise exception when node type is no start node 435 # raise exception when node type is no start node
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 check_limit("a", ".b") 499 check_limit("a", ".b")
500 check_limit("a", "[0]") 500 check_limit("a", "[0]")
501 check_limit("a", "*a") 501 check_limit("a", "*a")
502 502
503 503
504 def test_main(): 504 def test_main():
505 support.run_unittest(TestSpecifics) 505 support.run_unittest(TestSpecifics)
506 506
507 if __name__ == "__main__": 507 if __name__ == "__main__":
508 test_main() 508 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_compileall.py ('k') | Lib/test/test_complex.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+