1 | package tudelft.utilities.j2p;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.File;
|
---|
6 | import java.io.FileNotFoundException;
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.nio.file.Paths;
|
---|
9 | import java.util.Arrays;
|
---|
10 |
|
---|
11 | import org.junit.Before;
|
---|
12 | import org.junit.Test;
|
---|
13 |
|
---|
14 | import tudelft.utilities.j2p.t.TranslationException;
|
---|
15 | import tudelft.utilities.logging.Reporter;
|
---|
16 | import tudelft.utilities.logging.SavingReporter;
|
---|
17 | import tudelft.utilities.pyrunner.PythonError;
|
---|
18 | import tudelft.utilities.pyrunner.PythonVenv;
|
---|
19 |
|
---|
20 | public class ValueTest {
|
---|
21 |
|
---|
22 | PyProgram program;
|
---|
23 |
|
---|
24 | @Before
|
---|
25 | public void before() throws TranslationException {
|
---|
26 | program = PyProgram.fromDirectory(Paths.get("src/test/value"));
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Test
|
---|
30 | public void test() throws IOException, ClassNotFoundException {
|
---|
31 | System.out.println(program);
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Test
|
---|
35 | public void runFromZip() throws FileNotFoundException, IOException,
|
---|
36 | InterruptedException, PythonError {
|
---|
37 | File zipfile = program.getZip();
|
---|
38 | System.out.println("zip file at " + zipfile);
|
---|
39 | Reporter reporter = new SavingReporter("test");
|
---|
40 | PythonVenv venv = new PythonVenv(zipfile, reporter);
|
---|
41 | String res = venv.call(Arrays.asList("-m", "testcode.Value"), 10000);
|
---|
42 | System.out.println(res);
|
---|
43 | assertEquals(Arrays.asList("{\"value\":12.0}", "{\"value\":\"hallo\"}"),
|
---|
44 | Arrays.asList(res.replace(" ", "").split("\n")));
|
---|
45 | // as in Java but true->True and pyson inserts some extra whitespace
|
---|
46 | }
|
---|
47 | } |
---|