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
|
---|
27 | .fromDirectories(Arrays.asList((Paths.get("src/test/value"))));
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void test() throws IOException, ClassNotFoundException {
|
---|
32 | System.out.println(program);
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Test
|
---|
36 | public void runFromZip() throws FileNotFoundException, IOException,
|
---|
37 | InterruptedException, PythonError {
|
---|
38 | File zipfile = program.getZip();
|
---|
39 | System.out.println("zip file at " + zipfile);
|
---|
40 | Reporter reporter = new SavingReporter("test");
|
---|
41 | PythonVenv venv = new PythonVenv(zipfile, reporter);
|
---|
42 | String res = venv.call(Arrays.asList("-m", "testcode.Value"), 10000);
|
---|
43 | System.out.println(res);
|
---|
44 | assertEquals(Arrays.asList("{\"value\":12.0}", "{\"value\":\"hallo\"}"),
|
---|
45 | Arrays.asList(res.replace(" ", "").split("\n")));
|
---|
46 | // as in Java but true->True and pyson inserts some extra whitespace
|
---|
47 | }
|
---|
48 | } |
---|