package tudelft.utilities.j2p; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Paths; import java.util.Arrays; import org.junit.Before; import org.junit.Test; import tudelft.utilities.j2p.t.TranslationException; import tudelft.utilities.logging.Reporter; import tudelft.utilities.logging.SavingReporter; import tudelft.utilities.pyrunner.PythonError; import tudelft.utilities.pyrunner.PythonVenv; import tudelft.utilities.pyrunner.TestResult; /** * run a program that uses clazz.getResources() including and accessing * resources is tricky because (see #304) *
    *
  1. the resource has to end up in the python zip file somewhere *
  2. pip install (which is used to install the zip file) puts it somewhere *
  3. our translators have to find the location *
  4. the file contents have to be made accessible *
*/ public class GetResourcesTst { private PyProgram program; @Before public void before() throws TranslationException { program = PyProgram .fromDirectories(Arrays.asList((Paths.get("resourcestest")))); } @Test public void test() throws IOException, ClassNotFoundException { System.out.println(program); } @Test public void runFromZip() throws FileNotFoundException, IOException, InterruptedException, PythonError { File zipfile = program.getZip(); System.out.println("zip file at " + zipfile); Reporter reporter = new SavingReporter("test"); PythonVenv venv = new PythonVenv(zipfile, reporter); TestResult res = venv.test("testcode", 10000); assertTrue(res.toString(), res.isSuccess()); } }