From f07946e6944dd0e172dc593efeac9163384181e5 Mon Sep 17 00:00:00 2001 From: LaiWang2020 <68682038+LaiWang2020@users.noreply.github.com> Date: Fri, 28 May 2021 19:28:10 +0800 Subject: [PATCH] Improve Jython tests to cover more cases (#3937) Co-authored-by: duke326 <448711277@qq.com> Co-authored-by: chupengrocky --- .../database/DatabaseConfiguration.java | 4 +-- .../google/refine/jython/JythonEvaluable.java | 1 + .../refine/jython/JythonEvaluableTest.java | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/extensions/database/src/com/google/refine/extension/database/DatabaseConfiguration.java b/extensions/database/src/com/google/refine/extension/database/DatabaseConfiguration.java index 85c4cd6e8..47dad7f4e 100644 --- a/extensions/database/src/com/google/refine/extension/database/DatabaseConfiguration.java +++ b/extensions/database/src/com/google/refine/extension/database/DatabaseConfiguration.java @@ -42,8 +42,8 @@ public class DatabaseConfiguration { //optional parameters private boolean useSSL; - - + + public String getConnectionName() { return connectionName; } diff --git a/extensions/jython/src/com/google/refine/jython/JythonEvaluable.java b/extensions/jython/src/com/google/refine/jython/JythonEvaluable.java index d47ad605e..0e4cf2100 100644 --- a/extensions/jython/src/com/google/refine/jython/JythonEvaluable.java +++ b/extensions/jython/src/com/google/refine/jython/JythonEvaluable.java @@ -133,6 +133,7 @@ public class JythonEvaluable implements Evaluable { return new EvalError(e.toString()); } } + protected Object unwrap(Object result) { if (result != null) { diff --git a/extensions/jython/tests/src/com/google/refine/jython/JythonEvaluableTest.java b/extensions/jython/tests/src/com/google/refine/jython/JythonEvaluableTest.java index 196030ba7..b23e2c38d 100644 --- a/extensions/jython/tests/src/com/google/refine/jython/JythonEvaluableTest.java +++ b/extensions/jython/tests/src/com/google/refine/jython/JythonEvaluableTest.java @@ -1,7 +1,12 @@ package com.google.refine.jython; +import java.io.File; import java.util.Properties; +import com.google.refine.expr.EvalError; +import com.google.refine.expr.HasFields; +import org.python.core.*; +import org.python.util.PythonInterpreter; import org.testng.Assert; import org.testng.annotations.Test; @@ -16,6 +21,35 @@ import com.google.refine.model.Row; */ public class JythonEvaluableTest { + // Reproduces the situation when result is a PyObject + // Version with a test case which only calls the existing evaluate method + @Test + public void unwrapPyObjectTest(){ + Properties props = new Properties(); + Project project = new Project(); + + Row row = new Row(2); + row.setCell(0, new Cell("one", null)); + row.setCell(0, new Cell("1", null)); + + props.put("columnName", "number"); + props.put("true", "true"); + props.put("false", "false"); + props.put("rowIndex", "0"); + props.put("value", 1); + props.put("project", project); + props.put("call", "number"); + props.put("PI", "3.141592654"); + props.put("cells", new CellTuple(project, row)); + String funcExpression ="class Foo(object):\n" + + " bar = 1\n" + + "\n" + + "return Foo()"; + JythonEvaluable eval1 = new JythonEvaluable(funcExpression); + PyObject po = (PyObject) eval1.evaluate(props); + Assert.assertEquals(po.__getattr__("bar").toString(),"1"); + } + @Test public void testJythonConcurrent(){ Properties props = new Properties();