From: <pj...@us...> - 2009-03-29 23:21:16
|
Revision: 6117 http://jython.svn.sourceforge.net/jython/?rev=6117&view=rev Author: pjenvey Date: 2009-03-29 23:21:00 +0000 (Sun, 29 Mar 2009) Log Message: ----------- fix failing tests: always compile the compiled version, incase the bytecode magic changes Modified Paths: -------------- trunk/jython/Lib/test/classimport.jar trunk/jython/Lib/test/classimport_Lib.jar trunk/jython/Lib/test/test_classpathimporter.py Modified: trunk/jython/Lib/test/classimport.jar =================================================================== (Binary files differ) Modified: trunk/jython/Lib/test/classimport_Lib.jar =================================================================== (Binary files differ) Modified: trunk/jython/Lib/test/test_classpathimporter.py =================================================================== --- trunk/jython/Lib/test/test_classpathimporter.py 2009-03-29 22:13:47 UTC (rev 6116) +++ trunk/jython/Lib/test/test_classpathimporter.py 2009-03-29 23:21:00 UTC (rev 6117) @@ -1,9 +1,15 @@ +import os +import py_compile +import shutil +import sys +import tempfile import unittest -import sys +import zipfile from test import test_support from java.lang import Thread class ClasspathImporterTestCase(unittest.TestCase): + def setUp(self): self.orig_context = Thread.currentThread().contextClassLoader self.orig_path = sys.path @@ -11,32 +17,7 @@ def tearDown(self): Thread.currentThread().contextClassLoader = self.orig_context sys.path = self.orig_path - try: - del sys.modules['flat_in_jar'] - del sys.modules['jar_pkg'] - del sys.modules['jar_pkg.prefer_compiled'] - except KeyError: - pass - def setClassLoaderAndCheck(self, jar, prefix): - Thread.currentThread().contextClassLoader = test_support.make_jar_classloader(jar) - import flat_in_jar - self.assertEquals(flat_in_jar.value, 7) - import jar_pkg - self.assertEquals(prefix + '/jar_pkg/__init__$py.class', jar_pkg.__file__) - from jar_pkg import prefer_compiled - self.assertEquals(prefix + '/jar_pkg/prefer_compiled$py.class', prefer_compiled.__file__) - self.assert_(prefer_compiled.compiled) - self.assertRaises(NameError, __import__, 'flat_bad') - self.assertRaises(NameError, __import__, 'jar_pkg.bad') - - def test_default_pyclasspath(self): - self.setClassLoaderAndCheck("classimport.jar", "__pyclasspath__") - - def test_path_in_pyclasspath(self): - sys.path = ['__pyclasspath__/Lib'] - self.setClassLoaderAndCheck("classimport_Lib.jar", "__pyclasspath__/Lib") - # I don't like the checked in jar file bug1239.jar. The *one* thing I # liked about the tests in bugtests/ is that you could create a java file, # compile it, jar it and destroy the jar when done. Maybe when we move to @@ -54,8 +35,65 @@ sys.path.append("Lib/test/bug1126/bug1126.jar") import org.subpackage + +class PyclasspathImporterTestCase(unittest.TestCase): + + def setUp(self): + self.orig_context = Thread.currentThread().contextClassLoader + self.orig_path = sys.path + self.temp_dir = tempfile.mkdtemp() + self.modules = sys.modules.keys() + + def tearDown(self): + Thread.currentThread().contextClassLoader = self.orig_context + sys.path = self.orig_path + shutil.rmtree(self.temp_dir) + for module in sys.modules.keys(): + if module not in self.modules: + del sys.modules[module] + + def setClassLoaderAndCheck(self, orig_jar, prefix, compile_path=''): + # Create a new jar and compile prefer_compiled into it + orig_jar = test_support.findfile(orig_jar) + jar = os.path.join(self.temp_dir, os.path.basename(orig_jar)) + shutil.copy(orig_jar, jar) + + code = os.path.join(self.temp_dir, 'prefer_compiled.py') + fp = open(code, 'w') + fp.write('compiled = True') + fp.close() + py_compile.compile(code) + zip = zipfile.ZipFile(jar, 'a') + zip.write(os.path.join(self.temp_dir, 'prefer_compiled$py.class'), + os.path.join(compile_path, 'jar_pkg', + 'prefer_compiled$py.class')) + zip.close() + zip = zipfile.ZipFile(jar) + + Thread.currentThread().contextClassLoader = test_support.make_jar_classloader(jar) + import flat_in_jar + self.assertEquals(flat_in_jar.value, 7) + import jar_pkg + self.assertEquals(prefix + '/jar_pkg/__init__.py', jar_pkg.__file__) + from jar_pkg import prefer_compiled + self.assertEquals(prefix + '/jar_pkg/prefer_compiled$py.class', prefer_compiled.__file__) + self.assert_(prefer_compiled.compiled) + self.assertRaises(NameError, __import__, 'flat_bad') + self.assertRaises(NameError, __import__, 'jar_pkg.bad') + + def test_default_pyclasspath(self): + self.setClassLoaderAndCheck('classimport.jar', '__pyclasspath__') + + def test_path_in_pyclasspath(self): + sys.path = ['__pyclasspath__/Lib'] + self.setClassLoaderAndCheck('classimport_Lib.jar', + '__pyclasspath__/Lib', 'Lib') + + def test_main(): - test_support.run_unittest(ClasspathImporterTestCase) + test_support.run_unittest(ClasspathImporterTestCase, + PyclasspathImporterTestCase) + if __name__ == '__main__': test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |