Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ability to run compiled scripts in python 3.
Fixes #77
- Loading branch information
1 parent
2e51066
commit 96445a5
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package jep.test; | ||
|
||
import java.lang.IllegalStateException; | ||
import java.lang.Boolean; | ||
|
||
import jep.Jep; | ||
import jep.JepConfig; | ||
import jep.JepException; | ||
|
||
/** | ||
* Tests that a compiled script can be loaded by Jep.runscript() | ||
* | ||
* Created: May 2017 | ||
* | ||
* @author Ben Steffensmeier | ||
*/ | ||
public class TestCompiledScript { | ||
|
||
public static void main(String[] args) throws JepException{ | ||
JepConfig config = new JepConfig(); | ||
config.addIncludePaths("."); | ||
Jep jep = new Jep(config); | ||
jep.eval("import py_compile"); | ||
jep.eval("py_compile.compile(file='build/testScript.py', cfile='build/testScript.pyc')"); | ||
jep.eval(null); | ||
jep.runScript("build/testScript.pyc"); | ||
Object result = jep.getValue("isGood()"); | ||
jep.close(); | ||
if(!Boolean.TRUE.equals(result)){ | ||
throw new IllegalStateException("isGood() returned " + result); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import unittest | ||
import os | ||
import os.path | ||
|
||
from tests.jep_pipe import jep_pipe | ||
from tests.jep_pipe import build_java_process_cmd | ||
|
||
|
||
class TestRunScript(unittest.TestCase): | ||
|
||
def setUp(self): | ||
with open('build/testScript.py', 'w') as testScript: | ||
testScript.write("def isGood():\n") | ||
testScript.write(" return True\n") | ||
|
||
|
||
def test_compiledScript(self): | ||
jep_pipe(build_java_process_cmd('jep.test.TestCompiledScript')) | ||
|
||
|
||
def tearDown(self): | ||
if os.path.exists('build/testScript.py'): | ||
os.remove('build/testScript.py') | ||
if os.path.exists('build/testScript.pyc'): | ||
os.remove('build/testScript.pyc') | ||
|