diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 826eb85041a7..1b98864d6a1e 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -830,7 +830,7 @@ def is_url(filename): @contextlib.contextmanager def _open_file_or_url(fname): - if is_url(fname): + if not isinstance(fname, Path) and is_url(fname): import urllib.request with urllib.request.urlopen(fname) as f: yield (line.decode('utf-8') for line in f) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 4c0ec2a6bf2c..4a47db25d887 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -28,13 +28,15 @@ _validate_linestyle) -def test_rcparams(): +def test_rcparams(tmpdir): mpl.rc('text', usetex=False) mpl.rc('lines', linewidth=22) usetex = mpl.rcParams['text.usetex'] linewidth = mpl.rcParams['lines.linewidth'] - fname = os.path.join(os.path.dirname(__file__), 'test_rcparams.rc') + + rcpath = Path(tmpdir) / 'test_rcparams.rc' + rcpath.write_text('lines.linewidth: 33') # test context given dictionary with mpl.rc_context(rc={'text.usetex': not usetex}): @@ -42,17 +44,17 @@ def test_rcparams(): assert mpl.rcParams['text.usetex'] == usetex # test context given filename (mpl.rc sets linewidth to 33) - with mpl.rc_context(fname=fname): + with mpl.rc_context(fname=rcpath): assert mpl.rcParams['lines.linewidth'] == 33 assert mpl.rcParams['lines.linewidth'] == linewidth # test context given filename and dictionary - with mpl.rc_context(fname=fname, rc={'lines.linewidth': 44}): + with mpl.rc_context(fname=rcpath, rc={'lines.linewidth': 44}): assert mpl.rcParams['lines.linewidth'] == 44 assert mpl.rcParams['lines.linewidth'] == linewidth # test rc_file - mpl.rc_file(fname) + mpl.rc_file(rcpath) assert mpl.rcParams['lines.linewidth'] == 33 @@ -177,11 +179,11 @@ def test_mec_rcparams(): assert ln.get_markeredgecolor() == 'r' -def test_Issue_1713(): - utf32_be = os.path.join(os.path.dirname(__file__), - 'test_utf32_be_rcparams.rc') +def test_Issue_1713(tmpdir): + rcpath = Path(tmpdir) / 'test_rcparams.rc' + rcpath.write_text('timezone: UTC', encoding='UTF-32-BE') with mock.patch('locale.getpreferredencoding', return_value='UTF-32-BE'): - rc = mpl.rc_params_from_file(utf32_be, True, False) + rc = mpl.rc_params_from_file(rcpath, True, False) assert rc.get('timezone') == 'UTC' diff --git a/lib/matplotlib/tests/test_rcparams.rc b/lib/matplotlib/tests/test_rcparams.rc deleted file mode 100644 index af7345aa1be1..000000000000 --- a/lib/matplotlib/tests/test_rcparams.rc +++ /dev/null @@ -1,3 +0,0 @@ -# this file is used by the tests in test_rcparams.py - -lines.linewidth: 33 diff --git a/lib/matplotlib/tests/test_utf32_be_rcparams.rc b/lib/matplotlib/tests/test_utf32_be_rcparams.rc deleted file mode 100644 index defc20eeef39..000000000000 Binary files a/lib/matplotlib/tests/test_utf32_be_rcparams.rc and /dev/null differ diff --git a/setupext.py b/setupext.py index 5e6b5411f0ce..ed61bb56a030 100644 --- a/setupext.py +++ b/setupext.py @@ -431,8 +431,6 @@ def get_package_data(self): *_pkg_data_helper('matplotlib', 'tests/tinypages'), 'tests/cmr10.pfb', 'tests/mpltest.ttf', - 'tests/test_rcparams.rc', - 'tests/test_utf32_be_rcparams.rc', ], 'mpl_toolkits': [ *_pkg_data_helper('mpl_toolkits', 'tests/baseline_images'),