source: java2python/junit-t/src/test/java/tudelft/utilities/j2p/GetResourcesTest.java@ 896

Last change on this file since 896 was 896, checked in by wouter, 5 months ago

#310 moved GetResourcesTest to junit-t because this test is so much easier if we have junit translator and package translation. junit tests now require @RunWith annotation for proper translation. Added more translators

File size: 1.7 KB
Line 
1package tudelft.utilities.j2p;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.nio.file.Paths;
7import java.util.Arrays;
8
9import org.junit.Before;
10import org.junit.Test;
11
12import tudelft.utilities.j2p.t.TranslationException;
13import tudelft.utilities.logging.Reporter;
14import tudelft.utilities.logging.SavingReporter;
15import tudelft.utilities.pyrunner.PythonError;
16import tudelft.utilities.pyrunner.PythonVenv;
17import 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 */
29public 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}
Note: See TracBrowser for help on using the repository browser.