From 4a1d10eb1a2b37e655a8d23d790733aeb1011362 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 29 May 2019 16:40:15 +0200 Subject: [PATCH] Move test_rcparams test files inline into test_rcparams.py. (and, as a side effect, make the various rc-related functions support Path inputs.) --- lib/matplotlib/__init__.py | 2 +- lib/matplotlib/tests/test_rcparams.py | 20 ++++++++++-------- lib/matplotlib/tests/test_rcparams.rc | 3 --- .../tests/test_utf32_be_rcparams.rc | Bin 56 -> 0 bytes setupext.py | 2 -- 5 files changed, 12 insertions(+), 15 deletions(-) delete mode 100644 lib/matplotlib/tests/test_rcparams.rc delete mode 100644 lib/matplotlib/tests/test_utf32_be_rcparams.rc 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 defc20eeef3917e381d8d1290eea81f4a11f39cd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 56 rcmZQzU?^c=V8{gGTp&&b;wm7{2jV;^-wH@80C6Y~hXAoN5OV