Skip to content

Commit beec115

Browse files
authored
Merge pull request #543 from jgrewe/warnings
fix test warnings
2 parents 444aae5 + caff10d commit beec115

22 files changed

+167
-76
lines changed

docs/source/examples/categoryData.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import nixio
44
import matplotlib.pyplot as plt
55

6+
import docutils
67

78
def create_data():
89
categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
@@ -23,7 +24,10 @@ def plot(data_array):
2324
plt.bar(range(data_array.shape[0]), data_array[:], color="tab:blue")
2425
plt.xticks(range(data_array.shape[0]), labels=data_array.dimensions[0].labels)
2526
plt.ylabel("%s %s" % (data_array.label, "[%s]" % data_array.unit if data_array.unit else ""))
26-
plt.show()
27+
if docutils.is_running_under_pytest():
28+
plt.close()
29+
else:
30+
plt.show()
2731

2832

2933
def main():

docs/source/examples/docutils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
def is_running_under_pytest():
4+
return "PYTEST_CURRENT_TEST" in os.environ

docs/source/examples/imageData.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import numpy as np
3030
from PIL import Image as img
3131

32+
import docutils
33+
3234

3335
def load_image():
3436
image = img.open('lenna.png')
@@ -42,7 +44,8 @@ def plot_data(data_array):
4244
data_array.read_direct(img_data)
4345
img_data = np.array(img_data, dtype='uint8')
4446
new_img = img.fromarray(img_data)
45-
new_img.show()
47+
if not docutils.is_running_under_pytest():
48+
new_img.show()
4649

4750

4851
if __name__ == '__main__':

docs/source/examples/imageWithMetadata.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
http://en.wikipedia.org/wiki/File:Lenna.png#mediaviewer/File:Lenna.png
2424
2525
"""
26-
27-
import nixio as nix
2826
import numpy as np
29-
from PIL import Image as img
27+
import nixio as nix
3028
import matplotlib.pyplot as plt
3129

30+
import docutils
31+
32+
from PIL import Image as img
33+
3234

3335
def print_metadata_table(section, ax):
3436
columns = ['Name', 'Value']
@@ -73,10 +75,13 @@ def plot_data(data_array):
7375
img_axis.imshow(new_img)
7476

7577
info_axis = fig.add_subplot(122)
76-
print_metadata_table(data.metadata, info_axis)
78+
print_metadata_table(data_array.metadata, info_axis)
7779
fig.subplots_adjust(left=0.075, right=0.975, bottom=0.075, top=0.975)
78-
fig.savefig('image_with_metadata.png')
79-
fig.show()
80+
if docutils.is_running_under_pytest():
81+
plt.close()
82+
else:
83+
fig.savefig('image_with_metadata.png')
84+
fig.show()
8085

8186

8287
def add_image_information(nix_file):

docs/source/examples/irregularlySampledData.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import numpy as np
1919
import matplotlib.pyplot as plt
2020

21+
import docutils
22+
2123

2224
def create_data(duration, interval):
2325
times = np.around(np.cumsum(np.random.poisson(interval * 1000, int(1.5 * duration / interval))) / 1000., 3)
@@ -37,7 +39,10 @@ def plot_data(data_array):
3739
plt.legend()
3840
plt.xlim([0, x[-1]])
3941
plt.ylim(np.min(y) * 1.1, np.max(y) * 1.1)
40-
plt.show()
42+
if docutils.is_running_under_pytest():
43+
plt.close()
44+
else:
45+
plt.show()
4146

4247

4348
def main():

docs/source/examples/multipleROIs.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from PIL import Image as img
3030
import matplotlib.pyplot as plt
3131

32+
import docutils
33+
3234

3335
def load_image():
3436
image = img.open('lenna.png')
@@ -57,8 +59,12 @@ def plot_data(tag):
5759
# new_img = img.fromarray(img_data)
5860
plt.imshow(img_data)
5961
plt.gcf().set_size_inches((5.5, 5.5))
60-
# plt.savefig("../images/multiple_rois.png")
61-
plt.show()
62+
if docutils.is_running_under_pytest():
63+
plt.close()
64+
else:
65+
# plt.savefig("../images/multiple_rois.png")
66+
plt.show()
67+
6268

6369
def plot_roi_data(tag):
6470
position_count = tag.positions.shape[0]
@@ -71,8 +77,11 @@ def plot_roi_data(tag):
7177
image = img.fromarray(roi_data)
7278
ax.imshow(image)
7379

74-
# fig.savefig('../images/retrieved_rois.png')
75-
plt.show()
80+
if docutils.is_running_under_pytest():
81+
plt.close()
82+
else:
83+
# fig.savefig('../images/retrieved_rois.png')
84+
plt.show()
7685

7786

7887
def main():

docs/source/examples/multipleTimeSeries.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import numpy as np
1919
import matplotlib.pylab as plt
2020

21+
import docutils
22+
2123

2224
def create_data(duration=1, freq=10, stepsize=0.01):
2325
x = np.arange(0, duration * 2 * np.pi, stepsize)
@@ -42,8 +44,11 @@ def plot_data(data_array):
4244
plt.xlim(0, np.max(x))
4345
plt.ylim((1.1 * np.min(y), 1.1 * np.max(y)))
4446
plt.legend()
45-
plt.savefig('multiple_time_series.png')
46-
plt.show()
47+
if docutils.is_running_under_pytest():
48+
plt.close()
49+
else:
50+
plt.savefig('multiple_time_series.png')
51+
plt.show()
4752

4853
def main():
4954
# fake some data

docs/source/examples/multiple_points.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import nixio
2+
import docutils
23
import numpy as np
34
import matplotlib.pyplot as plt
45

@@ -36,8 +37,11 @@ def plot(multi_tag):
3637
ax.spines["right"].set_visible(False)
3738
fig.subplots_adjust(bottom=0.175, left=0.15, right=0.95, top=0.95)
3839
ax.legend(loc=3, frameon=False, ncol=2)
39-
# fig.savefig("../images/multiple_points.png")
40-
plt.show()
40+
if docutils.is_running_under_pytest():
41+
plt.close()
42+
else:
43+
# fig.savefig("../images/multiple_points.png")
44+
plt.show()
4145

4246

4347
def main():

docs/source/examples/multiple_regions.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import numpy as np
21
import nixio
2+
import numpy as np
33
import matplotlib.pyplot as plt
44
import matplotlib.patches as patches
55

6+
import docutils
7+
68

79
def create_example_data(nixfile):
810
sampling_interval = 0.001
@@ -79,8 +81,11 @@ def plot(nixfile):
7981
ax.spines["top"].set_visible(False)
8082
ax.spines["right"].set_visible(False)
8183
fig.subplots_adjust(bottom=0.175, left=0.15, right=0.95, top=0.95)
82-
# fig.savefig("../images/multiple_regions.png")
83-
plt.show()
84+
if docutils.is_running_under_pytest():
85+
plt.close()
86+
else:
87+
# fig.savefig("../images/multiple_regions.png")
88+
plt.show()
8489

8590

8691
def plot_tagged_data(nixfile):
@@ -106,8 +111,11 @@ def plot_tagged_data(nixfile):
106111
else:
107112
ax.set_yticklabels([])
108113
fig.subplots_adjust(left=0.15, bottom=0.2, wspace=0.5, right=0.975)
109-
# fig.savefig("../images/reading_tagged_data.png")
110-
plt.show()
114+
if docutils.is_running_under_pytest():
115+
plt.close()
116+
else:
117+
# fig.savefig("../images/reading_tagged_data.png")
118+
plt.show()
111119

112120

113121
def main():

docs/source/examples/regularlySampledData.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import numpy as np
1919
import matplotlib.pyplot as plt
2020

21+
import docutils
22+
2123

2224
def create_sinewave(duration=1, freq=10, stepsize=0.01):
2325
x = np.arange(0, duration * 2 * np.pi, stepsize)
@@ -36,7 +38,10 @@ def plot_data(data_array):
3638
plt.xlim(0, np.max(x))
3739
plt.ylim((1.1 * np.min(y), 1.1 * np.max(y)))
3840
plt.legend()
39-
plt.show()
41+
if docutils.is_running_under_pytest():
42+
plt.close()
43+
else:
44+
plt.show()
4045

4146

4247
def main():

0 commit comments

Comments
 (0)