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