|
3 | 3 | import io |
4 | 4 | import os |
5 | 5 | from pathlib import Path |
6 | | -import warnings |
7 | 6 |
|
8 | 7 | import numpy as np |
9 | 8 | import pytest |
@@ -85,44 +84,40 @@ def test_multipage_keep_empty(tmp_path): |
85 | 84 | os.chdir(tmp_path) |
86 | 85 |
|
87 | 86 | # test empty pdf files |
88 | | - # Due to order of `with` block execution, a warning for unclosed file is raised |
89 | | - # but the pytest.warns must happen before the PdfPages is created |
90 | | - with warnings.catch_warnings(): |
91 | | - warnings.filterwarnings("ignore", category=ResourceWarning) |
92 | | - |
93 | | - # an empty pdf is left behind with keep_empty unset |
94 | | - with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages("a.pdf") as pdf: |
95 | | - pass |
96 | | - assert os.path.exists("a.pdf") |
97 | | - |
98 | | - # an empty pdf is left behind with keep_empty=True |
99 | | - with pytest.warns(mpl.MatplotlibDeprecationWarning), \ |
100 | | - PdfPages("b.pdf", keep_empty=True) as pdf: |
101 | | - pass |
102 | | - assert os.path.exists("b.pdf") |
103 | | - |
104 | | - # an empty pdf deletes itself afterwards with keep_empty=False |
105 | | - with PdfPages("c.pdf", keep_empty=False) as pdf: |
106 | | - pass |
107 | | - assert not os.path.exists("c.pdf") |
108 | | - |
109 | | - # test pdf files with content, they should never be deleted |
110 | | - |
111 | | - # a non-empty pdf is left behind with keep_empty unset |
112 | | - with PdfPages("d.pdf") as pdf: |
113 | | - pdf.savefig(plt.figure()) |
114 | | - assert os.path.exists("d.pdf") |
115 | | - |
116 | | - # a non-empty pdf is left behind with keep_empty=True |
117 | | - with pytest.warns(mpl.MatplotlibDeprecationWarning), \ |
118 | | - PdfPages("e.pdf", keep_empty=True) as pdf: |
119 | | - pdf.savefig(plt.figure()) |
120 | | - assert os.path.exists("e.pdf") |
121 | | - |
122 | | - # a non-empty pdf is left behind with keep_empty=False |
123 | | - with PdfPages("f.pdf", keep_empty=False) as pdf: |
124 | | - pdf.savefig(plt.figure()) |
125 | | - assert os.path.exists("f.pdf") |
| 87 | + |
| 88 | + # an empty pdf is left behind with keep_empty unset |
| 89 | + with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages("a.pdf") as pdf: |
| 90 | + pass |
| 91 | + assert os.path.exists("a.pdf") |
| 92 | + |
| 93 | + # an empty pdf is left behind with keep_empty=True |
| 94 | + with pytest.warns(mpl.MatplotlibDeprecationWarning), \ |
| 95 | + PdfPages("b.pdf", keep_empty=True) as pdf: |
| 96 | + pass |
| 97 | + assert os.path.exists("b.pdf") |
| 98 | + |
| 99 | + # an empty pdf deletes itself afterwards with keep_empty=False |
| 100 | + with PdfPages("c.pdf", keep_empty=False) as pdf: |
| 101 | + pass |
| 102 | + assert not os.path.exists("c.pdf") |
| 103 | + |
| 104 | + # test pdf files with content, they should never be deleted |
| 105 | + |
| 106 | + # a non-empty pdf is left behind with keep_empty unset |
| 107 | + with PdfPages("d.pdf") as pdf: |
| 108 | + pdf.savefig(plt.figure()) |
| 109 | + assert os.path.exists("d.pdf") |
| 110 | + |
| 111 | + # a non-empty pdf is left behind with keep_empty=True |
| 112 | + with pytest.warns(mpl.MatplotlibDeprecationWarning), \ |
| 113 | + PdfPages("e.pdf", keep_empty=True) as pdf: |
| 114 | + pdf.savefig(plt.figure()) |
| 115 | + assert os.path.exists("e.pdf") |
| 116 | + |
| 117 | + # a non-empty pdf is left behind with keep_empty=False |
| 118 | + with PdfPages("f.pdf", keep_empty=False) as pdf: |
| 119 | + pdf.savefig(plt.figure()) |
| 120 | + assert os.path.exists("f.pdf") |
126 | 121 |
|
127 | 122 |
|
128 | 123 | def test_composite_image(): |
|
0 commit comments