Debian Codegraph @

nixio/test/test_doc_examples.py

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