1 | package tudelft.utilities.j2p;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.FileNotFoundException;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.nio.file.Paths;
|
---|
7 | import java.util.Arrays;
|
---|
8 |
|
---|
9 | import org.junit.Before;
|
---|
10 | import org.junit.Test;
|
---|
11 |
|
---|
12 | import tudelft.utilities.j2p.t.TranslationException;
|
---|
13 | import tudelft.utilities.logging.Reporter;
|
---|
14 | import tudelft.utilities.logging.SavingReporter;
|
---|
15 | import tudelft.utilities.pyrunner.PythonError;
|
---|
16 | import tudelft.utilities.pyrunner.PythonVenv;
|
---|
17 | import tudelft.utilities.pyrunner.TestResult;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * run a program that uses clazz.getResources() including and accessing
|
---|
21 | * resources is tricky because (see #304)
|
---|
22 | * <ol>
|
---|
23 | * <li>the resource has to end up in the python zip file somewhere
|
---|
24 | * <li>pip install (which is used to install the zip file) puts it somewhere
|
---|
25 | * <li>our translators have to find the location
|
---|
26 | * <li>the file contents have to be made accessible
|
---|
27 | * </ol>
|
---|
28 | */
|
---|
29 | public class GetResourcesTest {
|
---|
30 | private PyProgram program;
|
---|
31 |
|
---|
32 | @Before
|
---|
33 | public void before() throws TranslationException {
|
---|
34 | program = PyProgram
|
---|
35 | .fromDirectories(Arrays.asList((Paths.get("resourcestest"))));
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Test
|
---|
39 | public void test() throws IOException, ClassNotFoundException {
|
---|
40 | System.out.println(program);
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Test
|
---|
44 | public void runFromZip() throws FileNotFoundException, IOException,
|
---|
45 | InterruptedException, PythonError {
|
---|
46 | File zipfile = program.getZip();
|
---|
47 | System.out.println("zip file at " + zipfile);
|
---|
48 | Reporter reporter = new SavingReporter("test");
|
---|
49 | PythonVenv venv = new PythonVenv(zipfile, reporter);
|
---|
50 | // String res = venv.call(Arrays.asList("-m", "testcode.GetResourcesTest"),
|
---|
51 | // 10000);
|
---|
52 | TestResult res = venv.test("testcode", 10000);
|
---|
53 | System.out.println(res);
|
---|
54 | //assertEquals(new String[] { "ok1" }, res.split("\n"));
|
---|
55 | }
|
---|
56 |
|
---|
57 | }
|
---|