Skip to content

Commit 87cd23e

Browse files
closing figures after testing to prevent other tests from failing
1 parent 2824066 commit 87cd23e

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

test/test_cleanfigure.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_recursive_cleanfigure():
1818
ax.set_ylim([20, 80])
1919
ax.set_xlim([20, 80])
2020
cleanfigure._recursive_cleanfigure(fig)
21+
plt.close("all")
2122

2223

2324
def test_pruneOutsideBox():
@@ -35,8 +36,6 @@ def test_pruneOutsideBox():
3536
ylim([20, 80])
3637
cleanfigure;
3738
```
38-
39-
4039
"""
4140
x = np.linspace(1, 100, 20)
4241
y = np.linspace(1, 100, 20)
@@ -48,6 +47,7 @@ def test_pruneOutsideBox():
4847
ax.set_xlim([20, 80])
4948
cleanfigure._pruneOutsideBox(fig, ax, l)
5049
assert l.get_xdata().shape == (14,)
50+
plt.close("all")
5151

5252

5353
def test_replaceDataWithNaN():
@@ -65,8 +65,6 @@ def test_replaceDataWithNaN():
6565
ylim([20, 80])
6666
cleanfigure;
6767
```
68-
69-
7068
"""
7169
id_replace = np.array([0, 16])
7270
xData = np.linspace(1, 100, 20)
@@ -82,6 +80,7 @@ def test_replaceDataWithNaN():
8280
newdata = np.stack(l.get_data(), axis=1)
8381
assert newdata.shape == data.shape
8482
assert np.any(np.isnan(newdata))
83+
plt.close("all")
8584

8685

8786
def test_removeData():
@@ -99,8 +98,6 @@ def test_removeData():
9998
ylim([20, 80])
10099
cleanfigure;
101100
```
102-
103-
104101
"""
105102
id_remove = np.array([1, 2, 3, 17, 18, 19])
106103
xData = np.linspace(1, 100, 20)
@@ -113,6 +110,7 @@ def test_removeData():
113110
cleanfigure._removeData(l, id_remove)
114111
newdata = np.stack(l.get_data(), axis=1)
115112
assert newdata.shape == (14, 2)
113+
plt.close("all")
116114

117115

118116
def test_removeNaNs():
@@ -144,6 +142,7 @@ def test_removeNaNs():
144142
newdata = np.stack(l.get_data(), axis=1)
145143
assert not np.any(np.isnan(newdata))
146144
assert newdata.shape == (12, 2)
145+
plt.close("all")
147146

148147

149148
def test_isInBox():
@@ -198,6 +197,7 @@ def test_getVisualLimits():
198197
xLim, yLim = cleanfigure._getVisualLimits(fig, ax)
199198
assert np.allclose(xLim, np.array([20, 80]))
200199
assert np.allclose(yLim, np.array([20, 80]))
200+
plt.close("all")
201201

202202

203203
def test_movePointsCloser():
@@ -230,6 +230,7 @@ def test_movePointsCloser():
230230
cleanfigure._pruneOutsideBox(fig, ax, l)
231231
cleanfigure._movePointscloser(fig, ax, l)
232232
assert l.get_xdata().shape == (14,)
233+
plt.close("all")
233234

234235

235236
def test_simplifyLine():
@@ -264,6 +265,7 @@ def test_simplifyLine():
264265
cleanfigure._simplifyLine(fig, ax, l, 600)
265266
assert l.get_xdata().shape == (2,)
266267
assert l.get_ydata().shape == (2,)
268+
plt.close("all")
267269

268270

269271
# def test_simplifyStairs():
@@ -334,6 +336,7 @@ def test_limitPrecision():
334336
cleanfigure._limitPrecision(fig, ax, l, 1)
335337
assert l.get_xdata().shape == (2,)
336338
assert l.get_ydata().shape == (2,)
339+
plt.close("all")
337340

338341

339342
def test_opheimSimplify():
@@ -400,6 +403,7 @@ def test_is_step(function, result):
400403
elif function == "step":
401404
(l,) = ax.step(x, y)
402405
assert cleanfigure._isStep(l) == result
406+
plt.close("all")
403407

404408

405409
class Test_plottypes:
@@ -428,6 +432,7 @@ def test_plot(self):
428432
numLinesRaw = raw.count("\n")
429433
numLinesClean = clean.count("\n")
430434
assert numLinesRaw - numLinesClean == 18
435+
plt.close("all")
431436

432437
def test_step(self):
433438
""" """
@@ -442,6 +447,7 @@ def test_step(self):
442447
ax.set_xlim([20, 80])
443448
with pytest.warns(Warning):
444449
cleanfigure.cleanfigure(fig)
450+
plt.close("all")
445451

446452
def test_scatter(self):
447453
""" """
@@ -456,6 +462,7 @@ def test_scatter(self):
456462
ax.set_xlim([20, 80])
457463
with pytest.warns(Warning):
458464
cleanfigure.cleanfigure(fig)
465+
plt.close("all")
459466

