Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67ed3c8

Browse files
committed
Use pytest in matplotlib.test().
1 parenteef58c5 commit67ed3c8

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

‎lib/matplotlib/__init__.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,9 +1474,10 @@ def _jupyter_nbextension_paths():
14741474

14751475

14761476
default_test_modules= [
1477-
'matplotlib.tests.test_png',
1478-
'matplotlib.tests.test_units',
1479-
]
1477+
'matplotlib.tests',
1478+
'matplotlib.sphinxext.tests',
1479+
'mpl_toolkits.tests',
1480+
]
14801481

14811482

14821483
def_init_tests():
@@ -1510,19 +1511,51 @@ def _init_tests():
15101511
)
15111512
)
15121513

1513-
from .testing._noseimportcheck_deps
1514-
check_deps()
1514+
try:
1515+
importpytest
1516+
try:
1517+
fromunittestimportmock
1518+
exceptImportError:
1519+
importmock
1520+
exceptImportError:
1521+
print("matplotlib.test requires pytest and mock to run.")
1522+
raise
15151523

15161524

1517-
deftest(verbosity=1,coverage=False,**kwargs):
1525+
deftest(verbosity=None,coverage=False,switch_backend_warn=True,
1526+
recursionlimit=0,**kwargs):
15181527
"""run the matplotlib test suite"""
15191528
_init_tests()
15201529

1521-
from .testing._noseimporttestasnose_test
1522-
returnnose_test(verbosity,coverage,**kwargs)
1530+
old_backend=get_backend()
1531+
old_recursionlimit=sys.getrecursionlimit()
1532+
try:
1533+
use('agg')
1534+
ifrecursionlimit:
1535+
sys.setrecursionlimit(recursionlimit)
1536+
importpytest
1537+
1538+
args= ['--pyargs']+default_test_modules
1539+
1540+
ifcoverage:
1541+
args+= ['--cov']
1542+
1543+
ifverbosity:
1544+
args+= ['-'+'v'*verbosity]
1545+
1546+
args+=kwargs.pop('argv', [])
1547+
1548+
retcode=pytest.main(args,**kwargs)
1549+
finally:
1550+
ifold_backend.lower()!='agg':
1551+
use(old_backend,warn=switch_backend_warn)
1552+
ifrecursionlimit:
1553+
sys.setrecursionlimit(old_recursionlimit)
1554+
1555+
returnretcode
15231556

15241557

1525-
test.__test__=False#nose: this function is not a test
1558+
test.__test__=False#pytest: this function is not a test
15261559

15271560

15281561
def_replacer(data,key):

‎tests.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#
55
# $ python tests.py -v -d
66
#
7-
# The arguments are identical to the arguments accepted bynosetests.
7+
# The arguments are identical to the arguments accepted bypy.test.
88
#
9-
# See https://nose.readthedocs.org/ for a detailed description of
10-
# these options.
9+
# See http://doc.pytest.org/ for a detailed description of these options.
1110

1211
importsys
1312
importargparse
@@ -17,10 +16,6 @@
1716
frommatplotlibimporttest
1817

1918
parser=argparse.ArgumentParser(add_help=False)
20-
parser.add_argument('--no-pep8',action='store_true',
21-
help='Run all tests except PEP8 testing')
22-
parser.add_argument('--pep8',action='store_true',
23-
help='Run only PEP8 testing')
2419
parser.add_argument('--no-network',action='store_true',
2520
help='Run tests without network connection')
2621
parser.add_argument('-j',type=int,
@@ -32,15 +27,14 @@
3227
ifargs.no_network:
3328
frommatplotlib.testingimportdisable_internet
3429
disable_internet.turn_off_internet()
35-
extra_args.extend(['-a','!network'])
30+
extra_args.extend(['-m','notnetwork'])
3631
ifargs.j:
3732
extra_args.extend([
38-
'--processes={}'.format(args.j),
39-
'--process-timeout=300'
33+
'-n',str(args.j),
4034
])
4135

4236
print('Python byte-compilation optimization level: %d'%sys.flags.optimize)
4337

44-
success=test(argv=sys.argv[0:1]+extra_args,switch_backend_warn=False,
38+
retcode=test(argv=extra_args,switch_backend_warn=False,
4539
recursionlimit=args.recursionlimit)
46-
sys.exit(notsuccess)
40+
sys.exit(retcode)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp