| 1 |
import unittest |
| 2 |
|
| 3 |
import jpyutil |
| 4 |
|
| 5 |
jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=['target/classes', 'target/test-classes']) |
| 6 |
import jpy |
| 7 |
|
| 8 |
|
| 9 |
class TestEvalExec(unittest.TestCase): |
| 10 |
def setUp(self): |
| 11 |
self.fixture = jpy.get_type("org.jpy.fixtures.EvalTestFixture") |
| 12 |
self.assertIsNotNone(self.fixture) |
| 13 |
|
| 14 |
def test_foo_42(self): |
| 15 |
foo = 42 |
| 16 |
self.assertEqual(self.fixture.expression("foo"), 42) |
| 17 |
|
| 18 |
def test_foo_bar(self): |
| 19 |
foo = "bar" |
| 20 |
self.assertEqual(self.fixture.expression("foo"), "bar") |
| 21 |
|
| 22 |
def test_x_add_y(self): |
| 23 |
x = 123 |
| 24 |
y = 456 |
| 25 |
self.assertEqual(self.fixture.expression("x + y"), 579) |
| 26 |
|
| 27 |
def test_inc_baz(self): |
| 28 |
baz = 15 |
| 29 |
self.fixture.script("baz = baz + 1; self.assertEqual(baz, 16)") |
| 30 |
|
| 31 |
|
| 32 |
self.assertEqual(baz, 15) |
| 33 |
|
| 34 |
def test_exec_import(self): |
| 35 |
import sys |
| 36 |
self.assertTrue("json" not in sys.modules) |
| 37 |
self.fixture.script("import json") |
| 38 |
self.assertTrue("json" in sys.modules) |
| 39 |
|
| 40 |
|
| 41 |
if __name__ == '__main__': |
| 42 |
print('\nRunning ' + __file__) |
| 43 |
unittest.main() |