460467
def test_bar(self):
461468
""" """
@@ -469,6 +476,7 @@ def test_bar(self):
469476
ax.set_xlim([20, 80])
470477
with pytest.warns(Warning):
471478
cleanfigure.cleanfigure(fig)
479+
plt.close("all")
472480

473481
def test_hist(self):
474482
"""creates same test case as bar"""
@@ -482,6 +490,7 @@ def test_hist(self):
482490
ax.set_xlim([20, 80])
483491
with pytest.warns(Warning):
484492
cleanfigure.cleanfigure(fig)
493+
plt.close("all")
485494

486495
def test_plot3d(self):
487496
""" """
@@ -509,6 +518,7 @@ def test_plot3d(self):
509518
numLinesRaw = raw.count("\n")
510519
numLinesClean = clean.count("\n")
511520
assert numLinesRaw - numLinesClean == 14
521+
plt.close("all")
512522

513523
def test_scatter3d(self):
514524
""" """
@@ -525,6 +535,7 @@ def test_scatter3d(self):
525535
ax.set_zlim([0, 80])
526536
with pytest.warns(Warning):
527537
cleanfigure.cleanfigure(fig)
538+
plt.close("all")
528539

529540
def test_wireframe3D(self):
530541
""" """
@@ -541,6 +552,7 @@ def test_wireframe3D(self):
541552
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
542553
with pytest.warns(Warning):
543554
cleanfigure.cleanfigure(fig)
555+
plt.close("all")
544556

545557
def test_surface3D(self):
546558
""" """
@@ -573,6 +585,7 @@ def test_surface3D(self):
573585

574586
with pytest.warns(Warning):
575587
cleanfigure.cleanfigure(fig)
588+
plt.close("all")
576589

577590
def test_trisurface3D(self):
578591
"""
@@ -608,6 +621,7 @@ def test_trisurface3D(self):
608621
ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True)
609622
with pytest.warns(Warning):
610623
cleanfigure.cleanfigure(fig)
624+
plt.close("all")
611625

612626
def test_contour3D(self):
613627
""" """
@@ -623,6 +637,7 @@ def test_contour3D(self):
623637
ax.clabel(cset, fontsize=9, inline=1)
624638
with pytest.warns(Warning):
625639
cleanfigure.cleanfigure(fig)
640+
plt.close("all")
626641

627642
def test_polygon3D(self):
628643
""" """
@@ -663,6 +678,7 @@ def cc(arg):
663678
ax.set_zlim3d(0, 1)
664679
with pytest.warns(Warning):
665680
cleanfigure.cleanfigure(fig)
681+
plt.close("all")
666682

667683
def test_bar3D(self):
668684
""" """
@@ -687,6 +703,7 @@ def test_bar3D(self):
687703
ax.set_zlabel("Z")
688704
with pytest.warns(Warning):
689705
cleanfigure.cleanfigure(fig)
706+
plt.close("all")
690707

691708
def test_quiver3D(self):
692709
""" """
@@ -717,6 +734,7 @@ def test_quiver3D(self):
717734
ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)
718735
with pytest.warns(Warning):
719736
cleanfigure.cleanfigure(fig)
737+
plt.close("all")
720738

721739
def test_2D_in_3D(self):
722740
""" """
@@ -757,6 +775,7 @@ def test_2D_in_3D(self):
757775
ax.view_init(elev=20.0, azim=-35)
758776
with pytest.warns(Warning):
759777
cleanfigure.cleanfigure(fig)
778+
plt.close("all")
760779

761780

762781
class Test_lineplot:
@@ -789,6 +808,7 @@ def test_line_no_markers(self):
789808
numLinesRaw = raw.count("\n")
790809
numLinesClean = clean.count("\n")
791810
assert numLinesRaw - numLinesClean == 18
811+
plt.close("all")
792812

793813
def test_no_line_markers(self):
794814
"""test high-level usage for simple example.
@@ -817,6 +837,7 @@ def test_no_line_markers(self):
817837
numLinesRaw = raw.count("\n")
818838
numLinesClean = clean.count("\n")
819839
assert numLinesRaw - numLinesClean == 6
840+
plt.close("all")
820841

821842
def test_line_markers(self):
822843
"""test high-level usage for simple example.
@@ -845,6 +866,7 @@ def test_line_markers(self):
845866
numLinesRaw = raw.count("\n")
846867
numLinesClean = clean.count("\n")
847868
assert numLinesRaw - numLinesClean == 6
869+
plt.close("all")
848870

849871
def test_sine(self):
850872
""" """
@@ -869,6 +891,7 @@ def test_sine(self):
869891
numLinesRaw = raw.count("\n")
870892
numLinesClean = clean.count("\n")
871893
assert numLinesRaw - numLinesClean == 39
894+
plt.close("all")
872895

873896

874897
class Test_subplots:
@@ -924,6 +947,7 @@ def test_subplot(self):
924947
numLinesRaw = raw.count("\n")
925948
numLinesClean = clean.count("\n")
926949
assert numLinesRaw - numLinesClean == 36
950+
plt.close("all")
927951

928952

929953
def test_segmentVisible():

0 commit comments

Comments
 (0)