Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitac74b74

Browse files
authored
Merge pull request#27417 from timhoffm/tmp_path
Switch pytest fixture from tmpdir to tmp_path
2 parentsee241ad +1ccb661 commitac74b74

File tree

8 files changed

+37
-42
lines changed

8 files changed

+37
-42
lines changed

‎lib/matplotlib/tests/test_backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ def test_patheffects():
124124

125125
@needs_usetex
126126
@needs_ghostscript
127-
deftest_tilde_in_tempfilename(tmpdir):
127+
deftest_tilde_in_tempfilename(tmp_path):
128128
# Tilde ~ in the tempdir path (e.g. TMPDIR, TMP or TEMP on windows
129129
# when the username is very long and windows uses a short name) breaks
130130
# latex before https://github.com/matplotlib/matplotlib/pull/5928
131-
base_tempdir=Path(tmpdir,"short-1")
131+
base_tempdir=tmp_path/"short-1"
132132
base_tempdir.mkdir()
133133
# Change the path for new tempdirs, which is used internally by the ps
134134
# backend to write a file.

‎lib/matplotlib/tests/test_figure.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
importcopy
22
fromdatetimeimportdatetime
33
importio
4-
frompathlibimportPath
54
importpickle
65
importplatform
76
fromthreadingimportTimer
@@ -739,8 +738,8 @@ def test_add_artist(fig_test, fig_ref):
739738

740739

741740
@pytest.mark.parametrize("fmt", ["png","pdf","ps","eps","svg"])
742-
deftest_fspath(fmt,tmpdir):
743-
out=Path(tmpdir,f"test.{fmt}")
741+
deftest_fspath(fmt,tmp_path):
742+
out=tmp_path/f"test.{fmt}"
744743
plt.savefig(out)
745744
without.open("rb")asfile:
746745
# All the supported formats include the format name (case-insensitive)

‎lib/matplotlib/tests/test_font_manager.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ def test_score_weight():
4646
fontManager.score_weight(400,400))
4747

4848

49-
deftest_json_serialization(tmpdir):
49+
deftest_json_serialization(tmp_path):
5050
# Can't open a NamedTemporaryFile twice on Windows, so use a temporary
5151
# directory instead.
52-
path=Path(tmpdir,"fontlist.json")
53-
json_dump(fontManager,path)
54-
copy=json_load(path)
52+
json_dump(fontManager,tmp_path/"fontlist.json")
53+
copy=json_load(tmp_path/"fontlist.json")
5554
withwarnings.catch_warnings():
5655
warnings.filterwarnings('ignore','findfont: Font family.*not found')
5756
forpropin ({'family':'STIXGeneral'},
@@ -133,8 +132,7 @@ def test_find_noto():
133132
fig.savefig(BytesIO(),format=fmt)
134133

135134

136-
deftest_find_invalid(tmpdir):
137-
tmp_path=Path(tmpdir)
135+
deftest_find_invalid(tmp_path):
138136

139137
withpytest.raises(FileNotFoundError):
140138
get_font(tmp_path/'non-existent-font-name.ttf')

‎lib/matplotlib/tests/test_mathtext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ def test_mathtext_fallback(fallback, fontlist):
459459
mpl.font_manager.fontManager.ttflist.pop()
460460

461461

462-
deftest_math_to_image(tmpdir):
463-
mathtext.math_to_image('$x^2$',str(tmpdir.join('example.png')))
462+
deftest_math_to_image(tmp_path):
463+
mathtext.math_to_image('$x^2$',tmp_path/'example.png')
464464
mathtext.math_to_image('$x^2$',io.BytesIO())
465465
mathtext.math_to_image('$x^2$',io.BytesIO(),color='Maroon')
466466

‎lib/matplotlib/tests/test_matplotlib.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ def test_parse_to_version_info(version_str, version_tuple):
2121
reason="chmod() doesn't work as is on Windows")
2222
@pytest.mark.skipif(sys.platform!="win32"andos.geteuid()==0,
2323
reason="chmod() doesn't work as root")
24-
deftest_tmpconfigdir_warning(tmpdir):
24+
deftest_tmpconfigdir_warning(tmp_path):
2525
"""Test that a warning is emitted if a temporary configdir must be used."""
26-
mode=os.stat(tmpdir).st_mode
26+
mode=os.stat(tmp_path).st_mode
2727
try:
28-
os.chmod(tmpdir,0)
28+
os.chmod(tmp_path,0)
2929
proc=subprocess.run(
3030
[sys.executable,"-c","import matplotlib"],
31-
env={**os.environ,"MPLCONFIGDIR":str(tmpdir)},
31+
env={**os.environ,"MPLCONFIGDIR":str(tmp_path)},
3232
stderr=subprocess.PIPE,text=True,check=True)
3333
assert"set the MPLCONFIGDIR"inproc.stderr
3434
finally:
35-
os.chmod(tmpdir,mode)
35+
os.chmod(tmp_path,mode)
3636

