saalfeldlab / n5

Not HDF5
BSD 2-Clause "Simplified" License
163 stars 22 forks source link

Handle test temp files in a better way #88

Closed ctrueden closed 1 year ago

ctrueden commented 1 year ago

The tests need a temp directory for testing read/write behaviors. In N5FSTest, the testDirPath is set to ~/tmp/n5-test. But this clutters up the user's home directory, especially since this directory is not deleted after testing is complete. Better would be to use Files.createTempDirectory to create the directory in the dedicated temp file space, and File.deleteOnExit to remove it cleanly when the JVM shuts down.

This is also an issue with the various n5 extensions:

$ rg tmp.n5-test
n5-blosc/src/test/java/org/janelia/saalfeldlab/n5/blosc/BloscCompressionTest.java
52: static private String testDirPath = System.getProperty("user.home") + "/tmp/n5-test";

n5-viewer/src/test/java/org/janelia/saalfeldlab/n5/bdv/N5SourceFromMetadataTest.java
34: static private String testDirPath = System.getProperty("user.home") + "/tmp/n5-test";

n5-zarr/src/test/java/org/janelia/saalfeldlab/n5/zarr/N5ZarrTest.java
78: static private String testDirPath = System.getProperty("user.home") + "/tmp/n5-test.zarr";

n5-hdf5/src/test/java/org/janelia/saalfeldlab/n5/hdf5/N5HDF5Test.java
76: private static String testDirPath = System.getProperty("user.home") + "/tmp/n5-test.hdf5";

n5-ij/src/test/java/org/janelia/saalfeldlab/n5/MetadataIoTests.java
67: static private String testDirPath = System.getProperty("user.home") + "/tmp/n5-test";

n5/src/test/java/org/janelia/saalfeldlab/n5/N5FSTest.java
29: static private String testDirPath = System.getProperty("user.home") + "/tmp/n5-test";
cmhulbert commented 1 year ago

@ctrueden seems we were a little late to getting this fixed, sorry for that. In the new N5 version (and all the related n5 dependencies that had this issue) this should be resolved already in n5 3.0.0+. We did a similar thing to what you recently show in your PRs. Please reopen this if you still are running into this issue with the newest n5 releases.

ctrueden commented 1 year ago

@cmhulbert Haha, I totally forgot I had written up this issue when I filed all the N5 PRs attempting to fix it. I was just independently re-annoyed by the existence of ~/tmp filled with n5 test vestiges, and decided to look into what it would take to address it. Thanks for working on it, much appreciated.