2121import logging
2222import unittest
2323
24- from neo .test .rawiotest .tools import (can_use_network , make_all_directories ,
25- download_test_file , create_local_temp_dir )
24+ #~ from neo.test.rawiotest.tools import (can_use_network, make_all_directories,
25+ #~ download_test_file, create_local_temp_dir)
26+ from neo .utils import download_dataset , get_local_testing_data_folder
27+
28+ from neo .test .rawiotest .tools import can_use_network
2629
2730from neo .test .rawiotest import rawio_compliance as compliance
2831
2932
3033# url_for_tests = "https://portal.g-node.org/neo/" #This is the old place
31- url_for_tests = "https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/"
32-
34+ #~ url_for_tests = "https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/"
35+ repo_for_test = 'https://gin.g-node.org/NeuralEnsemble/ephy_testing_data'
3336
3437class BaseTestRawIO :
3538 '''
@@ -44,9 +47,9 @@ class BaseTestRawIO:
4447 # all IO test need to modify this:
4548 rawioclass = None # the IOclass to be tested
4649
47- files_to_test = [] # list of files to test compliances
48- files_to_download = [] # when files are at G-Node
49-
50+ entities_to_test = [] # list of files to test compliances
51+ entities_to_download = [] # when files are at gin
52+
5053 # allow environment to tell avoid using network
5154 use_network = can_use_network ()
5255
@@ -57,60 +60,88 @@ def setUp(self):
5760 Set up the test fixture. This is run for every test
5861 '''
5962 self .shortname = self .rawioclass .__name__ .lower ().replace ('rawio' , '' )
60- self .create_local_dir_if_not_exists ()
61- self .download_test_files_if_not_present ()
62-
63- def create_local_dir_if_not_exists (self ):
64- '''
65- Create a local directory to store testing files and return it.
66-
67- The directory path is also written to self.local_test_dir
68- '''
69- self .local_test_dir = create_local_temp_dir (self .shortname )
70- return self .local_test_dir
71-
72- def download_test_files_if_not_present (self ):
73- '''
74- Download %s file at G-node for testing
75- url_for_tests is global at beginning of this file.
76-
77- ''' % self .rawioclass .__name__
78-
79- if not self .use_network :
80- raise unittest .SkipTest ("Requires download of data from the web" )
81-
82- url = url_for_tests + self .shortname
83- try :
84- make_all_directories (self .files_to_download , self .local_test_dir )
85- download_test_file (self .files_to_download ,
86- self .local_test_dir , url )
87- except OSError as exc :
88- raise unittest .SkipTest (exc )
89-
90- download_test_files_if_not_present .__test__ = False
91-
92- def cleanup_file (self , path ):
93- '''
94- Remove test files or directories safely.
95- '''
96- cleanup_test_file (self .rawioclass , path , directory = self .local_test_dir )
97-
63+
64+ for remote_path in self .entities_to_download :
65+ download_dataset (repo = repo_for_test , remote_path = remote_path )
66+
67+ #~ self.create_local_dir_if_not_exists()
68+ #~ self.download_test_files_if_not_present()
69+
70+ #~ def create_local_dir_if_not_exists(self):
71+ #~ '''
72+ #~ Create a local directory to store testing files and return it.
73+
74+ #~ The directory path is also written to self.local_test_dir
75+ #~ '''
76+ #~ self.local_test_dir = create_local_temp_dir(self.shortname)
77+ #~ return self.local_test_dir
78+
79+ #~ def download_test_files_if_not_present(self):
80+ #~ '''
81+ #~ Download %s file at G-node for testing
82+ #~ url_for_tests is global at beginning of this file.
83+
84+ #~ ''' % self.rawioclass.__name__
85+
86+ #~ if not self.use_network:
87+ #~ raise unittest.SkipTest("Requires download of data from the web")
88+
89+ #~ url = url_for_tests + self.shortname
90+ #~ try:
91+ #~ make_all_directories(self.files_to_download, self.local_test_dir)
92+ #~ download_test_file(self.files_to_download,
93+ #~ self.local_test_dir, url)
94+ #~ except OSError as exc:
95+ #~ raise unittest.SkipTest(exc)
96+
97+ #~ download_test_files_if_not_present.__test__ = False
98+
99+ #~ def cleanup_file(self, path):
100+ #~ '''
101+ #~ Remove test files or directories safely.
102+ #~ '''
103+ #~ cleanup_test_file(self.rawioclass, path, directory=self.local_test_dir)
104+
105+ #~ def get_filename_path(self, filename):
106+ #~ '''
107+ #~ Get the path to a filename in the current temporary file directory
108+ #~ '''
109+ #~ return os.path.join(self.local_test_dir, filename)
110+
111+ def get_local_base_folder (self ):
112+ return get_local_testing_data_folder ()
113+
114+ def get_local_path (self , sub_path ):
115+ root_local_path = self .get_local_base_folder ()
116+ local_path = root_local_path / sub_path
117+ # TODO later : remove the str when all IOs handle the Path stuff
118+ local_path = str (local_path )
119+ return local_path
120+
98121 def get_filename_path (self , filename ):
99- '''
100- Get the path to a filename in the current temporary file directory
101- '''
102- return os .path .join (self .local_test_dir , filename )
122+ # keep for backward compatibility
123+ # will be removed soon
124+ classname = self .__class__ .__name__
125+ classname = classname .replace ('Test' , '' ).replace ('RawIO' , '' ).lower ()
126+ root_local_path = self .get_local_base_folder ()
127+ local_path = root_local_path / classname / filename
128+ # TODO later : remove the str when all IOs handle the Path stuff
129+ local_path = str (local_path )
130+ print ('get_filename_path will be removed (use get_local_path() instead)' , self .__class__ .__name__ , local_path )
131+ return local_path
103132
104133 def test_read_all (self ):
105134 # Read all file in self.entities_to_test
106135
107136 for entity_name in self .entities_to_test :
108- entity_name = self .get_filename_path (entity_name )
137+ # entity_name = self.get_filename_path(entity_name)
138+ # local path is a folder or a file
139+ local_path = self .get_local_path (entity_name )
109140
110141 if self .rawioclass .rawmode .endswith ('-file' ):
111- reader = self .rawioclass (filename = entity_name )
142+ reader = self .rawioclass (filename = local_path )
112143 elif self .rawioclass .rawmode .endswith ('-dir' ):
113- reader = self .rawioclass (dirname = entity_name )
144+ reader = self .rawioclass (dirname = local_path )
114145
115146 txt = reader .__repr__ ()
116147 assert 'nb_block' not in txt , 'Before parser_header() nb_block should be NOT known'
0 commit comments