|
2 | 2 |
|
3 | 3 | import pytest
|
4 | 4 |
|
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 |
14 | 6 | from ..testing import assert_produces_warning
|
15 | 7 |
|
16 | 8 | from .. import unpack_labeled_data
|
@@ -342,52 +334,56 @@ def funcy(ax, *args, **kwargs):
|
342 | 334 |
|
343 | 335 |
|
344 | 336 | 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'.*") |
345 | 349 | @unpack_labeled_data()
|
346 | 350 | def funcy(ax, *args, **kwargs):
|
347 | 351 | """Funcy does nothing"""
|
348 | 352 | pass
|
349 | 353 |
|
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__) |
355 | 357 |
|
356 | 358 | @unpack_labeled_data(replace_all_args=True, replace_names=[])
|
357 | 359 | def funcy(ax, x, y, z, bar=None):
|
358 | 360 | """Funcy does nothing"""
|
359 | 361 | pass
|
360 | 362 |
|
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__) |
366 | 366 |
|
367 | 367 | @unpack_labeled_data(replace_all_args=True, replace_names=["bar"])
|
368 | 368 | def funcy(ax, x, y, z, bar=None):
|
369 | 369 | """Funcy does nothing"""
|
370 | 370 | pass
|
371 | 371 |
|
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__) |
377 | 375 |
|
378 | 376 | @unpack_labeled_data(replace_names=["x", "bar"])
|
379 | 377 | def funcy(ax, x, y, z, bar=None):
|
380 | 378 | """Funcy does nothing"""
|
381 | 379 | pass
|
382 | 380 |
|
383 | 381 | # 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__) |
391 | 387 |
|
392 | 388 |
|
393 | 389 | def test_positional_parameter_names_as_function():
|
|
0 commit comments