4
4
import shutil
5
5
from datetime import datetime
6
6
from dateutil .tz import tzlocal
7
+ from pathlib import Path
8
+
9
+ from hdmf .testing import TestCase
7
10
8
11
try :
9
12
from pynwb import NWBFile
14
17
15
18
16
19
@unittest .skipIf (not PYNWB_AVAILABLE , "PyNWB not installed" )
17
- class TestNWBZarrIO (unittest . TestCase ):
20
+ class TestNWBZarrIO (TestCase ):
18
21
19
22
def setUp (self ):
20
- self .filepath = "test_io.zarr"
21
-
22
- def tearDown (self ):
23
- if os .path .exists (self .filepath ):
24
- shutil .rmtree (self .filepath )
25
-
26
- def write_test_file (self ):
27
- # Create the NWBFile
28
- nwbfile = NWBFile (
23
+ self .filepath = "test_io.nwb.zarr"
24
+ self .nwbfile = NWBFile (
29
25
session_description = "my first synthetic recording" ,
30
26
identifier = "EXAMPLE_ID" ,
31
27
session_start_time = datetime .now (tzlocal ()),
@@ -35,11 +31,33 @@ def write_test_file(self):
35
31
experiment_description = "I went on an adventure with thirteen dwarves to reclaim vast treasures." ,
36
32
session_id = "LONELYMTN" ,
37
33
)
38
-
39
34
# Create a device
40
- nwbfile .create_device (name = "array" , description = "the best array" , manufacturer = "Probe Company 9000" )
35
+ self .nwbfile .create_device (name = "array" , description = "the best array" , manufacturer = "Probe Company 9000" )
36
+
37
+ def tearDown (self ):
38
+ if os .path .exists (self .filepath ):
39
+ shutil .rmtree (self .filepath )
40
+
41
+ def write_test_file (self ):
41
42
with NWBZarrIO (path = self .filepath , mode = "w" ) as io :
42
- io .write (nwbfile )
43
+ io .write (self .nwbfile )
44
+
45
+ def test_file_extension_warning (self ):
46
+ """Test that a warning is raised when the file extension is not .nwb.zarr"""
47
+ wrong_filepath = Path (self .filepath ).with_suffix ('.h5' )
48
+
49
+ msg = (f"The file path provided: { wrong_filepath } does not end in '.nwb.zarr'. "
50
+ "It is recommended that NWB files using the Zarr backend use the '.nwb.zarr' extension" )
51
+
52
+ with self .assertWarnsWith (UserWarning , msg ):
53
+ with NWBZarrIO (path = wrong_filepath , mode = "w" ) as io :
54
+ io .write (self .nwbfile )
55
+
56
+ # should not warn on read or append
57
+ with NWBZarrIO (wrong_filepath , 'r' ) as io :
58
+ io .read ()
59
+ with NWBZarrIO (wrong_filepath , 'a' ) as io :
60
+ io .read ()
43
61
44
62
def test_read_nwb (self ):
45
63
"""
0 commit comments