11import copy
22import os
3- from pathlib import Path
43import subprocess
54import sys
65from unittest import mock
3231 _listify_validator )
3332
3433
35- def test_rcparams (tmpdir ):
34+ def test_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 assert title .get_color () == 'r'
198197
199198
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'
202201 rcpath .write_text ('timezone: UTC' , encoding = 'utf-8' )
203202 with mock .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- def test_backend_fallback_headless (tmpdir ):
524+ def test_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 with pytest .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" and not _c_internal_utils .display_is_valid (),
542541 reason = "headless" )
543- def test_backend_fallback_headful (tmpdir ):
542+ def test_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- def test_rcparams_legend_loc_from_file (tmpdir , value ):
622+ def test_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 with mpl .rc_context (fname = rc_path ):
631630 assert mpl .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- 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 } " )
653652 with mpl .rc_context (fname = rc_path ):
654653 assert mpl .rcParams ["path.sketch" ] == (1 , 2 , 3 )
0 commit comments