Issue #2307: Remove calls to PythonScript constructor without ClassLoader
argument, fix IscMosaic. Change-Id: Iff29b2790fd1c6d5f5b829f6b35ff31829cdc907 Former-commit-id: 85609a4bf9072ae41dbafbc1b874efbcd5bd21a4
This commit is contained in:
parent
e091a9d18d
commit
47878a4318
25 changed files with 273 additions and 445 deletions
|
@ -55,6 +55,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 11, 2009 njensen Initial creation
|
||||
* Jun 22, 2011 9897 ryu allow new GFE config and send notification
|
||||
* Sep 05, 2013 #2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -100,7 +101,8 @@ public class PythonPreferenceStore implements IPreferenceStore,
|
|||
try {
|
||||
py = new PythonScript(
|
||||
utilityDir + File.separator + "loadConfig.py",
|
||||
PyUtil.buildJepIncludePath(configPath, vtecPath));
|
||||
PyUtil.buildJepIncludePath(configPath, vtecPath), this
|
||||
.getClass().getClassLoader());
|
||||
} catch (JepException e) {
|
||||
statusHandler.handle(Priority.CRITICAL,
|
||||
"Unable to load GFE config", e);
|
||||
|
@ -116,7 +118,8 @@ public class PythonPreferenceStore implements IPreferenceStore,
|
|||
"Unable to load baseline GFE config", e);
|
||||
}
|
||||
|
||||
//Map<String, Object> originalSelectedConfiguration = selectedConfiguration;
|
||||
// Map<String, Object> originalSelectedConfiguration =
|
||||
// selectedConfiguration;
|
||||
args.put("configName", configName);
|
||||
try {
|
||||
selectedConfiguration = (Map<String, Object>) py.execute(
|
||||
|
@ -156,7 +159,8 @@ public class PythonPreferenceStore implements IPreferenceStore,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addConfigurationChangeListener(IConfigurationChangeListener listener) {
|
||||
public void addConfigurationChangeListener(
|
||||
IConfigurationChangeListener listener) {
|
||||
this.configurationChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
|
@ -191,6 +195,7 @@ public class PythonPreferenceStore implements IPreferenceStore,
|
|||
for (final IPropertyChangeListener listener : this.propertyChangeListeners) {
|
||||
SafeRunnable.run(new SafeRunnable(JFaceResources
|
||||
.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
listener.propertyChange(pe);
|
||||
}
|
||||
|
@ -203,6 +208,7 @@ public class PythonPreferenceStore implements IPreferenceStore,
|
|||
for (final IConfigurationChangeListener listener : this.configurationChangeListeners) {
|
||||
SafeRunnable.run(new SafeRunnable(JFaceResources
|
||||
.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
listener.configurationChanged(config);
|
||||
}
|
||||
|
@ -433,9 +439,11 @@ public class PythonPreferenceStore implements IPreferenceStore,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeConfigurationChangeListener(IConfigurationChangeListener listener) {
|
||||
public void removeConfigurationChangeListener(
|
||||
IConfigurationChangeListener listener) {
|
||||
this.configurationChangeListeners.remove(listener);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
|
@ -97,6 +97,7 @@ import com.raytheon.viz.gfe.textformatter.TextProductManager;
|
|||
* 04/24/2013 1936 dgilling Move initialization of TextProductMgr
|
||||
* to GFE startup.
|
||||
* 08/27/2013 2302 randerso Code cleanup for AutoSaveJob
|
||||
* 09/05/2013 2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -570,7 +571,7 @@ public class DataManager {
|
|||
.getFile(
|
||||
pathMgr.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.BASE), "python")
|
||||
.getPath()));
|
||||
.getPath()), this.getClass().getClassLoader());
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("str", response.get(1));
|
||||
Map<String, ?> obj = (Map<String, ?>) script.execute("unPickle",
|
||||
|
|
|
@ -223,7 +223,8 @@ public class CombinationsFileUtil {
|
|||
map.put("comboName", comboName);
|
||||
PythonScript python = null;
|
||||
try {
|
||||
python = new PythonScript(scriptPath, comboPath);
|
||||
python = new PythonScript(scriptPath, comboPath,
|
||||
CombinationsFileUtil.class.getClassLoader());
|
||||
Object com = python.execute("getCombinations", map);
|
||||
combos = (List<List<String>>) com;
|
||||
} catch (JepException e) {
|
||||
|
|
|
@ -89,6 +89,7 @@ import com.raytheon.viz.pointdata.rsc.PlotResourceData;
|
|||
* Jun 29, 2009 2538 jsanchez Implemented pointdata.
|
||||
* Aug 09, 2012 1085 jkorman Corrected data construction.
|
||||
* Sep 05, 2013 2316 bsteffen Unify pirep and ncpirep.
|
||||
* Sep 05, 2013 2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -460,11 +461,13 @@ public class PlotModelFactory2 {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node child = childNodes.item(i);
|
||||
if (Node.TEXT_NODE == child.getNodeType())
|
||||
if (Node.TEXT_NODE == child.getNodeType()) {
|
||||
sb.append(((Text) child).getData());
|
||||
}
|
||||
if (sb.length() > 0)
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
scriptInfo.scriptText = sb.toString();
|
||||
}
|
||||
|
||||
sampleScriptInfo = new ScriptInfo();
|
||||
sampleScriptInfo.plotDelegateName = scriptInfo.plotDelegateName;
|
||||
|
@ -599,8 +602,9 @@ public class PlotModelFactory2 {
|
|||
Object result = script.executePlotDelegateMethod("isValid",
|
||||
"rec", stationData);
|
||||
if (result instanceof Boolean
|
||||
&& !((Boolean) result).booleanValue())
|
||||
&& !((Boolean) result).booleanValue()) {
|
||||
return null;
|
||||
}
|
||||
} catch (JepException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
e.getLocalizedMessage(), e);
|
||||
|
@ -1272,9 +1276,9 @@ public class PlotModelFactory2 {
|
|||
|
||||
public PlotPythonScript getScript() throws JepException {
|
||||
if (script != null) {
|
||||
if (Thread.currentThread() == scriptThread)
|
||||
if (Thread.currentThread() == scriptThread) {
|
||||
return script;
|
||||
else {
|
||||
} else {
|
||||
statusHandler.handle(Priority.ERROR,
|
||||
"Plot model scripting was not properly disposed.");
|
||||
script = null;
|
||||
|
@ -1290,8 +1294,9 @@ public class PlotModelFactory2 {
|
|||
public void disposeScript() throws JepException {
|
||||
if (script != null) {
|
||||
try {
|
||||
if (Thread.currentThread() == scriptThread)
|
||||
if (Thread.currentThread() == scriptThread) {
|
||||
script.dispose();
|
||||
}
|
||||
} finally {
|
||||
script = null;
|
||||
scriptThread = null;
|
||||
|
@ -1312,8 +1317,9 @@ public class PlotModelFactory2 {
|
|||
StringBuilder includePath = new StringBuilder();
|
||||
for (LocalizationLevel ll : keys) {
|
||||
LocalizationFile lf = map.get(ll);
|
||||
if (includePath.length() > 0)
|
||||
if (includePath.length() > 0) {
|
||||
includePath.append(File.pathSeparator);
|
||||
}
|
||||
includePath.append(lf.getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
|
@ -1322,8 +1328,9 @@ public class PlotModelFactory2 {
|
|||
+ "PlotModelInterface.py");
|
||||
script = new PlotPythonScript(baseFile.getAbsolutePath(),
|
||||
includePath.toString(), plotDelegateName);
|
||||
if (scriptText != null)
|
||||
if (scriptText != null) {
|
||||
script.evaluate(scriptText);
|
||||
}
|
||||
script.executePlotDelegateMethod("init", "plotModelFactory",
|
||||
PlotModelFactory2.this);
|
||||
return script;
|
||||
|
@ -1338,7 +1345,8 @@ public class PlotModelFactory2 {
|
|||
|
||||
public PlotPythonScript(String filePath, String anIncludePath,
|
||||
String plotDelegateName) throws JepException {
|
||||
super(filePath, anIncludePath);
|
||||
super(filePath, anIncludePath, PlotPythonScript.class
|
||||
.getClassLoader());
|
||||
jep.eval("def "
|
||||
+ CHEAT_RUN
|
||||
+ "(text):\n return eval(compile(text,'string','exec'),globals(),globals())");
|
||||
|
@ -1359,10 +1367,11 @@ public class PlotModelFactory2 {
|
|||
map.put(argName, argValue);
|
||||
}
|
||||
return execute(methodName, plotDelegateName, map);
|
||||
} else
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File getTableFile(String fileName) {
|
||||
File rval = PathManagerFactory.getPathManager().getStaticFile(
|
||||
|
|
|
@ -60,6 +60,7 @@ import com.raytheon.uf.common.util.FileUtil;
|
|||
* 07/14/09 1995 bphillip Initial creation
|
||||
* Mar 14, 2013 1794 djohnson FileUtil.listFiles now returns List.
|
||||
* 06/13/13 2044 randerso Refactored to use IFPServer
|
||||
* Sep 05, 2013 2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -132,7 +133,8 @@ public class GfeIRT extends Thread {
|
|||
GfePyIncludeUtil.getCommonPythonIncludePath(),
|
||||
GfePyIncludeUtil.getIscScriptsIncludePath(),
|
||||
GfePyIncludeUtil.getGfeConfigIncludePath(siteID));
|
||||
script = new PythonScript(scriptFile, includePath);
|
||||
script = new PythonScript(scriptFile, includePath, this.getClass()
|
||||
.getClassLoader());
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
|
||||
GridLocation domain = config.dbDomain();
|
||||
|
|
|
@ -35,6 +35,7 @@ import com.raytheon.uf.common.python.PythonScript;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 25, 2011 dgilling Initial creation
|
||||
* Sep 05, 2013 #2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -53,7 +54,7 @@ public class IscSendScript extends PythonScript {
|
|||
*/
|
||||
public IscSendScript(String aFilePath, String anIncludePath)
|
||||
throws JepException {
|
||||
super(aFilePath, anIncludePath);
|
||||
super(aFilePath, anIncludePath, IscSendScript.class.getClassLoader());
|
||||
}
|
||||
|
||||
public Object execute(Map<String, Object> args) throws JepException {
|
||||
|
|
|
@ -44,6 +44,7 @@ import com.raytheon.uf.common.python.PythonScript;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 26, 2011 bphillip Initial creation
|
||||
* Sep 05, 2013 #2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -77,7 +78,8 @@ public class LogPurger {
|
|||
|
||||
PythonScript script = siteScriptMap.get(siteID);
|
||||
if (script == null) {
|
||||
script = new PythonScript(scriptFile, includePath);
|
||||
script = new PythonScript(scriptFile, includePath, this
|
||||
.getClass().getClassLoader());
|
||||
siteScriptMap.put(siteID, script);
|
||||
}
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
|
|
|
@ -52,6 +52,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* 07/06/09 1995 bphillip Initial port
|
||||
* 09/22/09 3058 rjpeter Converted to IRequestHandler
|
||||
* 09/05/13 2307 dgilling Use better PythonScript constructor.
|
||||
* </pre>
|
||||
*
|
||||
* @author bphillip
|
||||
|
@ -80,7 +81,8 @@ public class IscCreateDomainDictHandler implements
|
|||
.getCommonPythonIncludePath(), GfePyIncludeUtil
|
||||
.getIscScriptsIncludePath(), GfePyIncludeUtil
|
||||
.getGfeConfigIncludePath(request.getSiteID()));
|
||||
script = new PythonScript(scriptFile, includePath);
|
||||
script = new PythonScript(scriptFile, includePath, this.getClass()
|
||||
.getClassLoader());
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("xml", request.getXml());
|
||||
Object obj = script.execute("createDomainDict", args);
|
||||
|
|
|
@ -49,6 +49,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* 08/21/09 1995 bphillip Initial port
|
||||
* 09/22/09 3058 rjpeter Converted to IRequestHandler
|
||||
* 09/05/13 2307 dgilling Use better PythonScript constructor.
|
||||
* </pre>
|
||||
*
|
||||
* @author bphillip
|
||||
|
@ -75,7 +76,8 @@ public class IscGetRequestXmlHandler implements
|
|||
.getCommonPythonIncludePath(), GfePyIncludeUtil
|
||||
.getIscScriptsIncludePath(), GfePyIncludeUtil
|
||||
.getGfeConfigIncludePath(request.getSiteID()));
|
||||
script = new PythonScript(scriptFile, includePath);
|
||||
script = new PythonScript(scriptFile, includePath, this.getClass()
|
||||
.getClassLoader());
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("xml", request.getXml());
|
||||
args.put("selectedServers", request.getSelectedServers());
|
||||
|
|
|
@ -61,6 +61,8 @@ import com.raytheon.uf.common.util.FileUtil;
|
|||
* 08/21/09 1995 bphillip Initial port
|
||||
* 09/22/09 3058 rjpeter Converted to IRequestHandler
|
||||
* 03/07/13 1759 dgilling Refactor to not use GfeScript.
|
||||
* 09/05/13 2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bphillip
|
||||
|
@ -132,7 +134,8 @@ public class IscMakeRequestHandler implements IRequestHandler<IscMakeRequest> {
|
|||
try {
|
||||
PythonScript script = null;
|
||||
try {
|
||||
script = new PythonScript(scriptPath, includePath);
|
||||
script = new PythonScript(scriptPath, includePath,
|
||||
IscMakeRequestHandler.class.getClassLoader());
|
||||
try {
|
||||
script.execute(METHOD_NAME, args);
|
||||
} catch (JepException e) {
|
||||
|
|
|
@ -57,6 +57,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* 07/06/09 1995 bphillip Initial port
|
||||
* 09/22/09 3058 rjpeter Converted to IRequestHandler
|
||||
* 09/05/13 2307 dgilling Use better PythonScript constructor.
|
||||
* </pre>
|
||||
*
|
||||
* @author bphillip
|
||||
|
@ -140,7 +141,8 @@ public class IscRequestQueryHandler implements
|
|||
GfePyIncludeUtil.getCommonPythonIncludePath(),
|
||||
GfePyIncludeUtil.getIscScriptsIncludePath(),
|
||||
GfePyIncludeUtil.getGfeConfigIncludePath(siteID));
|
||||
script = new PythonScript(scriptFile, includePath);
|
||||
script = new PythonScript(scriptFile, includePath, this.getClass()
|
||||
.getClassLoader());
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("ancfURL", ancf);
|
||||
args.put("bncfURL", bncf);
|
||||
|
@ -168,7 +170,8 @@ public class IscRequestQueryHandler implements
|
|||
GfePyIncludeUtil.getCommonPythonIncludePath(),
|
||||
GfePyIncludeUtil.getIscScriptsIncludePath(),
|
||||
GfePyIncludeUtil.getGfeConfigIncludePath(siteID));
|
||||
script = new PythonScript(scriptFile, includePath);
|
||||
script = new PythonScript(scriptFile, includePath, this.getClass()
|
||||
.getClassLoader());
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("xml", xml);
|
||||
domainDict = script.execute("createDomainDict", args);
|
||||
|
|
|
@ -55,6 +55,7 @@ import com.raytheon.uf.common.util.FileUtil;
|
|||
* Mar 07, 2013 1759 dgilling Refactored to remove dependency
|
||||
* on GfeScriptExecutor.
|
||||
* Jun 13, 2013 #2044 randerso Refactored to use IFPServer
|
||||
* Sep 05, 2013 #2307 dgilling Use better PythonScript constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -96,7 +97,8 @@ public class PurgeGfeGridsRequestHandler implements
|
|||
String includePath = PyUtil.buildJepIncludePath(
|
||||
GfePyIncludeUtil.getCommonPythonIncludePath(),
|
||||
GfePyIncludeUtil.getIscScriptsIncludePath());
|
||||
script = new PythonScript(scriptPath, includePath);
|
||||
script = new PythonScript(scriptPath, includePath, this.getClass()
|
||||
.getClassLoader());
|
||||
try {
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("databaseID", request.getDatabaseID().toString());
|
||||
|
|
|
@ -39,7 +39,6 @@ from com.raytheon.uf.common.time import TimeRange
|
|||
from com.vividsolutions.jts.geom import Coordinate
|
||||
from java.awt import Point
|
||||
|
||||
from com.raytheon.edex.plugin.gfe.server import GridParmManager
|
||||
from com.raytheon.edex.plugin.gfe.config import IFPServerConfigManager
|
||||
from com.raytheon.edex.plugin.gfe.smartinit import IFPDB
|
||||
from com.raytheon.uf.common.dataplugin.gfe import GridDataHistory
|
||||
|
@ -82,6 +81,7 @@ from com.raytheon.uf.edex.database.cluster import ClusterTask
|
|||
# 05/23/13 1759 dgilling Remove unnecessary imports.
|
||||
# 06/05/13 2063 dgilling Change __siteInDbGrid() to
|
||||
# call IFPWE.history() like A1.
|
||||
# 09/05/13 2307 dgilling Fix breakage caused by #2044.
|
||||
#
|
||||
#
|
||||
|
||||
|
@ -565,7 +565,7 @@ class IscMosaic:
|
|||
grid = self.__validateAdjustWeatherKeys(grid,
|
||||
self.__parmName, tr)
|
||||
|
||||
grid = self.__remap(self.__dbwe.getParmid(), grid, inGeoDict, inFillV)
|
||||
grid = self.__remap(self.__dbwe, grid, inGeoDict, inFillV)
|
||||
|
||||
# if rate parm, then may need to adjust the values
|
||||
if self.__rateParm and inTimes[i] != tr:
|
||||
|
@ -1068,13 +1068,12 @@ class IscMosaic:
|
|||
|
||||
return grid.astype(numpy.float32)
|
||||
|
||||
def __remap(self, pid, grid, inGeoDict, inFillV):
|
||||
|
||||
gpi = GridParmManager.getGridParmInfo(pid).getPayload()
|
||||
def __remap(self, we, grid, inGeoDict, inFillV):
|
||||
gpi = we.getGpi()
|
||||
|
||||
gridType = gpi.getGridType().toString()
|
||||
|
||||
gs = self.__decodeGridSlice(pid, grid, TimeRange())
|
||||
gs = self.__decodeGridSlice(we, grid, TimeRange())
|
||||
|
||||
pd = self.__decodeProj(inGeoDict)
|
||||
fill = inFillV
|
||||
|
@ -1104,9 +1103,10 @@ class IscMosaic:
|
|||
newGrid = mapper.remap(gs.getDiscreteGrid(), fill, fill)
|
||||
return (newGrid.__numpy__[0], grid[1])
|
||||
|
||||
def __decodeGridSlice(self, pid, value, tr, history=None):
|
||||
def __decodeGridSlice(self, we, value, tr, history=None):
|
||||
pid = we.getParmid()
|
||||
gpi = we.getGpi()
|
||||
|
||||
gpi = GridParmManager.getGridParmInfo(pid).getPayload()
|
||||
gridType = gpi.getGridType().toString()
|
||||
|
||||
hist = ArrayList()
|
||||
|
|
|
@ -32,7 +32,9 @@ import jep.JepException;
|
|||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 7, 2009 njensen Initial creation
|
||||
* Dec 07, 2009 njensen Initial creation
|
||||
* Sep 05, 2013 #2307 dgilling Remove constructor without explicit
|
||||
* ClassLoader.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -49,22 +51,6 @@ public abstract class PythonInterpreter {
|
|||
|
||||
protected Jep jep;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param aFilePath
|
||||
* the path to the python script
|
||||
* @param anIncludePath
|
||||
* the python include path, with multiple directories being
|
||||
* separated by :
|
||||
* @throws JepException
|
||||
*/
|
||||
public PythonInterpreter(String aFilePath, String anIncludePath)
|
||||
throws JepException {
|
||||
jep = new Jep(false, anIncludePath);
|
||||
initializeJep(aFilePath, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
|
@ -1,156 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.python;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import jep.JepException;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 25, 2008 wdougherty Initial creation
|
||||
* </pre>
|
||||
*
|
||||
* @author wdougherty
|
||||
* @version 1.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class PythonMapScript extends PythonScript {
|
||||
public PythonMapScript(String filePath, String anIncludePath,
|
||||
ClassLoader classLoader, List<String> preEvals) throws JepException {
|
||||
super(filePath, anIncludePath, classLoader, preEvals);
|
||||
}
|
||||
|
||||
public PythonMapScript(String filePath, String anIncludePath,
|
||||
ClassLoader classLoader) throws JepException {
|
||||
super(filePath, anIncludePath, classLoader);
|
||||
}
|
||||
|
||||
public PythonMapScript(String script, String includePath)
|
||||
throws JepException {
|
||||
super(script, includePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Python variables in the current script from argmap. For each item in
|
||||
* the map, see if its value is a string beginning with "::". If it is not,
|
||||
* create a python variable in this test script whose name is the same as
|
||||
* the key, and assign it a value equal to the key's value.
|
||||
*
|
||||
* @param argmap
|
||||
* a map of argument names to values
|
||||
* @throws JepException
|
||||
* if Jep chokes on the generated code.
|
||||
*/
|
||||
public void setArgs(Map<String, Object> argmap) throws JepException {
|
||||
Object val;
|
||||
|
||||
for (String arg : argmap.keySet()) {
|
||||
if (arg.startsWith("::")) {
|
||||
continue;
|
||||
}
|
||||
val = argmap.get(arg);
|
||||
evaluateArgument(arg, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a method in a script. This is basically the same as the execute()
|
||||
* method of the base PythonScript class, except that it takes a Map of
|
||||
* argument names to values instead of twin arrays, and it has special
|
||||
* handling when the key is a String beginning with "::". The purpose of the
|
||||
* special handling is to allow complicated objects such as tuples and
|
||||
* arrays to be created in the script with eval() and then used as
|
||||
* parameters.
|
||||
*
|
||||
* @param methodName
|
||||
* The name of a method to execute.
|
||||
* @param instanceName
|
||||
* The name of a class or module within which the method can be
|
||||
* found.
|
||||
* @param argmap
|
||||
* Maps argument names to argument values. Argument names
|
||||
* beginning with "::" are interpreted as defining variables
|
||||
* which have already been declared in the script.
|
||||
* @return The Object produced by executing the method, which may be null.
|
||||
* @throws JepException
|
||||
* if Jep chokes on the scripted code.
|
||||
*/
|
||||
@Override
|
||||
public Object execute(String methodName, String instanceName,
|
||||
Map<String, Object> argmap) throws JepException {
|
||||
|
||||
setArgs(argmap);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(PythonScript.RESULT);
|
||||
sb.append(" = ");
|
||||
if (instanceName != null) {
|
||||
sb.append(instanceName).append(".");
|
||||
}
|
||||
sb.append(methodName).append("(");
|
||||
// add method parameters
|
||||
String ref;
|
||||
String sep = "";
|
||||
for (String arg : argmap.keySet()) {
|
||||
if ("self".equals(arg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.startsWith("::")) {
|
||||
ref = (String) argmap.get(arg);
|
||||
arg = arg.substring(2);
|
||||
} else {
|
||||
ref = arg;
|
||||
}
|
||||
sb.append(sep);
|
||||
sb.append(arg).append("=").append(ref);
|
||||
|
||||
sep = ",";
|
||||
}
|
||||
sb.append(")");
|
||||
// run the method
|
||||
jep.eval(sb.toString());
|
||||
// get the result
|
||||
return getExecutionResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpret an arbitrary Python expression in the script. This is just a
|
||||
* wrapper around the eval() method of the Jep instance of PythonScript.
|
||||
*
|
||||
* @param pythonExpr
|
||||
* Python expression to interpret.
|
||||
* @return true if the expression can be interpreted, false otherwise
|
||||
* (though usually a JepException is thrown).
|
||||
* @throws JepException
|
||||
* if Jepp chokes on the expression.
|
||||
*/
|
||||
public boolean evaluate(String pythonExpr) throws JepException {
|
||||
return jep.eval(pythonExpr);
|
||||
}
|
||||
}
|
|
@ -57,6 +57,8 @@ import jep.JepException;
|
|||
* Sep 18, 2009 2899 njensen Added cProfile support
|
||||
* Dec 7, 2009 3310 njensen Separated some functionality up to PythonInterpreter
|
||||
* Jun 26, 2012 #776 dgilling Fix leaking of global names.
|
||||
* Sep 05, 2013 #2307 dgilling Remove constructor without explicit
|
||||
* ClassLoader.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -70,21 +72,6 @@ public class PythonScript extends PythonInterpreter {
|
|||
|
||||
protected boolean profile = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param aFilePath
|
||||
* the path to the python script
|
||||
* @param anIncludePath
|
||||
* the python include path, with multiple directories being
|
||||
* separated by :
|
||||
* @throws JepException
|
||||
*/
|
||||
public PythonScript(String aFilePath, String anIncludePath)
|
||||
throws JepException {
|
||||
super(aFilePath, anIncludePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
|
@ -34,11 +34,27 @@ import com.raytheon.uf.common.python.PythonScript;
|
|||
* through invariant ScriptRequest objects in a concurrent queue. Output from
|
||||
* the scripts is through a concurrent Map based on the id from the
|
||||
* ScriptRequest.
|
||||
*
|
||||
* Why? Currently there are problems when a python script that includes pupynere
|
||||
* is disposed of in edex such as leaked memory and errors reloading the library
|
||||
* <p>
|
||||
* Why? Currently there are problems when a python script that includes numpy is
|
||||
* disposed of in edex such as leaked memory and errors reloading the library
|
||||
* again.
|
||||
* <p>
|
||||
* Instead of using this class it is recommended that developers instead use
|
||||
* {@link PythonJobCoordinator#newInstance(AbstractPythonScriptFactory<S>)}
|
||||
* instead to provide multi-threaded Python execution to their code.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 05, 2013 #2307 dgilling Use better PythonScript constructor,
|
||||
* mark as Deprecated.
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Deprecated
|
||||
public class PythonScriptManager {
|
||||
|
||||
private static final Object NullScriptResult = new Object();
|
||||
|
@ -104,7 +120,8 @@ public class PythonScriptManager {
|
|||
public void run() {
|
||||
PythonScript script;
|
||||
try {
|
||||
script = new PythonScript(scriptPath, pythonIncludePath);
|
||||
script = new PythonScript(scriptPath, pythonIncludePath,
|
||||
this.getClass().getClassLoader());
|
||||
} catch (JepException e1) {
|
||||
throw new RuntimeException("Failed to initialize script: "
|
||||
+ scriptPath);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="*HILOTest.java*|com/raytheon/viz/gfe/core/parm/TestParm.java|com/raytheon/viz/gfe/core/parm/TestParmManager.java|com/raytheon/viz/gfe/ui/runtimeui/TestHazardUtils.java|com/raytheon/viz/gfe/ui/runtimeui/TestSmartScript.java|gov/noaa/nws/ncep/gempak/parameters/colorbar/CLRBARTest.java|gov/noaa/nws/ncep/gempak/parameters/line/LineDataStringParserTest.java" kind="src" path="unit"/>
|
||||
<classpathentry excluding="*HILOTest.java*|com/raytheon/viz/gfe/core/parm/TestParm.java|com/raytheon/viz/gfe/core/parm/TestParmManager.java|com/raytheon/viz/gfe/ui/runtimeui/TestHazardUtils.java|gov/noaa/nws/ncep/gempak/parameters/colorbar/CLRBARTest.java|gov/noaa/nws/ncep/gempak/parameters/line/LineDataStringParserTest.java" kind="src" path="unit"/>
|
||||
<classpathentry kind="src" path="deploy"/>
|
||||
<classpathentry kind="src" path="resources"/>
|
||||
<classpathentry kind="src" path="integration"/>
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
|
@ -13,5 +18,6 @@
|
|||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
7
tests/.pydevproject
Normal file
7
tests/.pydevproject
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?eclipse-pydev version="1.0"?>
|
||||
|
||||
<pydev_project>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
|
||||
</pydev_project>
|
|
@ -34,23 +34,36 @@ idxKL = ["<None>", "one", "two", "three"]
|
|||
discreteGrid = (idxA, idxKL)
|
||||
|
||||
from com.raytheon.uf.common.dataplugin.gfe.grid import Grid2DByte
|
||||
from com.raytheon.viz.gfe.ui.runtimeui import TestSmartScript
|
||||
|
||||
numpyByteArray = np.ones((3,3), dtype=np.byte)
|
||||
dimx = 3
|
||||
dimy = 3
|
||||
|
||||
def testGetGridShape():
|
||||
def testGetGridShape(dataMgr):
|
||||
smartScript = SmartScript.SmartScript(dataMgr)
|
||||
valueExpected = (145, 145)
|
||||
valueObtained = smartScript.getGridShape()
|
||||
if not valueExpected==valueObtained:
|
||||
print "valueObtained =", valueObtained
|
||||
return (valueExpected==valueObtained)
|
||||
|
||||
def testGetGridInfo(model, element, level, timeRange, mostRecentModel=0):
|
||||
def testGetGridInfo(dataMgr, model, element, level, timeRange, mostRecentModel=0):
|
||||
smartScript = SmartScript.SmartScript(dataMgr)
|
||||
rtnInfo = smartScript.getGridInfo(model, element, level, timeRange, mostRecentModel)
|
||||
if rtnInfo is not None:
|
||||
gridTime = rtnInfo[0].gridTime()
|
||||
if gridTime is None:
|
||||
raise RuntimeError, "gridTime is None"
|
||||
return True
|
||||
|
||||
def testSortUglyStr(dataMgr, uglyStr):
|
||||
smartScript = SmartScript.SmartScript(dataMgr)
|
||||
return smartScript.sortUglyStr(uglyStr)
|
||||
|
||||
def testGetIndex(dataMgr, keyList, uglyStr):
|
||||
smartScript = SmartScript.SmartScript(dataMgr)
|
||||
return smartScript.getIndex(uglyStr, keyList)
|
||||
|
||||
def getParm(dataMgr, model, element, level):
|
||||
smartScript = SmartScript.SmartScript(dataMgr)
|
||||
return smartScript.getParm(model, element, level)
|
|
@ -42,6 +42,7 @@ import com.raytheon.uf.common.util.FileUtil;
|
|||
* Oct 23, 2012 1286 djohnson Change to find more localization files.
|
||||
* Jan 16, 2013 1487 djohnson Avoid adding new localization files to baseline utility directories.
|
||||
* May 31, 2013 1650 djohnson Fix incorrect merge from vlab branch.
|
||||
* Sep 05, 2013 2307 dgilling Better handling of directories in getPath().
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -104,7 +105,6 @@ public class TestPathManager extends PathManager {
|
|||
*/
|
||||
@Override
|
||||
public File getPath(LocalizationContext context, String fileName) {
|
||||
|
||||
File foundFile = null;
|
||||
|
||||
List<File> utilityDirs = getUtilityDirs();
|
||||
|
@ -120,27 +120,42 @@ public class TestPathManager extends PathManager {
|
|||
// if needed
|
||||
}
|
||||
|
||||
final int length = utilityDirs.size();
|
||||
for (int i = 0; i < length; i++) {
|
||||
File baseDir = new File(utilityDirs.get(i), context.toPath());
|
||||
for (File utilityDir : utilityDirs) {
|
||||
File baseDir = new File(utilityDir, context.toPath());
|
||||
File toFind = new File(baseDir, fileName);
|
||||
|
||||
File file = new File(baseDir, fileName);
|
||||
// If it's the final check or if a file exists
|
||||
if (i == (length - 1) || file.exists()) {
|
||||
foundFile = file;
|
||||
if (toFind.exists()) {
|
||||
if (!toFind.getAbsolutePath().startsWith(
|
||||
savedLocalizationFileDir.getAbsolutePath())) {
|
||||
foundFile = createTestIsolatedVersionOfLocalizationFile(
|
||||
context, fileName, toFind);
|
||||
} else {
|
||||
foundFile = toFind;
|
||||
}
|
||||
}
|
||||
|
||||
// if we found an actual file, we can be reasonably sure there's
|
||||
// only one file in the whole project with that name and can
|
||||
// stop looking. However, if we found a directory there may be
|
||||
// multiple plugins contributing to that directory and we have
|
||||
// to search the whole collection of directories to be sure
|
||||
// we've got all files that belong in that dir.
|
||||
if (toFind.isFile()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundFile == null
|
||||
|| foundFile.getAbsolutePath().startsWith(
|
||||
savedLocalizationFileDir.getAbsolutePath())) {
|
||||
if (foundFile != null) {
|
||||
return foundFile;
|
||||
} else {
|
||||
// Have to create a default File and the previous revision's
|
||||
// behavior was just to use the last File in utilityDirs. This
|
||||
// ensures that the path desired gets created as empty.
|
||||
return createTestIsolatedVersionOfLocalizationFile(context,
|
||||
fileName,
|
||||
new File(utilityDirs.get(utilityDirs.size() - 1),
|
||||
fileName));
|
||||
}
|
||||
|
||||
File savedFile = createTestIsolatedVersionOfLocalizationFile(
|
||||
context, fileName, foundFile);
|
||||
return savedFile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,16 +19,23 @@
|
|||
**/
|
||||
package com.raytheon.viz.gfe.ui.runtimeui;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import jep.JepException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactoryTest;
|
||||
import com.raytheon.uf.common.python.PyUtil;
|
||||
import com.raytheon.uf.common.python.PythonScript;
|
||||
import com.raytheon.uf.common.time.TimeRange;
|
||||
|
||||
|
@ -39,65 +46,51 @@ import com.raytheon.uf.common.time.TimeRange;
|
|||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Aug 1, 2008 wdougherty Initial creation
|
||||
* Aug 01, 2008 wdougherty Initial creation
|
||||
* Sep 05, 2013 #2307 dgilling Fix test case.
|
||||
* </pre>
|
||||
*
|
||||
* @author wdougherty
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
// TODO fix?
|
||||
@Ignore
|
||||
public class TestAbsTime extends TestCase {
|
||||
public class TestAbsTime {
|
||||
|
||||
protected static final String testScriptName = "ROOT/build/static/common/cave/etc/gfe/userPython/tests/TestAbsTime.py";
|
||||
private static final File SCRIPT_FILE = new File(
|
||||
"./python/gfe/TestAbsTime.py");
|
||||
|
||||
protected static final String smartScriptPath = "ROOT/build/static/common/cave/etc/gfe/userPython/utilities"
|
||||
+ ":ROOT/build"
|
||||
+ ":ROOT/AWIPSEdex/opt/utility/common_static/base/python/gfe"
|
||||
+ ":ROOT/AWIPSEdex/opt/utility/common_static/base/python"
|
||||
+ ":ROOT/AWIPSEdex/extensions/plugin-gfe/src";
|
||||
private PythonScript testScript = null;
|
||||
|
||||
PythonScript testScript;
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
PathManagerFactoryTest.initLocalization();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
String includePath = PyUtil.buildJepIncludePath(
|
||||
GfePyIncludeUtil.getCommonPythonIncludePath(),
|
||||
GfePyIncludeUtil.getCommonGfeIncludePath(),
|
||||
GfePyIncludeUtil.getUtilitiesIncludePath());
|
||||
|
||||
try {
|
||||
// Set up an interpreter that can run Python with Java classes.
|
||||
// Hopefully, using user.home will make this portable to any
|
||||
// developer.
|
||||
String root = System.getProperty("user.home") + File.separator
|
||||
+ "workspace";
|
||||
|
||||
testScript = new PythonScript(testScriptName.replaceAll("ROOT",
|
||||
root), smartScriptPath.replaceAll("ROOT", root));
|
||||
|
||||
testScript = new PythonScript(SCRIPT_FILE.getPath(), includePath,
|
||||
this.getClass().getClassLoader());
|
||||
} catch (JepException e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
@Override
|
||||
public void tearDown() {
|
||||
// Free any resources the previous interpreter used.
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (testScript != null) {
|
||||
testScript.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testAbsTimeZero() throws Exception {
|
||||
Map<String, Object> emptyMap = new HashMap<String, Object>();
|
||||
Map<String, Object> emptyMap = Collections.emptyMap();
|
||||
try {
|
||||
Date now = new Date();
|
||||
// AbsTime truncates to the nearest second. Wait one second
|
||||
|
|
|
@ -19,22 +19,33 @@
|
|||
**/
|
||||
package com.raytheon.viz.gfe.ui.runtimeui;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import jep.JepException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.raytheon.uf.common.python.PythonMapScript;
|
||||
import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactoryTest;
|
||||
import com.raytheon.uf.common.python.PyUtil;
|
||||
import com.raytheon.uf.common.python.PythonScript;
|
||||
import com.raytheon.uf.common.time.TimeRange;
|
||||
import com.raytheon.viz.gfe.Activator;
|
||||
import com.raytheon.viz.gfe.core.DataManager;
|
||||
import com.raytheon.viz.gfe.core.FakeDataManager;
|
||||
import com.raytheon.viz.gfe.core.internal.AbstractParmManager;
|
||||
import com.raytheon.viz.gfe.core.IParmManager;
|
||||
import com.raytheon.viz.gfe.core.internal.MockParmManager;
|
||||
import com.raytheon.viz.gfe.core.parm.Parm;
|
||||
import com.raytheon.viz.gfe.core.parm.Parm.CreateFromScratchMode;
|
||||
|
@ -47,144 +58,65 @@ import com.raytheon.viz.gfe.core.parm.Parm.CreateFromScratchMode;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 24, 2008 wdougherty Initial creation
|
||||
* Sep 05, 2013 #2307 dgilling Code cleanup
|
||||
* </pre>
|
||||
*
|
||||
* @author wdougherty
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class TestSmartScript extends TestCase {
|
||||
@Ignore
|
||||
// FIXME: This test case is currently broken because of a NullPOinterException
|
||||
// in AbstractSpatialDisplayManager
|
||||
// Activator.getDefault() is returning null at the moment.
|
||||
public class TestSmartScript {
|
||||
|
||||
protected static final String testScriptName = "ROOT/build/static/common/cave/etc/gfe/userPython/tests/TestSmartScript.py";
|
||||
private static final String SCRIPT_FILE_PATH = new File(
|
||||
"./python/gfe/TestSmartScript.py").getPath();
|
||||
|
||||
protected static final String smartScriptPath = "ROOT/build/static/common/cave/etc/gfe/userPython/utilities"
|
||||
+ ":ROOT/build"
|
||||
+ ":ROOT/AWIPSEdex/opt/utility/common_static/base/python/gfe"
|
||||
+ ":ROOT/AWIPSEdex/opt/utility/common_static/base/python"
|
||||
+ ":ROOT/AWIPSEdex/extensions/plugin-gfe/src";
|
||||
private PythonScript testScript = null;
|
||||
|
||||
/**
|
||||
* A PythonScript. All PythonScript's constructors are protected, so we have
|
||||
* to create this subclass in order to obtain an instance. While we're at
|
||||
* it, create a modified execute() method and a helper method for setting
|
||||
* groups of script variables.
|
||||
*
|
||||
*/
|
||||
private DataManager dataMgr;
|
||||
|
||||
PythonMapScript testScript;
|
||||
|
||||
Map<String, Object> argmap;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
try {
|
||||
// Create a DataManager to pass to the SmartScript constructor.
|
||||
DataManager dataManager = null;
|
||||
Activator activator = Activator.getDefault();
|
||||
if (activator == null) {
|
||||
FakeDataManager fakeDataManager = new FakeDataManager();
|
||||
AbstractParmManager pm = new MockParmManager(fakeDataManager);
|
||||
fakeDataManager.setParmManager(pm);
|
||||
dataManager = fakeDataManager;
|
||||
} else {
|
||||
dataManager = DataManager.getInstance(null);
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
PathManagerFactoryTest.initLocalization();
|
||||
}
|
||||
|
||||
// Set up an interpreter that can run Python with Java classes.
|
||||
// Hopefully, using user.home will make this portable to any
|
||||
// developer.
|
||||
String root = System.getProperty("user.home") + File.separator
|
||||
+ "workspace";
|
||||
ClassLoader classLoader = dataManager.getClass().getClassLoader();
|
||||
testScript = new PythonMapScript(testScriptName.replaceAll("ROOT",
|
||||
root), smartScriptPath.replaceAll("ROOT", root),
|
||||
classLoader);
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
FakeDataManager fakeDataMgr = new FakeDataManager();
|
||||
IParmManager pm = new MockParmManager(fakeDataMgr);
|
||||
fakeDataMgr.setParmManager(pm);
|
||||
dataMgr = fakeDataMgr;
|
||||
|
||||
// Put the data manager in the interpreter
|
||||
Map<String, Object> setupMap = new HashMap<String, Object>();
|
||||
setupMap.put("dataManager", dataManager);
|
||||
testScript.setArgs(setupMap);
|
||||
|
||||
// Create a SmartScript instance for use by the tests.
|
||||
boolean evalResult;
|
||||
evalResult = testScript
|
||||
.evaluate("smartScript = SmartScript.SmartScript(dataManager)");
|
||||
|
||||
// If eval somehow failed without throwing a JepException, fail.
|
||||
assertTrue(evalResult);
|
||||
|
||||
// Create an argmap to pass parameters in.
|
||||
argmap = new HashMap<String, Object>();
|
||||
String includePath = PyUtil.buildJepIncludePath(
|
||||
GfePyIncludeUtil.getCommonPythonIncludePath(),
|
||||
GfePyIncludeUtil.getCommonGfeIncludePath(),
|
||||
GfePyIncludeUtil.getUtilitiesIncludePath());
|
||||
try {
|
||||
testScript = new PythonScript(SCRIPT_FILE_PATH, includePath, this
|
||||
.getClass().getClassLoader());
|
||||
} catch (JepException e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
@Override
|
||||
public void tearDown() {
|
||||
// Free any resources the previous interpreter used.
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (testScript != null) {
|
||||
testScript.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the createGrid method of SmartScript.py when creating a discrete
|
||||
* grid.
|
||||
*
|
||||
* NOTE: This test currently throws an exception because one of the objects
|
||||
* supplied by MockParmManager always has a grid type of "SCALAR", which
|
||||
* leads to a ClassCastException in the grid cycler when SmartScript passes
|
||||
* a byte grid and keys to the grid cycler. If the code in the grid cycler
|
||||
* is hacked to force the grid type to "DISCRETE" for the test, it completes
|
||||
* successfully.
|
||||
*/
|
||||
@Test
|
||||
public void testCreateGridDiscrete() throws Exception {
|
||||
argmap.put("model", "Fcst");
|
||||
argmap.put("element", "hazXXX1234");
|
||||
argmap.put("elementType", "DISCRETE");
|
||||
argmap.put("timeRange", new TimeRange(new Date(), 10 * 3600 * 1000L));
|
||||
argmap.put("descriptiveName", "Discrete Test Grid");
|
||||
argmap.put("::timeConstraints", "tcTuple");
|
||||
argmap.put("units", "");
|
||||
argmap.put("::discreteKeys", "dkList");
|
||||
argmap.put("discreteOverlap", Boolean.FALSE);
|
||||
argmap.put("discreteAuxDataLength", Integer.valueOf(4));
|
||||
argmap.put("defaultColorTable", "YesNo");
|
||||
argmap.put("::numericGrid", "discreteGrid");
|
||||
Object obj = null;
|
||||
try {
|
||||
if (!testScript.evaluate("tcTuple = (1000, 1200, 600)")) {
|
||||
throw new Exception("eval(\"tcTuple... failed.");
|
||||
}
|
||||
if (!testScript
|
||||
.evaluate("dkList = ['One', ('Singular', 'Sensation')]")) {
|
||||
throw new Exception("eval(\"dklist = ... failed.");
|
||||
}
|
||||
obj = testScript.execute("createGrid", "smartScript", argmap);
|
||||
} catch (JepException e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testSortUglyStr() throws Exception {
|
||||
Map<String, Object> argmap = new HashMap<String, Object>(2, 1.0f);
|
||||
argmap.put("uglyStr", "I^AM^THE^CAPTAIN^OF^PINAFORE");
|
||||
argmap.put("dataMgr", dataMgr);
|
||||
String outstr = null;
|
||||
try {
|
||||
outstr = (String) testScript.execute("sortUglyStr", "smartScript",
|
||||
outstr = (String) testScript.execute("testSortUglyStr", null,
|
||||
argmap);
|
||||
} catch (JepException e) {
|
||||
throw new Exception(e);
|
||||
|
@ -194,43 +126,34 @@ public class TestSmartScript extends TestCase {
|
|||
|
||||
@Test
|
||||
public void testGetIndex() throws Exception {
|
||||
Map<String, Object> argmap = new HashMap<String, Object>(3, 1.0f);
|
||||
argmap.put("dataMgr", dataMgr);
|
||||
|
||||
String key1 = "Twas^Brillig^and^the^slithy^toves";
|
||||
String key2 = "Did^gyre^and^gimbol^in^the^wabe";
|
||||
String key3 = "Twas^Brillig^and";
|
||||
String key4 = "and^slithy^the^toves^Brillig^Twas";
|
||||
List<String> keyList = Arrays.asList(key1, key2, key3, key4);
|
||||
argmap.put("keyList", keyList);
|
||||
|
||||
for (int i = 0; i < keyList.size(); i++) {
|
||||
Integer outInt = null;
|
||||
argmap.put("uglyStr", keyList.get(i));
|
||||
try {
|
||||
testScript.evaluate("keyList = []");
|
||||
argmap.put("::keys", "keyList");
|
||||
argmap.put("uglyStr", key1);
|
||||
outInt = (Integer) testScript.execute("getIndex", "smartScript",
|
||||
outInt = (Integer) testScript.execute("testGetIndex", null,
|
||||
argmap);
|
||||
assertEquals("key1", 0, outInt.intValue());
|
||||
|
||||
argmap.put("uglyStr", key2);
|
||||
outInt = (Integer) testScript.execute("getIndex", "smartScript",
|
||||
argmap);
|
||||
assertEquals("key2", 1, outInt.intValue());
|
||||
|
||||
argmap.put("uglyStr", key3);
|
||||
outInt = (Integer) testScript.execute("getIndex", "smartScript",
|
||||
argmap);
|
||||
assertEquals("key3", 2, outInt.intValue());
|
||||
|
||||
argmap.put("uglyStr", key4);
|
||||
outInt = (Integer) testScript.execute("getIndex", "smartScript",
|
||||
argmap);
|
||||
assertEquals("key4", 0, outInt.intValue());
|
||||
|
||||
assertEquals("key" + (i + 1), i, outInt.intValue());
|
||||
} catch (JepException e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGridShape() throws Exception {
|
||||
try {
|
||||
Map<String, Object> argmap = new HashMap<String, Object>(1, 1.0f);
|
||||
argmap.put("dataMgr", dataMgr);
|
||||
Boolean testResult = (Boolean) testScript.execute(
|
||||
"testGetGridShape", null, argmap);
|
||||
assertTrue("Tuples should match", testResult);
|
||||
|
@ -241,16 +164,18 @@ public class TestSmartScript extends TestCase {
|
|||
|
||||
@Test
|
||||
public void testGetGridInfo() throws Exception {
|
||||
Map<String, Object> argmap = new HashMap<String, Object>(5, 1.0f);
|
||||
argmap.put("dataMgr", dataMgr);
|
||||
argmap.put("model", "Fcst");
|
||||
argmap.put("element", "Hazards");
|
||||
argmap.put("level", "SFC");
|
||||
|
||||
Parm parm = null;
|
||||
try {
|
||||
parm = (Parm) testScript.execute("getParm", "smartScript", argmap);
|
||||
} catch (JepException e1) {
|
||||
throw new Exception(e1);
|
||||
parm = (Parm) testScript.execute("getParm", null, argmap);
|
||||
} catch (JepException e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
assertNotNull("Retrieved Hazards_SFC parm.", parm);
|
||||
|
||||
TimeRange tr = new TimeRange(new Date(), 1000L);
|
||||
boolean created = parm.createFromScratchTR(tr,
|
||||
|
@ -272,6 +197,5 @@ public class TestSmartScript extends TestCase {
|
|||
} catch (JepException e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue