changeset: 73754:2be3a2e63683 branch: 3.2 parent: 73751:fa59b3758b14 user: Meador Inge date: Fri Nov 25 23:36:48 2011 -0600 files: Lib/test/test_py_compile.py description: Issue #12618: create unit tests for the py_compile module diff -r fa59b3758b14 -r 2be3a2e63683 Lib/test/test_py_compile.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_py_compile.py Fri Nov 25 23:36:48 2011 -0600 @@ -0,0 +1,42 @@ +import imp +import os +import py_compile +import shutil +import tempfile +import unittest + +from test import support, script_helper + +class PyCompileTests(unittest.TestCase): + + def setUp(self): + self.directory = tempfile.mkdtemp() + self.source_path = os.path.join(self.directory, '_test.py') + self.pyc_path = self.source_path + 'c' + self.cache_path = imp.cache_from_source(self.source_path) + with open(self.source_path, 'w') as file: + file.write('x = 123\n') + + def tearDown(self): + shutil.rmtree(self.directory) + + def test_absolute_path(self): + py_compile.compile(self.source_path, self.pyc_path) + self.assertTrue(os.path.exists(self.pyc_path)) + self.assertFalse(os.path.exists(self.cache_path)) + + def test_cache_path(self): + py_compile.compile(self.source_path) + self.assertTrue(os.path.exists(self.cache_path)) + + def test_relative_path(self): + py_compile.compile(os.path.relpath(self.source_path), + os.path.relpath(self.pyc_path)) + self.assertTrue(os.path.exists(self.pyc_path)) + self.assertFalse(os.path.exists(self.cache_path)) + +def test_main(): + support.run_unittest(PyCompileTests) + +if __name__ == "__main__": + test_main()

AltStyle によって変換されたページ (->オリジナル) /