summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2011-11-26 05:40:53 (GMT)
committerMeador Inge <meadori@gmail.com>2011-11-26 05:40:53 (GMT)
commit261a6d7c21c82e00c4a872ab7cabbcd8d419f7db (patch)
tree53aee71421b087b4711db909e8c248f11ec050e2 /Lib
parent4bc45b7a9f5fc849ee13699e3da8d483188fe90b (diff)
parent6f16660ca7f813f47bcc2462a8517819b7b76f5c (diff)
downloadcpython-261a6d7c21c82e00c4a872ab7cabbcd8d419f7db.zip
cpython-261a6d7c21c82e00c4a872ab7cabbcd8d419f7db.tar.gz
cpython-261a6d7c21c82e00c4a872ab7cabbcd8d419f7db.tar.bz2
Issue #12618: create unit tests for the py_compile module
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_py_compile.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
new file mode 100644
index 0000000..7491587
--- /dev/null
+++ b/Lib/test/test_py_compile.py
@@ -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()