Skip to content

Commit 683546e

Browse files
committed
regex assertions to convert
1 parent f17a2db commit 683546e

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

lib/matplotlib/tests/test_labeled_data_unpacking.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22

33
import pytest
44

5-
try:
6-
# 3.2+ versions
7-
from nose.tools import assert_regex, assert_not_regex
8-
except ImportError:
9-
# 2.7 versions
10-
from nose.tools import assert_regexp_matches, assert_not_regexp_matches
11-
assert_regex = assert_regexp_matches
12-
assert_not_regex = assert_not_regexp_matches
13-
5+
import re
146
from ..testing import assert_produces_warning
157

168
from .. import unpack_labeled_data
@@ -342,52 +334,56 @@ def funcy(ax, *args, **kwargs):
342334

343335

344336
def test_docstring_addition():
337+
all_positional_all_keyword = \
338+
re.compile(r".*All positional and all keyword arguments\.")
339+
all_positional = \
340+
re.compile(r".*All positional arguments\.")
341+
all_arguments = \
342+
re.compile(r".*All arguments with the following names: .*")
343+
all_arguments_with_following_names = \
344+
re.compile(r".*All arguments with the following names: '.*', '.*'\.")
345+
x_string = \
346+
re.compile(r".*'x'.*")
347+
bar_string = \
348+
re.compile(r".*'bar'.*")
345349
@unpack_labeled_data()
346350
def funcy(ax, *args, **kwargs):
347351
"""Funcy does nothing"""
348352
pass
349353

350-
assert_regex(funcy.__doc__,
351-
r".*All positional and all keyword arguments\.")
352-
assert_not_regex(funcy.__doc__, r".*All positional arguments\.")
353-
assert_not_regex(funcy.__doc__,
354-
r".*All arguments with the following names: .*")
354+
assert all_positional_all_keyword.match(funcy.__doc__)
355+
assert not all_positional.match(funcy.__doc__)
356+
assert not all_arguments.match(funcy.__doc__)
355357

356358
@unpack_labeled_data(replace_all_args=True, replace_names=[])
357359
def funcy(ax, x, y, z, bar=None):
358360
"""Funcy does nothing"""
359361
pass
360362

361-
assert_regex(funcy.__doc__, r".*All positional arguments\.")
362-
assert_not_regex(funcy.__doc__,
363-
r".*All positional and all keyword arguments\.")
364-
assert_not_regex(funcy.__doc__,
365-
r".*All arguments with the following names: .*")
363+
assert all_positional.match(funcy.__doc__)
364+
assert not all_positional_all_keyword.match(funcy.__doc__)
365+
assert not all_arguments.match(funcy.__doc__)
366366

367367
@unpack_labeled_data(replace_all_args=True, replace_names=["bar"])
368368
def funcy(ax, x, y, z, bar=None):
369369
"""Funcy does nothing"""
370370
pass
371371

372-
assert_regex(funcy.__doc__, r".*All positional arguments\.")
373-
assert_regex(funcy.__doc__,
374-
r".*All arguments with the following names: 'bar'\.")
375-
assert_not_regex(funcy.__doc__,
376-
r".*All positional and all keyword arguments\.")
372+
assert all_positional.match(funcy.__doc__)
373+
assert all_arguments.match(funcy.__doc__)
374+
assert not all_positional_all_keyword.match(funcy.__doc__)
377375

378376
@unpack_labeled_data(replace_names=["x", "bar"])
379377
def funcy(ax, x, y, z, bar=None):
380378
"""Funcy does nothing"""
381379
pass
382380

383381
# lists can print in any order, so test for both x,bar and bar,x
384-
assert_regex(funcy.__doc__,
385-
r".*All arguments with the following names: '.*', '.*'\.")
386-
assert_regex(funcy.__doc__, r".*'x'.*")
387-
assert_regex(funcy.__doc__, r".*'bar'.*")
388-
assert_not_regex(funcy.__doc__,
389-
r".*All positional and all keyword arguments\.")
390-
assert_not_regex(funcy.__doc__, r".*All positional arguments\.")
382+
assert all_arguments_with_following_names.match(funcy.__doc__)
383+
assert x_string.match(funcy.__doc__)
384+
assert bar_string.match(funcy.__doc__)
385+
assert not all_positional_all_keyword.match(funcy.__doc__)
386+
assert not all_positional.match(funcy.__doc__)
391387

392388

393389
def test_positional_parameter_names_as_function():

0 commit comments

Comments
 (0)