Skip to content

Commit ccece28

Browse files
committed
Propagate download test with datalad on test/iotest
1 parent 6ffe00d commit ccece28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+418
-761
lines changed

neo/test/iotest/common_io_test.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
assert_sub_schema_is_lazy_loaded,
3030
assert_children_empty)
3131

32-
from neo.test.rawiotest.tools import (can_use_network, make_all_directories,
33-
download_test_file, create_local_temp_dir)
32+
from neo.test.rawiotest.tools import can_use_network
33+
from neo.test.rawiotest.common_rawio_test import repo_for_test
34+
from neo.utils import download_dataset, get_local_testing_data_folder
3435

3536
from neo.test.iotest.tools import (cleanup_test_file,
3637
close_object_safe, create_generic_io_object,
@@ -40,11 +41,8 @@
4041
iter_generic_readers, iter_read_objects,
4142
read_generic,
4243
write_generic)
43-
from neo.test.generate_datasets import generate_from_supported_objects
44-
4544

46-
# url_for_tests = "https://portal.g-node.org/neo/" #This is the old place
47-
url_for_tests = "https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/"
45+
from neo.test.generate_datasets import generate_from_supported_objects
4846

4947

5048
class BaseTestIO:
@@ -67,8 +65,8 @@ class BaseTestIO:
6765
# all IO test need to modify this:
6866
ioclass = None # the IOclass to be tested
6967

70-
files_to_test = [] # list of files to test compliances
71-
files_to_download = [] # when files are at G-Node
68+
entities_to_test = [] # list of files to test compliances
69+
entities_to_download = [] # when files are at gin
7270

7371
# when reading then writing produces files with identical hashes
7472
hash_conserved_when_write_read = False
@@ -84,7 +82,6 @@ def setUp(self):
8482
'''
8583
Set up the test fixture. This is run for every test
8684
'''
87-
self.files_to_test = copy(self.__class__.files_to_test)
8885
self.higher = self.ioclass.supported_objects[0]
8986
self.shortname = self.ioclass.__name__.lower().rstrip('io')
9087
# these objects can both be written and read
@@ -93,11 +90,16 @@ def setUp(self):
9390
# these objects can be either written or read
9491
self.io_readorwrite = list(set(self.ioclass.readable_objects) |
9592
set(self.ioclass.writeable_objects))
96-
self.create_local_dir_if_not_exists()
97-
self.download_test_files_if_not_present()
93+
94+
for remote_path in self.entities_to_download:
95+
download_dataset(repo=repo_for_test, remote_path=remote_path)
96+
9897
self.files_generated = []
9998
self.generate_files_for_io_able_to_write()
100-
self.files_to_test.extend(self.files_generated)
99+
100+
# be carefull self.entities_to_test is class attributes
101+
self.files_to_test = [self.get_local_path(e) for e in self.entities_to_test]
102+
self.entities_to_test += self.files_generated
101103

102104
def create_local_dir_if_not_exists(self):
103105
'''
@@ -169,11 +171,33 @@ def able_to_write_or_read(self, writeread=False, readwrite=False):
169171

170172
return True
171173

174+
#~ def get_filename_path(self, filename):
175+
#~ '''
176+
#~ Get the path to a filename in the current temporary file directory
177+
#~ '''
178+
#~ return os.path.join(self.local_test_dir, filename)
179+
180+
def get_local_base_folder(self):
181+
return get_local_testing_data_folder()
182+
183+
def get_local_path(self, sub_path):
184+
root_local_path = self.get_local_base_folder()
185+
local_path = root_local_path / sub_path
186+
# TODO later : remove the str when all IOs handle the Path stuff
187+
local_path = str(local_path)
188+
return local_path
189+
172190
def get_filename_path(self, filename):
173-
'''
174-
Get the path to a filename in the current temporary file directory
175-
'''
176-
return os.path.join(self.local_test_dir, filename)
191+
# keep for backward compatibility
192+
# will be removed soon
193+
root_local_path = self.get_local_base_folder()
194+
local_path = root_local_path / self.shortname / filename
195+
# TODO later : remove the str when all IOs handle the Path stuff
196+
local_path = str(local_path)
197+
print('get_filename_path will be removed (use get_local_path() instead)', self.__class__.__name__, local_path)
198+
return local_path
199+
200+
177201

178202
def generic_io_object(self, filename=None, return_path=False, clean=False):
179203
'''

neo/test/iotest/test_alphaomegaio.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99

1010

1111
class TestAlphaOmegaIO(BaseTestIO, unittest.TestCase):
12-
files_to_test = ['File_AlphaOmega_1.map',
13-
'File_AlphaOmega_2.map']
14-
files_to_download = files_to_test
12+
entities_to_download =[
13+
'alphaomega'
14+
]
15+
entities_to_test = [
16+
'alphaomega/File_AlphaOmega_1.map',
17+
'alphaomega/File_AlphaOmega_2.map'
18+
]
1519
ioclass = AlphaOmegaIO
1620

1721

neo/test/iotest/test_asciisignalio.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
class TestAsciiSignalIOWithTestFiles(BaseTestIO, unittest.TestCase):
1818
ioclass = AsciiSignalIO
19-
files_to_download = [ # 'File_asciisignal_1.asc',
20-
'File_asciisignal_2.txt',
21-
'File_asciisignal_3.txt',
19+
entities_to_download = [
20+
'asciisignal'
21+
]
22+
entities_to_test = [
23+
'asciisignal/File_asciisignal_2.txt',
24+
'asciisignal/File_asciisignal_3.txt',
2225
]
23-
files_to_test = files_to_download
2426

2527

2628
class TestAsciiSignalIO(unittest.TestCase):

neo/test/iotest/test_asciispiketrainio.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
class TestAsciiSpikeTrainIO(BaseTestIO, unittest.TestCase, ):
1212
ioclass = AsciiSpikeTrainIO
13-
files_to_download = ['File_ascii_spiketrain_1.txt']
14-
files_to_test = files_to_download
13+
entities_to_download = [
14+
'asciispiketrain'
15+
]
16+
entities_to_test = [
17+
'asciispiketrain/File_ascii_spiketrain_1.txt',
18+
]
1519

1620

1721
if __name__ == "__main__":

neo/test/iotest/test_axographio.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,19 @@
1111
import numpy as np
1212
from numpy.testing import assert_equal
1313
import quantities as pq
14-
14+
from neo.test.rawiotest.test_axographrawio import TestAxographRawIO
1515

1616
class TestAxographIO(BaseTestIO, unittest.TestCase):
17-
files_to_test = [
18-
'AxoGraph_Graph_File', # version 1 file, provided with AxoGraph
19-
'AxoGraph_Digitized_File', # version 2 file, provided with AxoGraph
20-
'AxoGraph_X_File.axgx', # version 5 file, provided with AxoGraph
21-
'File_axograph.axgd', # version 6 file
22-
'episodic.axgd',
23-
'events_and_epochs.axgx',
24-
'written-by-axographio-with-linearsequence.axgx',
25-
'written-by-axographio-without-linearsequence.axgx',
26-
'corrupt-comment.axgx',
17+
entities_to_download = [
18+
'axograph'
2719
]
28-
files_to_download = files_to_test
20+
entities_to_test = TestAxographRawIO.entities_to_test
2921
ioclass = AxographIO
3022

3123
def test_version_1(self):
3224
"""Test reading a version 1 AxoGraph file"""
3325

34-
filename = self.get_filename_path('AxoGraph_Graph_File')
26+
filename = self.get_local_path('axograph/AxoGraph_Graph_File')
3527
reader = AxographIO(filename=filename)
3628
blk = reader.read_block(signal_group_mode='split-all')
3729
assert_equal(blk.annotations['format_ver'], 1)
@@ -55,7 +47,7 @@ def test_version_1(self):
5547
def test_version_2(self):
5648
"""Test reading a version 2 AxoGraph file"""
5749

58-
filename = self.get_filename_path('AxoGraph_Digitized_File')
50+
filename = self.get_local_path('axograph/AxoGraph_Digitized_File')
5951
reader = AxographIO(filename=filename)
6052
blk = reader.read_block(signal_group_mode='split-all')
6153
assert_equal(blk.annotations['format_ver'], 2)
@@ -85,7 +77,7 @@ def test_version_2(self):
8577
def test_version_5(self):
8678
"""Test reading a version 5 AxoGraph file"""
8779

88-
filename = self.get_filename_path('AxoGraph_X_File.axgx')
80+
filename = self.get_local_path('axograph/AxoGraph_X_File.axgx')
8981
reader = AxographIO(filename=filename)
9082
blk = reader.read_block(signal_group_mode='split-all')
9183
assert_equal(blk.annotations['format_ver'], 5)
@@ -109,7 +101,7 @@ def test_version_5(self):
109101
def test_version_6(self):
110102
"""Test reading a version 6 AxoGraph file"""
111103

112-
filename = self.get_filename_path('File_axograph.axgd')
104+
filename = self.get_local_path('axograph/File_axograph.axgd')
113105
reader = AxographIO(filename=filename)
114106
blk = reader.read_block(signal_group_mode='split-all')
115107
assert_equal(blk.annotations['format_ver'], 6)
@@ -133,7 +125,7 @@ def test_version_6(self):
133125
def test_file_written_by_axographio_package_with_linearsequence(self):
134126
"""Test reading file written by axographio package with linearsequence time column"""
135127

136-
filename = self.get_filename_path('written-by-axographio-with-linearsequence.axgx')
128+
filename = self.get_local_path('axograph/written-by-axographio-with-linearsequence.axgx')
137129
reader = AxographIO(filename=filename)
138130
blk = reader.read_block(signal_group_mode='split-all')
139131
assert_equal(blk.annotations['format_ver'], 6)
@@ -157,7 +149,7 @@ def test_file_written_by_axographio_package_with_linearsequence(self):
157149
def test_file_written_by_axographio_package_without_linearsequence(self):
158150
"""Test reading file written by axographio package without linearsequence time column"""
159151

160-
filename = self.get_filename_path('written-by-axographio-without-linearsequence.axgx')
152+
filename = self.get_local_path('axograph/written-by-axographio-without-linearsequence.axgx')
161153
reader = AxographIO(filename=filename)
162154
blk = reader.read_block(signal_group_mode='split-all')
163155
assert_equal(blk.annotations['format_ver'], 6)
@@ -181,7 +173,7 @@ def test_file_written_by_axographio_package_without_linearsequence(self):
181173
def test_file_with_corrupt_comment(self):
182174
"""Test reading a file with a corrupt comment"""
183175

184-
filename = self.get_filename_path('corrupt-comment.axgx')
176+
filename = self.get_local_path('axograph/corrupt-comment.axgx')
185177
reader = AxographIO(filename=filename)
186178
blk = reader.read_block(signal_group_mode='split-all')
187179
assert_equal(blk.annotations['format_ver'], 6)
@@ -205,7 +197,7 @@ def test_file_with_corrupt_comment(self):
205197
def test_multi_segment(self):
206198
"""Test reading an episodic file into multiple Segments"""
207199

208-
filename = self.get_filename_path('episodic.axgd')
200+
filename = self.get_local_path('axograph/episodic.axgd')
209201
reader = AxographIO(filename=filename)
210202
blk = reader.read_block(signal_group_mode='split-all')
211203

@@ -228,7 +220,7 @@ def test_multi_segment(self):
228220
def test_force_single_segment(self):
229221
"""Test reading an episodic file into one Segment"""
230222

231-
filename = self.get_filename_path('episodic.axgd')
223+
filename = self.get_local_path('axograph/episodic.axgd')
232224
reader = AxographIO(filename=filename, force_single_segment=True)
233225
blk = reader.read_block(signal_group_mode='split-all')
234226

@@ -251,7 +243,7 @@ def test_force_single_segment(self):
251243
def test_group_by_same_units(self):
252244
"""Test reading with group-by-same-units"""
253245

254-
filename = self.get_filename_path('episodic.axgd')
246+
filename = self.get_local_path('axograph/episodic.axgd')
255247
reader = AxographIO(filename=filename)
256248
blk = reader.read_block(signal_group_mode='group-by-same-units')
257249

@@ -274,7 +266,7 @@ def test_group_by_same_units(self):
274266
def test_events_and_epochs(self):
275267
"""Test loading events and epochs"""
276268

277-
filename = self.get_filename_path('events_and_epochs.axgx')
269+
filename = self.get_local_path('axograph/events_and_epochs.axgx')
278270
reader = AxographIO(filename=filename)
279271
blk = reader.read_block(signal_group_mode='split-all')
280272

@@ -297,14 +289,14 @@ def test_rec_datetime(self):
297289

298290
# file obtained in episodic acquisition mode has date and time on
299291
# separate lines of notes
300-
filename = self.get_filename_path('episodic.axgd')
292+
filename = self.get_local_path('axograph/episodic.axgd')
301293
reader = AxographIO(filename=filename)
302294
blk = reader.read_block(signal_group_mode='split-all')
303295
assert_equal(blk.rec_datetime, datetime(2018, 6, 7, 15, 11, 36))
304296

305297
# file obtained in continuous acquisition mode has date and time in
306298
# single line of notes
307-
filename = self.get_filename_path('events_and_epochs.axgx')
299+
filename = self.get_local_path('axograph/events_and_epochs.axgx')
308300
reader = AxographIO(filename=filename)
309301
blk = reader.read_block(signal_group_mode='split-all')
310302
assert_equal(blk.rec_datetime, datetime(2019, 5, 25, 20, 16, 25))

neo/test/iotest/test_axonaio.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717
class TestAxonaIO(BaseTestIO, unittest.TestCase, ):
1818
ioclass = AxonaIO
19-
20-
files_to_download = [
21-
'axona_raw.set',
22-
'axona_raw.bin'
19+
entities_to_download = [
20+
'axona'
2321
]
24-
files_to_test = [
25-
'axona_raw.set'
22+
entities_to_test = [
23+
'axona/axona_raw.set'
2624
]
2725

2826

neo/test/iotest/test_axonio.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@
77
from neo.io import AxonIO
88
from neo.test.iotest.common_io_test import BaseTestIO
99

10+
from neo.test.rawiotest.test_axonrawio import TestAxonRawIO
1011

1112
class TestAxonIO(BaseTestIO, unittest.TestCase):
12-
files_to_test = [
13-
'File_axon_1.abf',
14-
'File_axon_2.abf',
15-
'File_axon_3.abf',
16-
'File_axon_4.abf',
17-
'File_axon_5.abf',
18-
'File_axon_6.abf',
19-
'File_axon_7.abf',
20-
'test_file_edr3.abf',
21-
]
22-
files_to_download = files_to_test
13+
entities_to_download = TestAxonRawIO.entities_to_download
14+
entities_to_test = TestAxonRawIO.entities_to_test
2315
ioclass = AxonIO
2416

2517
def test_annotations(self):
26-
reader = AxonIO(filename=self.get_filename_path('File_axon_2.abf'))
18+
reader = AxonIO(filename=self.get_local_path('axon/File_axon_2.abf'))
2719
bl = reader.read_block()
2820
ev = bl.segments[0].events[0]
2921
assert 'comments' in ev.annotations
3022

3123
def test_read_protocol(self):
32-
for f in self.files_to_test:
33-
filename = self.get_filename_path(f)
24+
for f in self.entities_to_test:
25+
filename = self.get_local_path(f)
3426
reader = AxonIO(filename=filename)
3527
bl = reader.read_block(lazy=True)
3628
if bl.annotations['abf_version'] >= 2.:

neo/test/iotest/test_bci2000.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
class TestBCI2000IO(BaseTestIO, unittest.TestCase, ):
1212
ioclass = BCI2000IO
13-
files_to_test = [
14-
'eeg1_1.dat',
15-
'eeg1_2.dat',
16-
'eeg1_3.dat',
13+
entities_to_download = [
14+
'bci2000'
15+
]
16+
entities_to_test = [
17+
'bci2000/eeg1_1.dat',
18+
'bci2000/eeg1_2.dat',
19+
'bci2000/eeg1_3.dat',
1720
]
18-
files_to_download = files_to_test
1921

2022

2123
if __name__ == "__main__":

0 commit comments

Comments
 (0)