Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e1aedf

Browse files
committed
Don't access internet during tests.
The tests that style.use() and imread() support urls can just use local urls (`file://`); this avoids failing the tests when downloading the gist fails due to a flaky connection.
1 parent af80d57 commit 4e1aedf

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ environment:
1616
global:
1717
PYTHONIOENCODING: UTF-8
1818
PYTEST_ARGS: -raR --numprocesses=auto --timeout=300 --durations=25
19-
--cov-report= --cov=lib -m "not network" --log-level=DEBUG
19+
--cov-report= --cov=lib --log-level=DEBUG
2020

2121
matrix:
2222
# theoretically the CONDA_INSTALL_LOCN could be only two: one for 32bit,

doc/devel/testing.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ commands, such as:
5454

5555
======================== ===========
5656
``--pep8`` Perform pep8 checks (requires pytest-pep8_)
57-
``-m "not network"`` Disable tests that require network access
5857
======================== ===========
5958

6059
Additional arguments are passed on to pytest. See the pytest documentation for

lib/matplotlib/tests/test_image.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
from pathlib import Path
77
import platform
8+
import sys
89
import urllib.request
910
import warnings
1011

@@ -657,9 +658,11 @@ def test_minimized_rasterized():
657658
assert False
658659

659660

660-
@pytest.mark.network
661661
def test_load_from_url():
662-
url = "http://matplotlib.org/_static/logo_sidebar_horiz.png"
662+
path = Path(__file__).parent / "baseline_images/test_image/imshow.png"
663+
uri = ('file:'
664+
+ ('///' if sys.platform == 'win32' else '//')
665+
+ path.resolve().as_posix())
663666
plt.imread(url)
664667
plt.imread(urllib.request.urlopen(url))
665668

lib/matplotlib/tests/test_style.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gc
44
from pathlib import Path
55
from tempfile import TemporaryDirectory
6+
import sys
67

78
import pytest
89

@@ -56,10 +57,14 @@ def test_use():
5657
assert mpl.rcParams[PARAM] == VALUE
5758

5859

59-
@pytest.mark.network
60-
def test_use_url():
60+
def test_use_url(tmpdir):
61+
path = Path(tmpdir, 'file')
62+
path.write_text('axes.facecolor: adeade')
6163
with temp_style('test', DUMMY_SETTINGS):
62-
with style.context('https://gist.github.com/adrn/6590261/raw'):
64+
uri = ('file:'
65+
+ ('///' if sys.platform == 'win32' else '//')
66+
+ path.resolve().as_posix())
67+
with style.context(uri):
6368
assert mpl.rcParams['axes.facecolor'] == "#adeade"
6469

6570

pytest.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ python_files = test_*.py
66

77
markers =
88
backend: Set alternate Matplotlib backend temporarily.
9-
network: Mark a test that uses the network.
109
style: Set alternate Matplotlib style temporarily.

tests.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,10 @@
3939
from matplotlib import test
4040

4141
parser = argparse.ArgumentParser(add_help=False)
42-
parser.add_argument('--no-network', action='store_true',
43-
help='Run tests without network connection')
4442
parser.add_argument('--recursionlimit', type=int, default=0,
4543
help='Specify recursionlimit for test run')
4644
args, extra_args = parser.parse_known_args()
4745

48-
if args.no_network:
49-
from matplotlib.testing import disable_internet
50-
disable_internet.turn_off_internet()
51-
extra_args.extend(['-m', 'not network'])
52-
5346
print('Python byte-compilation optimization level:', sys.flags.optimize)
5447

5548
retcode = test(argv=extra_args, switch_backend_warn=False,

0 commit comments

Comments
 (0)