Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 1 | import compiler |
| 2 | import os |
| 3 | import test.test_support |
| 4 | import unittest |
| 5 | |
| 6 | class CompilerTest(unittest.TestCase): |
| 7 | |
| 8 | def testCompileLibrary(self): |
| 9 | # A simple but large test. Compile all the code in the |
| 10 | # standard library and its test suite. This doesn't verify |
| 11 | # that any of the code is correct, merely the compiler is able |
| 12 | # to generate some kind of code for it. |
| 13 | |
| 14 | libdir = os.path.dirname(unittest.__file__) |
| 15 | testdir = os.path.dirname(test.test_support.__file__) |
| 16 | |
| 17 | for dir in [libdir, testdir]: |
Tim Peters | 2a5f656 | 2004-08-08 16:37:37 +0000 | [diff] [blame] | 18 | for basename in os.listdir(dir): |
| 19 | if not basename.endswith(".py"): |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 20 | continue |
Tim Peters | 2a5f656 | 2004-08-08 16:37:37 +0000 | [diff] [blame] | 21 | path = os.path.join(dir, basename) |
Tim Peters | b6ecc16 | 2004-08-08 16:32:54 +0000 | [diff] [blame] | 22 | if test.test_support.verbose: |
Tim Peters | 2a5f656 | 2004-08-08 16:37:37 +0000 | [diff] [blame] | 23 | print "compiling", path |
| 24 | f = open(path) |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 25 | buf = f.read() |
| 26 | f.close() |
Tim Peters | 0955f29 | 2004-08-08 16:43:59 +0000 | [diff] [blame] | 27 | if "badsyntax" in basename: |
| 28 | self.assertRaises(SyntaxError, compiler.compile, |
| 29 | buf, basename, "exec") |
| 30 | else: |
| 31 | compiler.compile(buf, basename, "exec") |
Jeremy Hylton | 4336eda | 2004-08-07 19:25:33 +0000 | [diff] [blame] | 32 | |
| 33 | def test_main(): |
| 34 | test.test_support.requires("compiler") |
| 35 | test.test_support.run_unittest(CompilerTest) |
| 36 | |
| 37 | if __name__ == "__main__": |
| 38 | test_main() |