8000 Remove unnecessary uses of unittest.mock. by anntzer · Pull Request #14379 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Remove unnecessary uses of unittest.mock. #14379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
10000 Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/matplotlib/tests/test_backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@ def CustomHandler(signum, frame):
])
def test_correct_key(backend, qt_key, qt_mods, answer):
"""
Make a figure
Send a key_press_event event (using non-public, qtX backend specific api)
Catch the event
Assert sent and caught keys are the same
Make a figure.
Send a key_press_event event (using non-public, qtX backend specific api).
Catch the event.
Assert sent and caught keys are the same.
"""
qt_canvas = plt.figure().canvas

event = mock.Mock()
event.isAutoRepeat.return_value = False
event.key.return_value = qt_key
event.modifiers.return_value = qt_mods
class _Event:
def isAutoRepeat(self): return False
def key(self): return qt_key
def modifiers(self): return qt_mods

def receive(event):
assert event.key == answer

qt_canvas.mpl_connect('key_press_event', receive)
qt_canvas.keyPressEvent(event)
qt_canvas.keyPressEvent(_Event())


@pytest.mark.backend('Qt5Agg')
Expand Down
13 changes: 7 additions & 6 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import tempfile
from unittest.mock import Mock

import dateutil.tz
import dateutil.rrule
Expand Down Expand Up @@ -245,12 +244,14 @@ def test_locator_set_formatter():


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

formatter = mdates.AutoDateFormatter(locator)
class _Locator:
def _get_unit(self): return -11

def callable_formatting_function(dates, _):
return [dt.strftime('%d-%m//%Y') for dt in dates]

formatter = mdates.AutoDateFormatter(_Locator())
formatter.scaled[-10] = callable_formatting_function
assert formatter([datetime.datetime(2014, 12, 25)]) == ['25-12//2014']

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import Mock
from types import SimpleNamespace

import matplotlib.widgets as widgets
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -54,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()
event = SimpleNamespace()
event.button = button
ax = tool.ax
event.x, event.y = ax.transData.transform([(xdata, ydata),
Expand Down
0