1
1
import copy
2
2
import os
3
- from pathlib import Path
4
3
import subprocess
5
4
import sys
6
5
from unittest import mock
32
31
_listify_validator )
33
32
34
33
35
- def test_rcparams (tmpdir ):
34
+ def test_rcparams (tmp_path ):
36
35
mpl .rc ('text' , usetex = False )
37
36
mpl .rc ('lines' , linewidth = 22 )
38
37
39
38
usetex = mpl .rcParams ['text.usetex' ]
40
39
linewidth = mpl .rcParams ['lines.linewidth' ]
41
40
42
- rcpath = Path ( tmpdir ) / 'test_rcparams.rc'
41
+ rcpath = tmp_path / 'test_rcparams.rc'
43
42
rcpath .write_text ('lines.linewidth: 33' , encoding = 'utf-8' )
44
43
45
44
# test context given dictionary
@@ -197,8 +196,8 @@ def test_axes_titlecolor_rcparams():
197
196
assert title .get_color () == 'r'
198
197
199
198
200
- def test_Issue_1713 (tmpdir ):
201
- rcpath = Path ( tmpdir ) / 'test_rcparams.rc'
199
+ def test_Issue_1713 (tmp_path ):
200
+ rcpath = tmp_path / 'test_rcparams.rc'
202
201
rcpath .write_text ('timezone: UTC' , encoding = 'utf-8' )
203
202
with mock .patch ('locale.getpreferredencoding' , return_value = 'UTF-32-BE' ):
204
203
rc = mpl .rc_params_from_file (rcpath , True , False )
@@ -522,10 +521,10 @@ def test_rcparams_reset_after_fail():
522
521
523
522
524
523
@pytest .mark .skipif (sys .platform != "linux" , reason = "Linux only" )
525
- def test_backend_fallback_headless (tmpdir ):
524
+ def test_backend_fallback_headless (tmp_path ):
526
525
env = {** os .environ ,
527
526
"DISPLAY" : "" , "WAYLAND_DISPLAY" : "" ,
528
- "MPLBACKEND" : "" , "MPLCONFIGDIR" : str (tmpdir )}
527
+ "MPLBACKEND" : "" , "MPLCONFIGDIR" : str (tmp_path )}
529
528
with pytest .raises (subprocess .CalledProcessError ):
530
529
subprocess .run (
531
530
[sys .executable , "-c" ,
@@ -540,9 +539,9 @@ def test_backend_fallback_headless(tmpdir):
540
539
@pytest .mark .skipif (
541
540
sys .platform == "linux" and not _c_internal_utils .display_is_valid (),
542
541
reason = "headless" )
543
- def test_backend_fallback_headful (tmpdir ):
542
+ def test_backend_fallback_headful (tmp_path ):
544
543
pytest .importorskip ("tkinter" )
545
- env = {** os .environ , "MPLBACKEND" : "" , "MPLCONFIGDIR" : str (tmpdir )}
544
+ env = {** os .environ , "MPLBACKEND" : "" , "MPLCONFIGDIR" : str (tmp_path )}
546
545
backend = subprocess .check_output (
547
546
[sys .executable , "-c" ,
548
547
"import matplotlib as mpl; "
@@ -620,12 +619,12 @@ def test_rcparams_legend_loc(value):
620
619
(0.9 , .7 ),
621
620
(- 0.9 , .7 ),
622
621
])
623
- def test_rcparams_legend_loc_from_file (tmpdir , value ):
622
+ def test_rcparams_legend_loc_from_file (tmp_path , value ):
624
623
# rcParams['legend.loc'] should be settable from matplotlibrc.
625
624
# if any of these are not allowed, an exception will be raised.
626
625
# 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 } " )
629
628
630
629
with mpl .rc_context (fname = rc_path ):
631
630
assert mpl .rcParams ["legend.loc" ] == value
@@ -647,8 +646,8 @@ def test_validate_sketch_error(value):
647
646
648
647
649
648
@pytest .mark .parametrize ("value" , ['1, 2, 3' , '(1,2,3)' ])
650
- def test_rcparams_path_sketch_from_file (tmpdir , value ):
651
- rc_path = tmpdir . join ( "matplotlibrc" )
652
- rc_path .write (f"path.sketch: { value } " )
649
+ def test_rcparams_path_sketch_from_file (tmp_path , value ):
650
+ rc_path = tmp_path / "matplotlibrc"
651
+ rc_path .write_text (f"path.sketch: { value } " )
653
652
with mpl .rc_context (fname = rc_path ):
654
653
assert mpl .rcParams ["path.sketch" ] == (1 , 2 , 3 )
0 commit comments