3737

38-
deftest_importable_with_no_home(tmpdir):
38+
deftest_importable_with_no_home(tmp_path):
3939
subprocess.run(
4040
[sys.executable,"-c",
4141
"import pathlib; pathlib.Path.home = lambda *args: 1/0; "
4242
"import matplotlib.pyplot"],
43-
env={**os.environ,"MPLCONFIGDIR":str(tmpdir)},check=True)
43+
env={**os.environ,"MPLCONFIGDIR":str(tmp_path)},check=True)
4444

4545

4646
deftest_use_doc_standard_backends():

‎lib/matplotlib/tests/test_pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
frommatplotlibimportpyplotasplt
1212

1313

14-
deftest_pyplot_up_to_date(tmpdir):
14+
deftest_pyplot_up_to_date(tmp_path):
1515
pytest.importorskip("black")
1616

1717
gen_script=Path(mpl.__file__).parents[2]/"tools/boilerplate.py"
1818
ifnotgen_script.exists():
1919
pytest.skip("boilerplate.py not found")
2020
orig_contents=Path(plt.__file__).read_text()
21-
plt_file=tmpdir.join('pyplot.py')
21+
plt_file=tmp_path/'pyplot.py'
2222
plt_file.write_text(orig_contents,'utf-8')
2323

2424
subprocess_run_for_testing(

‎lib/matplotlib/tests/test_rcparams.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
importcopy
22
importos
3-
frompathlibimportPath
43
importsubprocess
54
importsys
65
fromunittestimportmock
@@ -32,14 +31,14 @@
3231
_listify_validator)
3332

3433

35-
deftest_rcparams(tmpdir):
34+
deftest_rcparams(tmp_path):
3635
mpl.rc('text',usetex=False)
3736
mpl.rc('lines',linewidth=22)
3837

3938
usetex=mpl.rcParams['text.usetex']
4039
linewidth=mpl.rcParams['lines.linewidth']
4140

42-
rcpath=Path(tmpdir)/'test_rcparams.rc'
41+
rcpath=tmp_path/'test_rcparams.rc'
4342
rcpath.write_text('lines.linewidth: 33',encoding='utf-8')
4443

4544
# test context given dictionary
@@ -197,8 +196,8 @@ def test_axes_titlecolor_rcparams():
197196
asserttitle.get_color()=='r'
198197

199198

200-
deftest_Issue_1713(tmpdir):
201-
rcpath=Path(tmpdir)/'test_rcparams.rc'
199+
deftest_Issue_1713(tmp_path):
200+
rcpath=tmp_path/'test_rcparams.rc'
202201
rcpath.write_text('timezone: UTC',encoding='utf-8')
203202
withmock.patch('locale.getpreferredencoding',return_value='UTF-32-BE'):
204203
rc=mpl.rc_params_from_file(rcpath,True,False)
@@ -522,10 +521,10 @@ def test_rcparams_reset_after_fail():
522521

523522

