[Jython-checkins] jython: Move testing of compileall into Python regrtest
jim.baker
jython-checkins at python.org
Wed Feb 11 21:49:29 CET 2015
https://hg.python.org/jython/rev/d40cb4d16450
changeset: 7581:d40cb4d16450
user: Jim Baker <jim.baker at rackspace.com>
date: Wed Feb 11 13:49:17 2015 -0700
summary:
Move testing of compileall into Python regrtest
files:
Lib/test/test_compile_jy.py | 62 ++++++++++++++++++++++--
bugtests/test403.py | 34 -------------
bugtests/test403/greeter.py | 2 -
bugtests/test403/test.py | 3 -
4 files changed, 55 insertions(+), 46 deletions(-)
diff --git a/Lib/test/test_compile_jy.py b/Lib/test/test_compile_jy.py
--- a/Lib/test/test_compile_jy.py
+++ b/Lib/test/test_compile_jy.py
@@ -1,10 +1,14 @@
+import __builtin__
+import compileall
+import os
+import py_compile
+import shutil
+import subprocess
+import sys
+import textwrap
import unittest
-import os
-import sys
-import shutil
-import __builtin__
-import py_compile
-from test.test_support import run_unittest, TESTFN, is_jython
+from test.test_support import TESTFN, is_jython, run_unittest, temp_cwd
+
class TestMtime(unittest.TestCase):
@@ -50,8 +54,52 @@
finally:
shutil.rmtree(TESTFN)
+
+class TestCompileall(unittest.TestCase):
+
+ def write_code(self, package, name, code):
+ with open(os.path.join(package, name), "w") as f:
+ f.write(textwrap.dedent(code))
+
+ def test_compileall(self):
+ with temp_cwd():
+ PACKAGE = os.path.realpath("./greetings")
+ PYC_GREETER = os.path.join(PACKAGE, "greeter.pyc")
+ PYCLASS_GREETER = os.path.join(PACKAGE, "greeter$py.class")
+ PYCLASS_TEST = os.path.join(PACKAGE, "test$py.class")
+
+ os.mkdir(PACKAGE)
+ self.write_code(
+ PACKAGE, "greeter.py",
+ """
+ def greet():
+ print 'Hello world!'
+ """)
+ self.write_code(
+ PACKAGE, "test.py",
+ """
+ from greeter import greet
+ greet()
+ """)
+
+ # pretend we have a Python bytecode compiler by touching this file
+ open(PYC_GREETER, "a").close()
+
+ compileall.compile_dir(PACKAGE)
+ self.assertTrue(os.path.exists(PYC_GREETER)) # still exists
+ self.assertTrue(os.path.exists(PYCLASS_TEST)) # along with these new compiled files
+ self.assertTrue(os.path.exists(PYCLASS_GREETER))
+
+ # verify we can work with just compiled files
+ os.unlink(os.path.join(PACKAGE, "greeter.py"))
+ self.assertEqual(
+ subprocess.check_output([sys.executable, os.path.join(PACKAGE, "test.py")]).rstrip(),
+ "Hello world!")
+
+
def test_main():
- run_unittest(TestMtime)
+ run_unittest(TestMtime, TestCompileall)
+
if __name__ == "__main__":
test_main()
diff --git a/bugtests/test403.py b/bugtests/test403.py
deleted file mode 100644
--- a/bugtests/test403.py
+++ /dev/null
@@ -1,34 +0,0 @@
-"""
-test fix for bug #1672
-
-"""
-
-import os
-import compileall
-
-PACKAGE = "test403"
-PYC_GREETER = os.path.join(PACKAGE, "greeter.pyc")
-PYCLASS_GREETER = os.path.join(PACKAGE, "greeter$py.class")
-PYCLASS_TEST = os.path.join(PACKAGE, "test$py.class")
-
-def cleanup():
- try:
- for f in (PYC_GREETER, PYCLASS_TEST, PYCLASS_GREETER):
- os.unlink(f)
- except OSError:
- pass
-
-
-# setup
-cleanup()
-open(PYC_GREETER, "a").close()
-
-# test
-compileall.compile_dir(PACKAGE)
-print PYCLASS_TEST
-print PYCLASS_GREETER
-assert os.path.exists(PYCLASS_TEST)
-assert os.path.exists(PYCLASS_GREETER)
-
-# teardown
-cleanup()
diff --git a/bugtests/test403/greeter.py b/bugtests/test403/greeter.py
deleted file mode 100644
--- a/bugtests/test403/greeter.py
+++ /dev/null
@@ -1,2 +0,0 @@
-def greet():
- print 'Hello world'
diff --git a/bugtests/test403/test.py b/bugtests/test403/test.py
deleted file mode 100644
--- a/bugtests/test403/test.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from greeter import greet
-
-greet()
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list