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 | import java.util.LinkedList;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.logging.Level;
|
---|
13 |
|
---|
14 | import org.junit.Test;
|
---|
15 |
|
---|
16 | import tudelft.utilities.logging.Reporter;
|
---|
17 | import tudelft.utilities.pyrunner.PythonError;
|
---|
18 | import tudelft.utilities.pyrunner.PythonVenv;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * A more complex package involving multiple files.
|
---|
22 | */
|
---|
23 | public 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 | }
|
---|