Skip to content

Commit

Permalink
test: fix macro test for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Apr 24, 2024
1 parent ca8ae04 commit 0458574
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions src/test/java/org/janelia/saalfeldlab/n5/ij/MacroTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

import org.janelia.saalfeldlab.n5.N5Exception;
import org.janelia.saalfeldlab.n5.N5Reader;
import org.janelia.saalfeldlab.n5.N5Writer;
import org.janelia.saalfeldlab.n5.RunImportExportTest;
import org.janelia.saalfeldlab.n5.TestExportImports;
import org.janelia.saalfeldlab.n5.universe.N5Factory;
import org.junit.After;
Expand All @@ -30,38 +30,57 @@

public class MacroTests {

private File containerDir;

private File n5rootF;

private File containerDir;
private String dataset;

private ImagePlus imp;

@Before
public void before() {
System.setProperty("java.awt.headless", "true");

final String n5Root = "src/test/resources/test.n5";
n5rootF = new File(n5Root);
containerDir = new File(tempN5PathName());

final URL configUrl = RunImportExportTest.class.getResource( "/plugins.config" );
final File baseDir = new File( configUrl.getFile() ).getParentFile();
containerDir = new File( baseDir, "macrotest.n5" );
System.out.println( containerDir.getAbsolutePath() );
n5rootF = Paths.get("src", "test", "resources", "test.n5").toFile();
dataset = "dataset";

imp = NewImage.createImage("test", 8, 7, 9, 16, NewImage.FILL_NOISE);
final String format = N5ScalePyramidExporter.AUTO_FORMAT;
final String format = N5ScalePyramidExporter.N5_FORMAT;

final N5ScalePyramidExporter writer = new N5ScalePyramidExporter();
writer.setOptions( imp, containerDir.getAbsolutePath(), "dataset", format, "16,16,16", false,
writer.setOptions( imp, containerDir.getAbsolutePath(), dataset, format, "16,16,16", false,
N5ScalePyramidExporter.NONE, N5ScalePyramidExporter.DOWN_SAMPLE, N5ScalePyramidExporter.RAW_COMPRESSION);
writer.run(); // run() closes the n5 writer
}

@After
public void after() {

final N5Writer n5 = new N5Factory().openWriter(containerDir.getAbsolutePath());
n5.remove();
N5Writer n5;
try {
n5 = new N5Factory().openWriter(containerDir.getCanonicalPath());
n5.remove();
} catch (IOException e) {}
}

private static String tempN5PathName() {

try {
final File tmpFile = Files.createTempDirectory("n5-ij-macro-test-").toFile();
tmpFile.deleteOnExit();
return tmpFile.getCanonicalPath();
} catch (final Exception e) {
throw new RuntimeException(e);
}
}

protected String tempN5Location() throws URISyntaxException {

final String basePath = new File(tempN5PathName()).toURI().normalize().getPath();
return new URI("file", null, basePath, null).toString();
}

@Test
Expand All @@ -78,7 +97,7 @@ public void testMacroContentHelper( String urlFormat ) {

// URL
final N5Importer plugin = (N5Importer)IJ.runPlugIn("org.janelia.saalfeldlab.n5.ij.N5Importer",
String.format( urlFormat + " hide", containerDir.getAbsolutePath(), "dataset" ));
String.format( urlFormat + " hide", containerDir.getAbsolutePath(), dataset ));

final List<ImagePlus> res = plugin.getResult();
final ImagePlus imgImported = res.get(0);
Expand Down Expand Up @@ -107,7 +126,7 @@ public void testMacroContentHelper( String urlFormat ) {
public void testMacro() {

final N5Importer plugin = (N5Importer)IJ.runPlugIn("org.janelia.saalfeldlab.n5.ij.N5Importer",
String.format("url=%s/%s hide", n5rootF.getAbsolutePath(), "cosem" ));
String.format("url=%s?%s hide", n5rootF.getAbsolutePath(), "cosem" ));

final List<ImagePlus> res = plugin.getResult();
assertEquals(" crop num", 1, res.size());
Expand All @@ -121,7 +140,7 @@ public void testMacro() {
@Test
public void testMacroVirtual() {
final N5Importer plugin = (N5Importer)IJ.runPlugIn("org.janelia.saalfeldlab.n5.ij.N5Importer",
String.format("url=%s/%s hide virtual", n5rootF.getAbsolutePath(), "cosem" ));
String.format("url=%s?%s hide virtual", n5rootF.getAbsolutePath(), "cosem" ));

final List<ImagePlus> res = plugin.getResult();
assertEquals(" crop num", 1, res.size());
Expand All @@ -135,7 +154,7 @@ public void testMacroCrop() {
final String maxString = "250,250,120";

final N5Importer plugin = (N5Importer)IJ.runPlugIn("org.janelia.saalfeldlab.n5.ij.N5Importer",
String.format("url=%s/%s hide min=%s max=%s",
String.format("url=%s?%s hide min=%s max=%s",
n5rootF.getAbsolutePath(), "cosem", minString, maxString ));

final List<ImagePlus> res = plugin.getResult();
Expand Down

0 comments on commit 0458574

Please sign in to comment.