use of org.scijava.Context in project imagej-ops by imagej.
the class ReadmeExampleTest method testReadmesExample.
@Test
public void testReadmesExample() throws Exception {
// extract the example script
final File readme = new File("README.md");
final String contents = new String(FileUtils.readFile(readme), "UTF-8");
final String telltale = String.format("```python%n");
final int begin = contents.indexOf(telltale) + telltale.length();
assertTrue(begin > telltale.length());
assertTrue(contents.indexOf(telltale, begin) < 0);
final int end = contents.indexOf(String.format("```%n"), begin);
assertTrue(end > 0);
final String snippet = contents.substring(begin, end);
assertTrue(snippet.startsWith("# @ImageJ ij"));
final Context context = new Context();
final ScriptService script = context.getService(ScriptService.class);
// create mock ImageJ gateway
script.addAlias("ImageJ", Mock.class);
final ScriptModule module = script.run("op-example.py", snippet, true).get();
assertNotNull(module);
module.run();
final Mock ij = context.getService(Mock.class);
assertEquals(3, ij.images.size());
assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3);
assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3);
assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3);
}
Aggregations