[Jython-checkins] jython: All JUnit tests now pass, usually*

jim.baker jython-checkins at python.org
Wed Jan 6 23:02:41 EST 2016


https://hg.python.org/jython/rev/0702331d99a1
changeset:   7854:0702331d99a1
user:        Jim Baker <jim.baker at rackspace.com>
date:        Wed Jan 06 21:02:22 2016 -0700
summary:
  All JUnit tests now pass, usually*

JSR 223 scope support, for locals(), needed to take in account support
for builtins being added. Also excludes more types not supported by
com.ziclix.python.sql.

*However we still get intermitten NPE failures in BaseBytes tests,
which need to be investigated.

files:
  tests/java/com/ziclix/python/sql/DataHandlerTest.java |  28 +++++++--
  tests/java/org/python/jsr223/ScriptEngineTest.java    |  19 ++++--
  2 files changed, 32 insertions(+), 15 deletions(-)


diff --git a/tests/java/com/ziclix/python/sql/DataHandlerTest.java b/tests/java/com/ziclix/python/sql/DataHandlerTest.java
--- a/tests/java/com/ziclix/python/sql/DataHandlerTest.java
+++ b/tests/java/com/ziclix/python/sql/DataHandlerTest.java
@@ -12,6 +12,7 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.python.core.PyObject;
 import org.python.core.PySystemState;
 
 import junit.framework.TestCase;
@@ -35,24 +36,35 @@
         ResultSet rs = (ResultSet)Proxy.newProxyInstance(getClass().getClassLoader(),
                                                          new Class<?>[] {ResultSet.class},
                                                          new DefaultReturnHandler());
-        List<String> unsupportedTypes = Arrays.asList("ARRAY",
-                                                      "DATALINK",
-                                                      "DISTINCT",
-                                                      "REF",
-                                                      "ROWID", // java 6
-                                                      "STRUCT");
+        List<String> unsupportedTypes = Arrays.asList(
+                "ARRAY",
+                "DATALINK",
+                "DISTINCT",
+                "REF",
+                "REF_CURSOR",
+                "ROWID",
+                "STRUCT",
+                "TIME_WITH_TIMEZONE",
+                "TIMESTAMP_WITH_TIMEZONE"
+        );
         for (Field field : Types.class.getDeclaredFields()) {
             String typeName = field.getName();
             int type = field.getInt(null);
             if (unsupportedTypes.contains(typeName)) {
                 try {
                     _handler.getPyObject(rs, 1, type);
-                    fail("SQLException expected");
+                    fail("SQLException expected: " + typeName);
                 } catch (SQLException sqle) {
                     // expected
                 }
             } else {
-                assertNotNull(typeName + " should return None", _handler.getPyObject(rs, 1, type));
+                try {
+                    PyObject pyobj = _handler.getPyObject(rs, 1, type);
+                    assertNotNull(typeName + " should return None", pyobj);
+                } catch (SQLException sqle) {
+                    // unexpected! but useful for future proofing changes in SQL support
+                    fail("unexpected SQLException: " + typeName);
+                }
             }
         }
     }
diff --git a/tests/java/org/python/jsr223/ScriptEngineTest.java b/tests/java/org/python/jsr223/ScriptEngineTest.java
--- a/tests/java/org/python/jsr223/ScriptEngineTest.java
+++ b/tests/java/org/python/jsr223/ScriptEngineTest.java
@@ -16,6 +16,7 @@
 
 import junit.framework.TestCase;
 
+import org.junit.Assert;
 import org.python.core.Options;
 import org.python.core.PyString;
 
@@ -224,13 +225,18 @@
         }
     }
 
+    // FIXME PyScriptEngineScope lacks items(), iteritems(), and other dict methods
+    // This should be added in a future release
+
     public void testScope_repr() throws ScriptException {
         ScriptEngineManager manager = new ScriptEngineManager();
         ScriptEngine pythonEngine = manager.getEngineByName("python");
         pythonEngine.eval("a = 4");
         pythonEngine.eval("b = 'hi'");
-        pythonEngine.eval("localrepr = `locals()`");
-        assertEquals("{'b': u'hi', 'a': 4}", pythonEngine.get("localrepr"));
+        String repr = (String)pythonEngine.eval("repr(locals())");
+        // locals() contains builtins as of 2.7.0, so we need to selectively test
+        Assert.assertTrue(repr.contains("'a': 4"));
+        Assert.assertTrue(repr.contains("'b': u'hi'"));
     }
 
     public void testScope_iter() throws ScriptException {
@@ -238,10 +244,9 @@
         ScriptEngine pythonEngine = manager.getEngineByName("python");
         pythonEngine.eval("a = 4");
         pythonEngine.eval("b = 'hi'");
-        pythonEngine.eval("list = []");
-        pythonEngine.eval("for loc in locals(): list.append(loc)");
-        pythonEngine.eval("listrepr = `list`");
-        assertEquals("[u'a', u'b', u'list']", pythonEngine.get("listrepr"));
+        assertEquals(
+                "['__builtins__', 'a', 'b']",
+                pythonEngine.eval("repr(sorted((item for item in locals())))"));
     }
 
     public void testScope_lookup() throws ScriptException {
@@ -250,7 +255,7 @@
         pythonEngine.eval("a = 4");
         pythonEngine.eval("b = 'hi'");
         pythonEngine.eval("var_a = locals()['a']");
-        pythonEngine.eval("arepr = `var_a`");
+        pythonEngine.eval("arepr = repr(var_a)");
         assertEquals("4", pythonEngine.get("arepr"));
     }
 

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


More information about the Jython-checkins mailing list