source: java2python/jackson-t/src/test/java/tudelft/utilities/j2p/ActionsUseTest.java@ 505

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

#161 restructuring test code, each test program in its own dir.

File size: 2.0 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
20/**
21 * A more complex package involving multiple files.
22 */
23public class ActionsUseTest {
24
25 PyProgram program = PyProgram
26 .fromDirectory(Paths.get("src/test/javaactions"));
27
28 @Test
29 public void test() throws IOException, ClassNotFoundException {
30 System.out.println(program);
31 }
32
33 @Test
34 public void runFromZip() throws FileNotFoundException, IOException,
35 InterruptedException, PythonError {
36 File zipfile = program.getZip();
37 // File zipfile = zip(translate(TESTDIR + FULLNAME), new File(FULLNAME));
38 System.out.println("zip file at " + zipfile);
39 Reporter reporter = new Reporter() {
40 private List<String> warnings = new LinkedList<>();
41
42 @Override
43 public void log(Level level, String msg) {
44 log(level, msg, null);
45 }
46
47 @Override
48 public void log(Level level, String msg, Throwable thrown) {
49 if (level == Level.WARNING || level == Level.SEVERE) {
50 warnings.add(msg);
51 System.err.println(msg);
52 if (thrown != null)
53 thrown.printStackTrace();
54 } else {
55 System.out.println(level + ":" + msg);
56 }
57 }
58 };
59 PythonVenv venv = new PythonVenv(zipfile, reporter);
60 String res = venv.call(
61 Arrays.asList("-m", "testcode.actions.ActionsUse"), 10000);
62 System.out.println(res);
63 assertEquals("serializeAcceptTest\n"
64 + "{\"Accept\":{\"actor\":\"party1\",\"bid\":\"issuevalues\"}}\n"
65 + "deserializeAcceptTest\n" + "Accept[party1,issuevalues]\n"
66 + "AlltestsOK\n", res.replace(" ", ""));
67 // as in Java but true->True and pyson inserts some extra whitespace
68 }
69
70}
Note: See TracBrowser for help on using the repository browser.