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

Last change on this file since 491 was 477, checked in by wouter, 17 months ago
File size: 1.9 KB
RevLine 
[418]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);
[477]63 String res = venv.call(Arrays.asList("-m", "testcode.Value"), 10000);
[418]64 System.out.println(res);
65 assertEquals("{\"value\":12.0}\n" + "{\"value\":\"hallo\"}",
66 res.replace(" ", ""));
67 // as in Java but true->True and pyson inserts some extra whitespace
68 }
69}
Note: See TracBrowser for help on using the repository browser.