source: java2python/jackson-t/src/test/java/tudelft/utilities/j2p/ValueTest.java@ 506

Last change on this file since 506 was 506, checked in by wouter, 17 months ago

#161 PyProgram.fromDirectory introduced to clean up test code. Moved test programs to separate folders each.

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