Skip to content

Commit

Permalink
Mock is in stdlib in Py3.
Browse files Browse the repository at this point in the history
so don't rely on the 3rd party version.

Also replace py.test by pytest in the docs (recommended since pytest
3.0, https://docs.pytest.org/en/latest/changelog.html#id281; we require
pytest>=3.1 anyways).

Also delete tox.ini which is clearly outdated.
  • Loading branch information
anntzer committed Mar 3, 2018
1 parent 072dd2b commit 7657f82
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ install:
#
- conda create -q -n test-environment python=%PYTHON_VERSION%
msinttypes freetype=2.6 "libpng>=1.6.21,<1.7" zlib=1.2 tk=8.5
pip setuptools numpy mock pandas sphinx tornado
pip setuptools numpy pandas sphinx tornado
- activate test-environment
- echo %PYTHON_VERSION% %TARGET_ARCH%
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
Expand Down
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ env:
- secure: "dfjNqGKzQG5bu3FnDNwLG8H/C4QoieFo4PfFmZPdM2RY7WIzukwKFNT6kiDfOrpwt+2bR7FhzjOGlDECGtlGOtYPN8XuXGjhcP4a4IfakdbDfF+D3NPIpf5VlE6776k0VpvcZBTMYJKNFIMc7QPkOwjvNJ2aXyfe3hBuGlKJzQU="
- CYCLER=cycler
- DATEUTIL=python-dateutil
- MOCK=
- NOSE=
- NUMPY=numpy
- PANDAS=
Expand All @@ -71,7 +70,6 @@ matrix:
env:
- CYCLER=cycler==0.10
- DATEUTIL=python-dateutil==2.1
- MOCK=mock
- NOSE=nose
- NUMPY=numpy==1.10.0
- PANDAS='pandas<0.21.0'
Expand All @@ -87,7 +85,6 @@ matrix:
env: PRE=--pre
- os: osx
language: generic # https://github.com/travis-ci/travis-ci/issues/2312
env: MOCK=mock
only: master
cache:
# As for now travis caches only "$HOME/.cache/pip"
Expand Down Expand Up @@ -123,21 +120,18 @@ before_install:
fi
install:
# Upgrade pip and setuptools. Mock has issues with the default version of
# setuptools
- |
# Setup environment
# Setup environment.
ccache -s
git describe
# Upgrade pip and setuptools and wheel to get as clean an install as possible
# Upgrade pip and setuptools and wheel to get as clean an install as possible.
python -mpip install --upgrade pip setuptools wheel
- |
# Install dependencies from PyPI
# Install dependencies from PyPI.
python -mpip install --upgrade $PRE \
codecov \
coverage \
$CYCLER \
$MOCK \
$NOSE \
$NUMPY \
$PANDAS \
Expand Down
6 changes: 3 additions & 3 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ To run the test suite:
* extract the :file:`lib\\matplotlib\\tests` or
:file:`lib\\mpl_toolkits\\tests` directories from the source distribution;
* install test dependencies: `pytest <https://pypi.python.org/pypi/pytest>`_,
`mock <https://pypi.python.org/pypi/mock>`_, Pillow, MiKTeX, GhostScript,
ffmpeg, avconv, ImageMagick, and `Inkscape <https://inkscape.org/>`_;
* run ``py.test path\to\tests\directory``.
Pillow, MiKTeX, GhostScript, ffmpeg, avconv, ImageMagick, and `Inkscape
<https://inkscape.org/>`_;
* run ``pytest path\to\tests\directory``.


Third-party distributions of Matplotlib
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ Testing

After installation, you can launch the test suite::

py.test
pytest

Or from the Python interpreter::

import matplotlib
matplotlib.test()

Consider reading http://matplotlib.org/devel/coding_guide.html#testing for
more information. Note that the test suite requires pytest and, on Python 2.7,
mock. Please install with pip or your package manager of choice.
Consider reading http://matplotlib.org/devel/coding_guide.html#testing for more
information. Note that the test suite requires pytest. Please install with pip
or your package manager of choice.

Contact
=======
Expand Down
1 change: 0 additions & 1 deletion doc-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sphinx>=1.3,!=1.5.0,!=1.6.4
colorspacious
ipython
ipywidgets
mock
numpydoc>=0.4
pillow
sphinx-gallery>=0.1.12
2 changes: 0 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def _check_deps():
"numpydoc": 'numpydoc',
"PIL.Image": 'pillow',
"sphinx_gallery": 'sphinx_gallery'}
if sys.version_info < (3, 3):
names["mock"] = 'mock'
missing = []
for name in names:
try:
Expand Down
5 changes: 2 additions & 3 deletions doc/devel/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,17 @@ Additionally you will need to copy :file:`setup.cfg.template` to
In either case you can then run the tests to check your work
environment is set up properly::

python tests.py
pytest

.. _pytest: http://doc.pytest.org/en/latest/
.. _pep8: https://pep8.readthedocs.io/en/latest/
.. _mock: https://docs.python.org/dev/library/unittest.mock.html
.. _Ghostscript: https://www.ghostscript.com/
.. _Inkscape: https://inkscape.org>

.. note::

**Additional dependencies for testing**: pytest_ (version 3.1 or later),
mock_ (if Python 2), Ghostscript_, Inkscape_
Ghostscript_, Inkscape_

.. seealso::

Expand Down
1 change: 0 additions & 1 deletion doc/devel/documenting_mpl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ requirements that are needed to build the documentation. They are listed in
* Sphinx>=1.3, !=1.5.0, !=1.6.4
* colorspacious
* IPython
* mock
* numpydoc>=0.4
* Pillow
* sphinx-gallery>=0.1.12
Expand Down
12 changes: 5 additions & 7 deletions doc/devel/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Matplotlib's testing infrastructure depends on pytest_. The tests are in
infrastructure are in :mod:`matplotlib.testing`.

.. _pytest: http://doc.pytest.org/en/latest/
.. _mock: https://docs.python.org/3/library/unittest.mock.html
.. _Ghostscript: https://www.ghostscript.com/
.. _Inkscape: https://inkscape.org
.. _pytest-cov: https://pytest-cov.readthedocs.io/en/latest/
Expand All @@ -27,7 +26,6 @@ local FreeType build
The following software is required to run the tests:

- pytest_ (>=3.1)
- mock_, when running Python 2
- Ghostscript_ (to render PDF files)
- Inkscape_ (to render SVG files)

Expand All @@ -44,7 +42,7 @@ Running the tests

Running the tests is simple. Make sure you have pytest installed and run::

py.test
pytest

or::

Expand Down Expand Up @@ -74,22 +72,22 @@ To run a single test from the command line, you can provide a file path,
optionally followed by the function separated by two colons, e.g., (tests do
not need to be installed, but Matplotlib should be)::

py.test lib/matplotlib/tests/test_simplification.py::test_clipping
pytest lib/matplotlib/tests/test_simplification.py::test_clipping

or, if tests are installed, a dot-separated path to the module, optionally
followed by the function separated by two colons, such as::

py.test --pyargs matplotlib.tests.test_simplification::test_clipping
pytest --pyargs matplotlib.tests.test_simplification::test_clipping

If you want to run the full test suite, but want to save wall time try
running the tests in parallel::

py.test --verbose -n 5
pytest --verbose -n 5

Depending on your version of Python and pytest-xdist, you may need to set
``PYTHONHASHSEED`` to a fixed value when running in parallel::

PYTHONHASHSEED=0 py.test --verbose -n 5
PYTHONHASHSEED=0 pytest --verbose -n 5

An alternative implementation that does not look at command line arguments
and works from within Python is to run the tests from the Matplotlib library
Expand Down
6 changes: 1 addition & 5 deletions doc/sphinxext/mock_gui_toolkits.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import sys

try:
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock
from unittest.mock import MagicMock


class MyCairoCffi(MagicMock):
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,12 +1478,8 @@ def _init_tests():

try:
import pytest
try:
from unittest import mock
except ImportError:
import mock
except ImportError:
print("matplotlib.test requires pytest and mock to run.")
print("matplotlib.test requires pytest to run.")
raise


