1
1
#!/usr/bin/env python
2
+ """
3
+ Run the Matplotlib test suite, using the mplcairo backend to patch out
4
+ Matplotlib's agg backend.
5
+
6
+ .. PYTEST_DONT_REWRITE
7
+ """
2
8
3
9
from argparse import ArgumentParser
4
10
import os
@@ -49,32 +55,24 @@ def compare_images(*args, **kwargs):
49
55
import matplotlib .pyplot as plt
50
56
plt .switch_backend ("agg" )
51
57
52
- cwd = os .getcwd ()
53
- try :
54
- matplotlib_srcdir = os .fsdecode (subprocess .check_output (
55
- ["git" , "rev-parse" , "--show-toplevel" ],
56
- cwd = Path (matplotlib .__file__ ).parent )[:- 1 ])
57
- except CalledProcessError :
58
- sys .exit ("This script must be run in an environment where Matplotlib "
59
- "is installed as an editable install." )
60
-
61
- os .chdir (matplotlib_srcdir )
62
- rv = pytest .main (["-p" , "__main__" , * rest ])
63
- os .chdir (cwd )
64
- result_images = Path (matplotlib_srcdir , "result_images" )
65
- if result_images .exists ():
66
- dest = Path (cwd , "result_images" )
67
- shutil .rmtree (str (dest ), ignore_errors = True )
68
- result_images .replace (dest )
69
- return rv
58
+ return pytest .main ([
59
+ "-p" , "__main__" ,
60
+ # Don't get confused by our *own* conftest...
61
+ "-p" , "no:{}" .format (Path (__file__ ).parent .resolve ()
62
+ / "tests/conftest.py" ),
63
+ "--pyargs" , "matplotlib" ,
64
+ * rest ])
70
65
71
66
72
67
def pytest_collection_modifyitems (session , config , items ):
68
+ if len (items ) == 0 :
69
+ pytest .exit ("No tests found; Matplotlib was likely installed without "
70
+ "test data." )
73
71
excluded_modules = {
74
72
"matplotlib.tests.test_compare_images" ,
75
73
}
76
74
excluded_nodeids = {
77
- "lib/ matplotlib/tests/" + name for name in [
75
+ "matplotlib/tests/" + name for name in [
78
76
"test_agg.py::test_repeated_save_with_alpha" ,
79
77
"test_artist.py::test_cull_markers" ,
80
78
"test_backend_pdf.py::test_composite_image" ,
@@ -97,18 +95,22 @@ def pytest_collection_modifyitems(session, config, items):
97
95
"test_simplification.py::test_throw_rendering_complexity_exceeded" ,
98
96
]
99
97
}
100
- filtered = []
98
+ selected = []
99
+ deselected = []
101
100
for item in items :
102
- if item .module .__name__ in excluded_modules :
103
- pass
104
- elif item .nodeid in excluded_nodeids :
105
- excluded_nodeids -= {item .nodeid }
101
+ if (item .module .__name__ in excluded_modules
102
+ or item .nodeid in excluded_nodeids ):
103
+ deselected .append (item )
106
104
else :
107
- filtered .append (item )
108
- if excluded_nodeids :
105
+ selected .append (item )
106
+ items [:] = selected
107
+ config .hook .pytest_deselected (items = deselected )
108
+ invalid_exclusions = (
109
+ (excluded_modules - {item .module .__name__ for item in deselected })
110
+ | (excluded_nodeids - {item .nodeid for item in deselected }))
111
+ if invalid_exclusions :
109
112
warnings .warn ("Unused exclusions:\n {}"
110
- .format ("\n " .join (sorted (excluded_nodeids ))))
111
- items [:] = filtered
113
+ .format ("\n " .join (sorted (invalid_exclusions ))))
112
114
113
115
114
116
if __name__ == "__main__" :
0 commit comments