source: java2python/jackson-t/src/test/java/ValueTest.java@ 430

Last change on this file since 430 was 418, checked in by wouter, 2 years ago

#126 added Value, ValueTest . This closely reflects using a custom deserializer whcih we need . The test is currently failing

File size: 2.0 KB
Line 
1
2import static org.junit.Assert.assertEquals;
3
4import java.io.File;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.nio.file.Path;
8import java.nio.file.Paths;
9import java.util.Arrays;
10import java.util.LinkedList;
11import java.util.List;
12import java.util.logging.Level;
13
14import org.junit.Test;
15
16import tudelft.utilities.j2p.PyModule;
17import tudelft.utilities.j2p.PyProgram;
18import tudelft.utilities.logging.Reporter;
19import tudelft.utilities.pyrunner.PythonError;
20import tudelft.utilities.pyrunner.PythonVenv;
21
22public class ValueTest {
23
24 private final static Path TESTPATH = Paths.get("src/test/java");
25 private final static File FILE = new File("testcode/Value.java");
26
27 @Test
28 public void test() throws IOException, ClassNotFoundException {
29 System.out.println(getProgram());
30 }
31
32 private PyProgram getProgram() throws FileNotFoundException {
33 return new PyProgram(
34 Arrays.asList(PyModule.fromJavaFile(TESTPATH, FILE)));
35 }
36
37 @Test
38 public void runFromZip() throws FileNotFoundException, IOException,
39 InterruptedException, PythonError {
40 File zipfile = getProgram().getZip();
41 System.out.println("zip file at " + zipfile);
42 Reporter reporter = new Reporter() {
43 private List<String> warnings = new LinkedList<>();
44
45 @Override
46 public void log(Level level, String msg) {
47 log(level, msg, null);
48 }
49
50 @Override
51 public void log(Level level, String msg, Throwable thrown) {
52 if (level == Level.WARNING || level == Level.SEVERE) {
53 warnings.add(msg);
54 System.err.println(msg);
55 if (thrown != null)
56 thrown.printStackTrace();
57 } else {
58 System.out.println(level + ":" + msg);
59 }
60 }
61 };
62 PythonVenv venv = new PythonVenv(zipfile, reporter);
63 String res = venv.call(
64 Arrays.asList("-m", "testcode.actions.ActionsUse"), 10000);
65 System.out.println(res);
66 assertEquals("{\"value\":12.0}\n" + "{\"value\":\"hallo\"}",
67 res.replace(" ", ""));
68 // as in Java but true->True and pyson inserts some extra whitespace
69 }
70}
Note: See TracBrowser for help on using the repository browser.