524523
@pytest.mark.skipif(sys.platform!="linux",reason="Linux only")
525-
deftest_backend_fallback_headless(tmpdir):
524+
deftest_backend_fallback_headless(tmp_path):
526525
env= {**os.environ,
527526
"DISPLAY":"","WAYLAND_DISPLAY":"",
528-
"MPLBACKEND":"","MPLCONFIGDIR":str(tmpdir)}
527+
"MPLBACKEND":"","MPLCONFIGDIR":str(tmp_path)}
529528
withpytest.raises(subprocess.CalledProcessError):
530529
subprocess.run(
531530
[sys.executable,"-c",
@@ -540,9 +539,9 @@ def test_backend_fallback_headless(tmpdir):
540539
@pytest.mark.skipif(
541540
sys.platform=="linux"andnot_c_internal_utils.display_is_valid(),
542541
reason="headless")
543-
deftest_backend_fallback_headful(tmpdir):
542+
deftest_backend_fallback_headful(tmp_path):
544543
pytest.importorskip("tkinter")
545-
env= {**os.environ,"MPLBACKEND":"","MPLCONFIGDIR":str(tmpdir)}
544+
env= {**os.environ,"MPLBACKEND":"","MPLCONFIGDIR":str(tmp_path)}
546545
backend=subprocess.check_output(
547546
[sys.executable,"-c",
548547
"import matplotlib as mpl; "
@@ -620,12 +619,12 @@ def test_rcparams_legend_loc(value):
620619
(0.9,.7),
621620
(-0.9,.7),
622621
])
623-
deftest_rcparams_legend_loc_from_file(tmpdir,value):
622+
deftest_rcparams_legend_loc_from_file(tmp_path,value):
624623
# rcParams['legend.loc'] should be settable from matplotlibrc.
625624
# if any of these are not allowed, an exception will be raised.
626625
# test for gh issue #22338
627-
rc_path=tmpdir.join("matplotlibrc")
628-
rc_path.write(f"legend.loc:{value}")
626+
rc_path=tmp_path/"matplotlibrc"
627+
rc_path.write_text(f"legend.loc:{value}")
629628

630629
withmpl.rc_context(fname=rc_path):
631630
assertmpl.rcParams["legend.loc"]==value
@@ -647,8 +646,8 @@ def test_validate_sketch_error(value):
647646

648647

649648
@pytest.mark.parametrize("value", ['1, 2, 3','(1,2,3)'])
650-
deftest_rcparams_path_sketch_from_file(tmpdir,value):
651-
rc_path=tmpdir.join("matplotlibrc")
652-
rc_path.write(f"path.sketch:{value}")
649+
deftest_rcparams_path_sketch_from_file(tmp_path,value):
650+
rc_path=tmp_path/"matplotlibrc"
651+
rc_path.write_text(f"path.sketch:{value}")
653652
withmpl.rc_context(fname=rc_path):
654653
assertmpl.rcParams["path.sketch"]== (1,2,3)

‎lib/matplotlib/tests/test_style.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def test_use():
5858
assertmpl.rcParams[PARAM]==VALUE
5959

6060

61-
deftest_use_url(tmpdir):
62-
path=Path(tmpdir,'file')
61+
deftest_use_url(tmp_path):
62+
path=tmp_path/'file'
6363
path.write_text('axes.facecolor: adeade',encoding='utf-8')
6464
withtemp_style('test',DUMMY_SETTINGS):
6565
url= ('file:'
@@ -69,10 +69,9 @@ def test_use_url(tmpdir):
6969
assertmpl.rcParams['axes.facecolor']=="#adeade"
7070

7171

72-
deftest_single_path(tmpdir):
72+
deftest_single_path(tmp_path):
7373
mpl.rcParams[PARAM]='gray'
74-
temp_file=f'text.{STYLE_EXTENSION}'
75-
path=Path(tmpdir,temp_file)
74+
path=tmp_path/f'text.{STYLE_EXTENSION}'
7675
path.write_text(f'{PARAM} :{VALUE}',encoding='utf-8')
7776
withstyle.context(path):
7877
assertmpl.rcParams[PARAM]==VALUE

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp