1
- import importlib .util as getmod
2
- import os
3
- import runpy
4
1
import sys
2
+ import runpy
5
3
import unittest
4
+ import importlib .util
5
+ import importlib .machinery
6
+ import matplotlib .pyplot as plt
6
7
7
8
from pathlib import Path
8
9
from shutil import copyfile
9
10
10
- import matplotlib .pyplot as plt
11
-
12
-
13
11
TEST_IMAGE = "lenna.png"
14
12
15
13
@@ -23,22 +21,25 @@ def run_script(self, script_name):
23
21
24
22
def handle_lif (self ):
25
23
lif_path = Path .joinpath (self .examples_path , "lif.py" )
26
- spec = getmod .spec_from_file_location ("lif" , str (lif_path ))
27
- spec .loader .load_module ("lif" )
24
+ print (lif_path )
25
+ spec = importlib .util .spec_from_file_location ("lif" , lif_path )
26
+ module = importlib .util .module_from_spec (spec )
27
+ sys .modules ["lif" ] = module
28
+ spec .loader .exec_module (module )
28
29
29
30
def handle_image (self ):
30
31
image_path = Path .joinpath (self .examples_path , TEST_IMAGE )
31
- copyfile (str (image_path ), str (Path .joinpath (Path (os . getcwd ()), TEST_IMAGE )))
32
+ copyfile (str (image_path ), str (Path .joinpath (Path (Path . cwd ()), TEST_IMAGE )))
32
33
33
34
def setUp (self ):
34
- curr_path = os . getcwd ()
35
- if os . path . basename ( curr_path ) == "nixpy" :
35
+ curr_path = Path . cwd ()
36
+ if curr_path . stem == "nixpy" :
36
37
self .examples_path = Path .joinpath (Path (curr_path ),
37
38
"docs" , "source" , "examples" )
38
- elif os . path . basename ( curr_path ) == "nixio" :
39
+ elif curr_path . stem == "nixio" :
39
40
self .examples_path = Path .joinpath (Path (curr_path ).parent ,
40
41
"docs" , "source" , "examples" )
41
- elif os . path . basename ( curr_path ) == "test" :
42
+ elif curr_path . stem == "test" :
42
43
self .examples_path = Path .joinpath (Path (curr_path ).parent .parent ,
43
44
"docs" , "source" , "examples" )
44
45
@@ -48,28 +49,28 @@ def setUp(self):
48
49
def tearDown (self ):
49
50
plt .close ("all" )
50
51
plt .ioff ()
51
- if os . path . exists (TEST_IMAGE ):
52
- os . remove ( TEST_IMAGE )
52
+ if Path . exists (Path ( " TEST_IMAGE" ) ):
53
+ Path . unlink ( Path ( TEST_IMAGE ) )
53
54
54
55
def test_annotations (self ):
55
56
self .run_script ("annotations.py" )
56
57
# cleanup
57
- os . remove ( "annotations.nix" )
58
+ Path . unlink ( Path ( "annotations.nix" ) )
58
59
59
60
def test_category_data (self ):
60
61
self .run_script ("categoryData.py" )
61
62
# cleanup
62
- os . remove ( "categoryData.nix" )
63
+ Path . unlink ( Path ( "categoryData.nix" ) )
63
64
64
65
def test_continuous_recording (self ):
65
66
self .run_script ("continuousRecording.py" )
66
67
# cleanup
67
- os . remove ( "continuous_recording.nix" )
68
+ Path . unlink ( Path ( "continuous_recording.nix" ) )
68
69
69
70
def test_file_create (self ):
70
71
self .run_script ("fileCreate.py" )
71
72
# cleanup
72
- os . remove ( "file_create_example.nix" )
73
+ Path . unlink ( Path ( "file_create_example.nix" ) )
73
74
74
75
def test_image_data (self ):
75
76
# test will open image with an external program; does not work on windows
@@ -78,50 +79,50 @@ def test_image_data(self):
78
79
self .handle_image ()
79
80
self .run_script ("imageData.py" )
80
81
# cleanup
81
- os . remove ( "image_example.nix" )
82
+ Path . unlink ( Path ( "image_example.nix" ) )
82
83
83
84
def test_image_with_metadata (self ):
84
85
# Requires PIL package and the "Lenna" image.
85
86
self .handle_image ()
86
87
self .run_script ("imageWithMetadata.py" )
87
88
# cleanup
88
- os . remove ( "image_with_source_example.h5" )
89
- os . remove ( "image_with_metadata.png" )
89
+ Path . unlink ( Path ( "image_with_source_example.h5" ) )
90
+ Path . unlink ( Path ( "image_with_metadata.png" ) )
90
91
91
92
def test_irregularly_sampled_data (self ):
92
93
self .run_script ("irregularlySampledData.py" )
93
94
# cleanup
94
- os . remove ( "irregular_data_example.nix" )
95
+ Path . unlink ( Path ( "irregular_data_example.nix" ) )
95
96
96
97
def test_lif (self ):
97
98
self .run_script ("lif.py" )
98
99
99
100
def test_multiple_points (self ):
100
101
self .run_script ("multiple_points.py" )
101
102
# cleanup
102
- os . remove ( "multiple_points.nix" )
103
+ Path . unlink ( Path ( "multiple_points.nix" ) )
103
104
104
105
def test_multiple_regions (self ):
105
106
self .run_script ("multiple_regions.py" )
106
107
# cleanup
107
- os . remove ( "multiple_regions.nix" )
108
+ Path . unlink ( Path ( "multiple_regions.nix" ) )
108
109
109
110
def test_multiple_rois (self ):
110
111
# Requires PIL package and the "Lenna" image.
111
112
self .handle_image ()
112
113
self .run_script ("multipleROIs.py" )
113
114
# cleanup
114
- os . remove ( "multiple_roi.nix" )
115
+ Path . unlink ( Path ( "multiple_roi.nix" ) )
115
116
116
117
def test_range_dimension_link (self ):
117
118
self .run_script ("rangeDimensionLink.py" )
118
119
# cleanup
119
- os . remove ( "range_link.nix" )
120
+ Path . unlink ( Path ( "range_link.nix" ) )
120
121
121
122
def test_regularly_sampled_data (self ):
122
123
self .run_script ("regularlySampledData.py" )
123
124
# cleanup
124
- os . remove ( "regular_data_example.nix" )
125
+ Path . unlink ( Path ( "regular_data_example.nix" ) )
125
126
126
127
def test_single_roi (self ):
127
128
# test will open image with an external program; does not work on windows
@@ -130,44 +131,44 @@ def test_single_roi(self):
130
131
self .handle_image ()
131
132
self .run_script ("singleROI.py" )
132
133
# cleanup
133
- os . remove ( "single_roi.nix" )
134
+ Path . unlink ( Path ( "single_roi.nix" ) )
134
135
135
136
def test_sources (self ):
136
137
self .run_script ("sources.py" )
137
138
# cleanup
138
- os . remove ( "sources.nix" )
139
+ Path . unlink ( Path ( "sources.nix" ) )
139
140
140
141
def test_spike_features (self ):
141
142
# Requires scipy package and "lif.py"
142
143
self .handle_lif ()
143
144
self .run_script ("spikeFeatures.py" )
144
145
# cleanup
145
- os . remove ( "spike_features.h5" )
146
+ Path . unlink ( Path ( "spike_features.h5" ) )
146
147
147
148
def test_spike_tagging (self ):
148
149
# Requires "lif.py"
149
150
self .handle_lif ()
150
151
self .run_script ("spikeTagging.py" )
151
152
# cleanup
152
- os . remove ( "spike_tagging.nix" )
153
+ Path . unlink ( Path ( "spike_tagging.nix" ) )
153
154
154
155
def test_tabular_data (self ):
155
156
self .run_script ("tabulardata.py" )
156
157
# cleanup
157
- os . remove ( "dataframe.nix" )
158
+ Path . unlink ( Path ( "dataframe.nix" ) )
158
159
159
160
def test_tagged_feature (self ):
160
161
# Requires scipy package and "lif.py"
161
162
self .handle_lif ()
162
163
self .run_script ("taggedFeature.py" )
163
164
# cleanup
164
- os . remove ( "spike_features.nix" )
165
+ Path . unlink ( Path ( "spike_features.nix" ) )
165
166
166
167
def test_tagging_example (self ):
167
168
# Requires scipy package
168
169
self .run_script ("tagging_example.py" )
169
170
# cleanup
170
- os . remove ( "tagging1.nix" )
171
+ Path . unlink ( Path ( "tagging1.nix" ) )
171
172
172
173
def test_tagging_nd (self ):
173
174
# not testing any nix feature
@@ -179,4 +180,4 @@ def test_untagged_feature(self):
179
180
self .handle_lif ()
180
181
self .run_script ("untaggedFeature.py" )
181
182
# cleanup
182
- os . remove ( "untagged_feature.h5" )
183
+ Path . unlink ( Path ( "untagged_feature.h5" ) )
0 commit comments