[Jython-checkins] jython (2.5): Test and temporary fix for http://bugs.jython.org/issue1900

frank.wierzbicki jython-checkins at python.org
Fri Jun 15 06:43:32 CEST 2012


http://hg.python.org/jython/rev/88d5d1113ef1
changeset:   6710:88d5d1113ef1
branch:      2.5
parent:      6651:207e3db21d5b
user:        Frank Wierzbicki <fwierzbicki at gmail.com>
date:        Thu Jun 14 21:31:35 2012 -0700
summary:
  Test and temporary fix for http://bugs.jython.org/issue1900

files:
  build.xml                                        |  17 +++++++
  src/org/python/core/imp.java                     |   6 ++
  tests/java/org/python/tests/imp/ImportTests.java |  22 ++++++++++
  tests/python/testpkg/__init__.py                 |  10 ++++
  tests/python/testpkg/submodule.py                |   1 +
  5 files changed, 56 insertions(+), 0 deletions(-)


diff --git a/build.xml b/build.xml
--- a/build.xml
+++ b/build.xml
@@ -940,6 +940,23 @@
             </batchtest>
         </junit>
     </target>
+    <target name="importest" depends="developer-build" description="run all the JUnit tests that need tests/python in the path.">
+        <mkdir dir="${junit.reports}"/>
+        <junit fork="true" printsummary="true">
+            <formatter type="xml"/>
+            <sysproperty key="python.home" value="${dist.dir}"/>
+            <sysproperty key="python.test.source.dir" value="${test.source.dir}"/>
+            <classpath refid="test.classpath"/>
+            <classpath refid="test.classpath"/>
+            <classpath>
+                <pathelement location="${jython.base.dir}/tests/python"/>
+            </classpath>
+            <batchtest todir="${junit.reports}">
+                <fileset dir="${test.source.dir}" includes="org/python/tests/imp/*Test*.java">
+                </fileset>
+            </batchtest>
+        </junit>
+    </target>
     <target name="idxtest" depends="developer-build">
         <mkdir dir="${junit.reports}"/>
         <junit fork="true" printsummary="true" showoutput="true">
diff --git a/src/org/python/core/imp.java b/src/org/python/core/imp.java
--- a/src/org/python/core/imp.java
+++ b/src/org/python/core/imp.java
@@ -1013,6 +1013,12 @@
         PyObject[] submods = new PyObject[names.length];
         for (int i = 0; i < names.length; i++) {
             PyObject submod = module.__findattr__(names[i]);
+            //XXX: Temporary fix for http://bugs.jython.org/issue1900
+            if (submod == null) {
+                submod = module.impAttr(names[i]);
+            }
+            //end temporary fix.
+
             if (submod == null) {
                 throw Py.ImportError("cannot import name " + names[i]);
             }
diff --git a/tests/java/org/python/tests/imp/ImportTests.java b/tests/java/org/python/tests/imp/ImportTests.java
new file mode 100644
--- /dev/null
+++ b/tests/java/org/python/tests/imp/ImportTests.java
@@ -0,0 +1,22 @@
+package org.python.tests.imp;
+
+import junit.framework.TestCase;
+
+import org.python.core.Py;
+import org.python.core.PyObject;
+import org.python.core.PyList;
+import org.python.core.PyString;
+import org.python.core.PySystemState;
+import org.python.core.imp;
+
+import java.io.File;
+
+public class ImportTests extends TestCase {
+
+    public void testImportFromJava() {
+        PySystemState.initialize();
+        PyObject submodule = imp.load("testpkg.submodule");
+        PyObject module = imp.load("testpkg");
+        module.__getattr__("test").__call__();
+    }
+}
diff --git a/tests/python/testpkg/__init__.py b/tests/python/testpkg/__init__.py
new file mode 100644
--- /dev/null
+++ b/tests/python/testpkg/__init__.py
@@ -0,0 +1,10 @@
+import sys
+
+
+def test():
+    print dir(sys.modules['testpkg'])
+    print 'submodule in sys.modules: %s' % ('testpkg.submodule' in sys.modules)
+    import testpkg
+    print testpkg.__file__
+    print dir(testpkg)
+    from testpkg import submodule
diff --git a/tests/python/testpkg/submodule.py b/tests/python/testpkg/submodule.py
new file mode 100644
--- /dev/null
+++ b/tests/python/testpkg/submodule.py
@@ -0,0 +1,1 @@
+# coding: utf-8

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list