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