Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3f729a1

Browse filesBrowse files
committed
TST: Remove superfluous chdir from tests
These tests don't chdir back to the original directory on exit, so anything using the current directory would be in the temporary directory of this test. Most notably, any image comparison results would be dumped in that temporary directory instead of the usual `result_images` in the current directory.
1 parent de11026 commit 3f729a1
Copy full SHA for 3f729a1

File tree

Expand file treeCollapse file tree

2 files changed

+36
-28
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+36
-28
lines changed

‎lib/matplotlib/tests/test_backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pdf.py
+18-14Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,43 +81,47 @@ def test_multipage_properfinalize():
8181

8282

8383
def 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

123127
def test_composite_image():

‎lib/matplotlib/tests/test_backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pgf.py
+18-14Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,43 +288,47 @@ def test_pdf_pages_metadata_check(monkeypatch, system):
288288

289289
@needs_pgf_xelatex
290290
def test_multipage_keep_empty(tmp_path):
291-
os.chdir(tmp_path)
292-
293291
# test empty pdf files
294292

295293
# an empty pdf is left behind with keep_empty unset
296-
with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages("a.pdf") as pdf:
294+
fn = tmp_path / "a.pdf"
295+
with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages(fn) as pdf:
297296
pass
298-
assert os.path.exists("a.pdf")
297+
assert fn.exists()
299298

300299
# an empty pdf is left behind with keep_empty=True
300+
fn = tmp_path / "b.pdf"
301301
with pytest.warns(mpl.MatplotlibDeprecationWarning), \
302-
PdfPages("b.pdf", keep_empty=True) as pdf:
302+
PdfPages(fn, keep_empty=True) as pdf:
303303
pass
304-
assert os.path.exists("b.pdf")
304+
assert fn.exists()
305305

306306
# an empty pdf deletes itself afterwards with keep_empty=False
307-
with PdfPages("c.pdf", keep_empty=False) as pdf:
307+
fn = tmp_path / "c.pdf"
308+
with PdfPages(fn, keep_empty=False) as pdf:
308309
pass
309-
assert not os.path.exists("c.pdf")
310+
assert not fn.exists()
310311

311312
# test pdf files with content, they should never be deleted
312313

313314
# a non-empty pdf is left behind with keep_empty unset
314-
with PdfPages("d.pdf") as pdf:
315+
fn = tmp_path / "d.pdf"
316+
with PdfPages(fn) as pdf:
315317
pdf.savefig(plt.figure())
316-
assert os.path.exists("d.pdf")
318+
assert fn.exists()
317319

318320
# a non-empty pdf is left behind with keep_empty=True
321+
fn = tmp_path / "e.pdf"
319322
with pytest.warns(mpl.MatplotlibDeprecationWarning), \
320-
PdfPages("e.pdf", keep_empty=True) as pdf:
323+
PdfPages(fn, keep_empty=True) as pdf:
321324
pdf.savefig(plt.figure())
322-
assert os.path.exists("e.pdf")
325+
assert fn.exists()
323326

324327
# a non-empty pdf is left behind with keep_empty=False
325-
with PdfPages("f.pdf", keep_empty=False) as pdf:
328+
fn = tmp_path / "f.pdf"
329+
with PdfPages(fn, keep_empty=False) as pdf:
326330
pdf.savefig(plt.figure())
327-
assert os.path.exists("f.pdf")
331+
assert fn.exists()
328332

329333

330334
@needs_pgf_xelatex

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.