Expand Down
11 changes: 3 additions & 8 deletions lib/matplotlib/tests/test_backend_qt4.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from __future__ import absolute_import, division, print_function
import copy
from unittest.mock import Mock

from matplotlib import pyplot as plt
from matplotlib._pylab_helpers import Gcf
import matplotlib
import copy

import pytest
try:
# mock in python 3.3+
from unittest import mock
except ImportError:
import mock

with matplotlib.rc_context(rc={'backend': 'Qt4Agg'}):
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat')
Expand Down Expand Up @@ -91,7 +86,7 @@ def test_correct_key(qt_key, qt_mods, answer):
"""
qt_canvas = plt.figure().canvas

event = mock.Mock()
event = Mock()
event.isAutoRepeat.return_value = False
event.key.return_value = qt_key
event.modifiers.return_value = qt_mods
Expand Down
8 changes: 1 addition & 7 deletions lib/matplotlib/tests/test_backend_qt5.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
from __future__ import absolute_import, division, print_function

import copy
from unittest import mock

import matplotlib
from matplotlib import pyplot as plt
from matplotlib._pylab_helpers import Gcf

import pytest
try:
# mock in python 3.3+
from unittest import mock
except ImportError:
import mock

with matplotlib.rc_context(rc={'backend': 'Qt5Agg'}):
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat',
Expand Down
16 changes: 3 additions & 13 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
from __future__ import absolute_import, division, print_function

from six.moves import map


import datetime
import dateutil
import tempfile
from unittest.mock import Mock

import dateutil
import numpy as np
import pytest
import pytz

try:
# mock in python 3.3+
from unittest import mock
except ImportError:
import mock

from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
Expand Down Expand Up @@ -270,7 +260,7 @@ def test_strftime_fields(dt):

def test_date_formatter_callable():
scale = -11
locator = mock.Mock(_get_unit=mock.Mock(return_value=scale))
locator = Mock(_get_unit=Mock(return_value=scale))
callable_formatting_function = (lambda dates, _:
[dt.strftime('%d-%m//%Y') for dt in dates])

Expand Down
12 changes: 3 additions & 9 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
from __future__ import absolute_import, division, print_function

try:
# mock in python 3.3+
from unittest import mock
except ImportError:
import mock
import collections
import inspect
from unittest import mock

import numpy as np
import pytest


from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.transforms as mtransforms
import matplotlib.collections as mcollections
from matplotlib.legend_handler import HandlerTuple
import matplotlib.legend as mlegend
import inspect


# test that docstrigs are the same
Expand Down
9 changes: 2 additions & 7 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
from __future__ import absolute_import, division, print_function

import six

from collections import OrderedDict
import os
from unittest import mock
import warnings
from collections import OrderedDict

from cycler import cycler, Cycler
import pytest

try:
from unittest import mock
except ImportError:
import mock
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
Expand Down
10 changes: 3 additions & 7 deletions lib/matplotlib/tests/test_units.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import datetime
from unittest.mock import MagicMock

from matplotlib.cbook import iterable
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison
import matplotlib.units as munits
import numpy as np
import datetime

try:
# mock in python 3.3+
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock


# Basic class that wraps numpy array and has units
Expand Down
10 changes: 2 additions & 8 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
from __future__ import absolute_import, division, print_function

try:
# mock in python 3.3+
from unittest import mock
except ImportError:
import mock
from unittest.mock import Mock

import matplotlib.widgets as widgets
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -60,7 +54,7 @@ def do_event(tool, etype, button=1, xdata=0, ydata=0, key=None, step=1):
*step*
number of scroll steps (positive for 'up', negative for 'down')
"""
event = mock.Mock()
event = Mock()
event.button = button
ax = tool.ax
event.x, event.y = ax.transData.transform([(xdata, ydata),
Expand Down
2 changes: 1 addition & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# $ python tests.py -v -d
#
# The arguments are identical to the arguments accepted by py.test.
# The arguments are identical to the arguments accepted by pytest.
#
# See http://doc.pytest.org/ for a detailed description of these options.

Expand Down
Loading

0 comments on commit 7657f82

Please sign in to comment.