diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index ae17c7a4a4e3..ad565ea9e81b 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -81,43 +81,47 @@ def test_multipage_properfinalize(): def test_multipage_keep_empty(tmp_path): - os.chdir(tmp_path) - # test empty pdf files # an empty pdf is left behind with keep_empty unset - with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages("a.pdf") as pdf: + fn = tmp_path / "a.pdf" + with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages(fn) as pdf: pass - assert os.path.exists("a.pdf") + assert fn.exists() # an empty pdf is left behind with keep_empty=True + fn = tmp_path / "b.pdf" with pytest.warns(mpl.MatplotlibDeprecationWarning), \ - PdfPages("b.pdf", keep_empty=True) as pdf: + PdfPages(fn, keep_empty=True) as pdf: pass - assert os.path.exists("b.pdf") + assert fn.exists() # an empty pdf deletes itself afterwards with keep_empty=False - with PdfPages("c.pdf", keep_empty=False) as pdf: + fn = tmp_path / "c.pdf" + with PdfPages(fn, keep_empty=False) as pdf: pass - assert not os.path.exists("c.pdf") + assert not fn.exists() # test pdf files with content, they should never be deleted # a non-empty pdf is left behind with keep_empty unset - with PdfPages("d.pdf") as pdf: + fn = tmp_path / "d.pdf" + with PdfPages(fn) as pdf: pdf.savefig(plt.figure()) - assert os.path.exists("d.pdf") + assert fn.exists() # a non-empty pdf is left behind with keep_empty=True + fn = tmp_path / "e.pdf" with pytest.warns(mpl.MatplotlibDeprecationWarning), \ - PdfPages("e.pdf", keep_empty=True) as pdf: + PdfPages(fn, keep_empty=True) as pdf: pdf.savefig(plt.figure()) - assert os.path.exists("e.pdf") + assert fn.exists() # a non-empty pdf is left behind with keep_empty=False - with PdfPages("f.pdf", keep_empty=False) as pdf: + fn = tmp_path / "f.pdf" + with PdfPages(fn, keep_empty=False) as pdf: pdf.savefig(plt.figure()) - assert os.path.exists("f.pdf") + assert fn.exists() def test_composite_image(): diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index a866916c58c6..8a83515f161c 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -288,43 +288,47 @@ def test_pdf_pages_metadata_check(monkeypatch, system): @needs_pgf_xelatex def test_multipage_keep_empty(tmp_path): - os.chdir(tmp_path) - # test empty pdf files # an empty pdf is left behind with keep_empty unset - with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages("a.pdf") as pdf: + fn = tmp_path / "a.pdf" + with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages(fn) as pdf: pass - assert os.path.exists("a.pdf") + assert fn.exists() # an empty pdf is left behind with keep_empty=True + fn = tmp_path / "b.pdf" with pytest.warns(mpl.MatplotlibDeprecationWarning), \ - PdfPages("b.pdf", keep_empty=True) as pdf: + PdfPages(fn, keep_empty=True) as pdf: pass - assert os.path.exists("b.pdf") + assert fn.exists() # an empty pdf deletes itself afterwards with keep_empty=False - with PdfPages("c.pdf", keep_empty=False) as pdf: + fn = tmp_path / "c.pdf" + with PdfPages(fn, keep_empty=False) as pdf: pass - assert not os.path.exists("c.pdf") + assert not fn.exists() # test pdf files with content, they should never be deleted # a non-empty pdf is left behind with keep_empty unset - with PdfPages("d.pdf") as pdf: + fn = tmp_path / "d.pdf" + with PdfPages(fn) as pdf: pdf.savefig(plt.figure()) - assert os.path.exists("d.pdf") + assert fn.exists() # a non-empty pdf is left behind with keep_empty=True + fn = tmp_path / "e.pdf" with pytest.warns(mpl.MatplotlibDeprecationWarning), \ - PdfPages("e.pdf", keep_empty=True) as pdf: + PdfPages(fn, keep_empty=True) as pdf: pdf.savefig(plt.figure()) - assert os.path.exists("e.pdf") + assert fn.exists() # a non-empty pdf is left behind with keep_empty=False - with PdfPages("f.pdf", keep_empty=False) as pdf: + fn = tmp_path / "f.pdf" + with PdfPages(fn, keep_empty=False) as pdf: pdf.savefig(plt.figure()) - assert os.path.exists("f.pdf") + assert fn.exists() @needs_pgf_xelatex
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: