forked from matplotlib/matplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_buildbot_test_postmortem.py
134 lines (114 loc) · 4.64 KB
/
_buildbot_test_postmortem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""For all failed image comparisons, gather the baseline image, the
current image and the absdiff image into a single directory specified
by target_dir.
This is meant to be run from the mplroot directory."""
from __future__ import print_function
import os, shutil
roots = ['test_matplotlib','test_plots']
savedresults_dir = 'saved-results'
baseline_dir = 'baseline'
expected_basename = 'expected-'
diff_basename = 'failed-diff-'
target_dir = os.path.abspath('status_images')
nbase = len(diff_basename)
def listFiles(root, patterns='*', recurse=1, return_folders=0):
"""
Recursively list files
from Parmar and Martelli in the Python Cookbook
"""
import os.path, fnmatch
# Expand patterns from semicolon-separated string to list
pattern_list = patterns.split(';')
# Collect input and output arguments into one bunch
class Bunch:
def __init__(self, **kwds): self.__dict__.update(kwds)
arg = Bunch(recurse=recurse, pattern_list=pattern_list,
return_folders=return_folders, results=[])
def visit(arg, dirname, files):
# Append to arg.results all relevant files (and perhaps folders)
for name in files:
fullname = os.path.normpath(os.path.join(dirname, name))
if arg.return_folders or os.path.isfile(fullname):
for pattern in arg.pattern_list:
if fnmatch.fnmatch(name, pattern):
arg.results.append(fullname)
break
# Block recursion if recursion was disallowed
if not arg.recurse: files[:]=[]
os.path.walk(root, visit, arg)
return arg.results
def get_recursive_filelist(args):
"""
Recurse all the files and dirs in *args* ignoring symbolic links
and return the files as a list of strings
"""
files = []
for arg in args:
if os.path.isfile(arg):
files.append(arg)
continue
if os.path.isdir(arg):
newfiles = listFiles(arg, recurse=1, return_folders=1)
files.extend(newfiles)
return [f for f in files if not os.path.islink(f)]
def path_split_all(fname):
"""split a file path into a list of directories and filename"""
pieces = [fname]
previous_tails = []
while 1:
head,tail = os.path.split(pieces[0])
if head=='':
return pieces + previous_tails
pieces = [head]
previous_tails.insert(0,tail)
if 1:
if os.path.exists(target_dir):
shutil.rmtree(target_dir)
os.makedirs( target_dir ) # prevent buildbot DirectoryUpload failure
# new matplotlib.testing infrastructure
for fname in get_recursive_filelist(['result_images']):
# only images
if not fname.endswith('.png'): continue
result_dir, result_fname = os.path.split(fname)
absdiff_fname = os.path.join( result_dir, diff_basename + result_fname)
expected_fname = os.path.join( result_dir, expected_basename + result_fname)
if not os.path.exists(absdiff_fname):
continue
if not os.path.exists(expected_fname):
continue
print(fname)
print(absdiff_fname)
teststr = os.path.splitext(fname)[0]
this_targetdir = os.path.join(target_dir,teststr)
os.makedirs( this_targetdir )
shutil.copy( expected_fname,
os.path.join(this_targetdir,'baseline.png') )
shutil.copy( fname,
os.path.join(this_targetdir,'actual.png') )
shutil.copy( absdiff_fname,
os.path.join(this_targetdir,'absdiff.png') )
# old mplTest infrastructure
for fpath in get_recursive_filelist(roots):
# only images
if not fpath.endswith('.png'): continue
pieces = path_split_all( fpath )
if pieces[1]!=savedresults_dir:
continue
root = pieces[0]
testclass = pieces[2]
fname = pieces[3]
if not fname.startswith(diff_basename):
# only failed images
continue
origname = fname[nbase:]
testname = os.path.splitext(origname)[0]
# make a name for the test
teststr = '%s.%s.%s'%(root,testclass,testname)
this_targetdir = os.path.join(target_dir,teststr)
os.makedirs( this_targetdir )
shutil.copy( os.path.join(root,baseline_dir,testclass,origname),
os.path.join(this_targetdir,'baseline.png') )
shutil.copy( os.path.join(root,savedresults_dir,testclass,origname),
os.path.join(this_targetdir,'actual.png') )
shutil.copy( os.path.join(root,savedresults_dir,testclass,fname),
os.path.join(this_targetdir,'absdiff.png') )