cpython/Lib/test/test_compiler.py
Tim Peters b6ecc165f2 In verbose mode, display the name of each file before trying to compile
it.  Else when this fails, there's no way to tell which file it was
chewing on.
2004-08-08 16:32:54 +00:00

34 lines
1.1 KiB
Python

import compiler
import os
import test.test_support
import unittest
class CompilerTest(unittest.TestCase):
def testCompileLibrary(self):
# A simple but large test. Compile all the code in the
# standard library and its test suite. This doesn't verify
# that any of the code is correct, merely the compiler is able
# to generate some kind of code for it.
libdir = os.path.dirname(unittest.__file__)
testdir = os.path.dirname(test.test_support.__file__)
for dir in [libdir, testdir]:
for path in os.listdir(dir):
if not path.endswith(".py"):
continue
fpath = os.path.join(dir, path)
if test.test_support.verbose:
print "compiling", fpath
f = open(fpath)
buf = f.read()
f.close()
compiler.compile(buf, path, "exec")
def test_main():
test.test_support.requires("compiler")
test.test_support.run_unittest(CompilerTest)
if __name__ == "__main__":
test_main()