@@ -81,43 +81,47 @@ def test_multipage_properfinalize():
8181
8282
8383def test_multipage_keep_empty (tmp_path ):
84- os .chdir (tmp_path )
85-
8684 # test empty pdf files
8785
8886 # an empty pdf is left behind with keep_empty unset
89- with pytest .warns (mpl .MatplotlibDeprecationWarning ), PdfPages ("a.pdf" ) as pdf :
87+ fn = tmp_path / "a.pdf"
88+ with pytest .warns (mpl .MatplotlibDeprecationWarning ), PdfPages (fn ) as pdf :
9089 pass
91- assert os . path . exists ("a.pdf" )
90+ assert fn . exists ()
9291
9392 # an empty pdf is left behind with keep_empty=True
93+ fn = tmp_path / "b.pdf"
9494 with pytest .warns (mpl .MatplotlibDeprecationWarning ), \
95- PdfPages ("b.pdf" , keep_empty = True ) as pdf :
95+ PdfPages (fn , keep_empty = True ) as pdf :
9696 pass
97- assert os . path . exists ("b.pdf" )
97+ assert fn . exists ()
9898
9999 # an empty pdf deletes itself afterwards with keep_empty=False
100- with PdfPages ("c.pdf" , keep_empty = False ) as pdf :
100+ fn = tmp_path / "c.pdf"
101+ with PdfPages (fn , keep_empty = False ) as pdf :
101102 pass
102- assert not os . path . exists ("c.pdf" )
103+ assert not fn . exists ()
103104
104105 # test pdf files with content, they should never be deleted
105106
106107 # a non-empty pdf is left behind with keep_empty unset
107- with PdfPages ("d.pdf" ) as pdf :
108+ fn = tmp_path / "d.pdf"
109+ with PdfPages (fn ) as pdf :
108110 pdf .savefig (plt .figure ())
109- assert os . path . exists ("d.pdf" )
111+ assert fn . exists ()
110112
111113 # a non-empty pdf is left behind with keep_empty=True
114+ fn = tmp_path / "e.pdf"
112115 with pytest .warns (mpl .MatplotlibDeprecationWarning ), \
113- PdfPages ("e.pdf" , keep_empty = True ) as pdf :
116+ PdfPages (fn , keep_empty = True ) as pdf :
114117 pdf .savefig (plt .figure ())
115- assert os . path . exists ("e.pdf" )
118+ assert fn . exists ()
116119
117120 # a non-empty pdf is left behind with keep_empty=False
118- with PdfPages ("f.pdf" , keep_empty = False ) as pdf :
121+ fn = tmp_path / "f.pdf"
122+ with PdfPages (fn , keep_empty = False ) as pdf :
119123 pdf .savefig (plt .figure ())
120- assert os . path . exists ("f.pdf" )
124+ assert fn . exists ()
121125
122126
123127def test_composite_image ():
0 commit comments