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.Test;
|
---|
12 |
|
---|
13 | import tudelft.utilities.logging.Reporter;
|
---|
14 | import tudelft.utilities.logging.SavingReporter;
|
---|
15 | import tudelft.utilities.pyrunner.PythonError;
|
---|
16 | import tudelft.utilities.pyrunner.PythonVenv;
|
---|
17 |
|
---|
18 | public class ValueTest {
|
---|
19 |
|
---|
20 | PyProgram program = PyProgram.fromDirectory(Paths.get("src/test/value"));
|
---|
21 |
|
---|
22 | @Test
|
---|
23 | public void test() throws IOException, ClassNotFoundException {
|
---|
24 | System.out.println(program);
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Test
|
---|
28 | public void runFromZip() throws FileNotFoundException, IOException,
|
---|
29 | InterruptedException, PythonError {
|
---|
30 | File zipfile = program.getZip();
|
---|
31 | System.out.println("zip file at " + zipfile);
|
---|
32 | Reporter reporter = new SavingReporter("test");
|
---|
33 | PythonVenv venv = new PythonVenv(zipfile, reporter);
|
---|
34 | String res = venv.call(Arrays.asList("-m", "testcode.Value"), 10000);
|
---|
35 | System.out.println(res);
|
---|
36 | assertEquals(Arrays.asList("{\"value\":12.0}", "{\"value\":\"hallo\"}"),
|
---|
37 | Arrays.asList(res.replace(" ", "").split("\n")));
|
---|
38 | // as in Java but true->True and pyson inserts some extra whitespace
|
---|
39 | }
|
---|
40 | } |
---|