Skip to content

Commit acbe728

Browse files
committed
Use same disallow list for making images, checking diffs
1 parent 68b1d48 commit acbe728

File tree

3 files changed

+78
-72
lines changed

3 files changed

+78
-72
lines changed

test/image/compare_pixels_test.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const getImagePaths = require('./assets/get_image_paths');
44
const getMockList = require('./assets/get_mock_list');
55
const fs = require('fs');
66
const minimist = require('minimist');
7+
const path = require('path');
78
const pixelmatch = require('pixelmatch');
89
const { PNG } = require('pngjs');
910

@@ -59,14 +60,8 @@ argv._.forEach((pattern) => {
5960

6061
const skipped = new Set();
6162
const failed = new Set();
62-
const disallowList = new Set([
63-
'map_angles',
64-
'map_stamen-style',
65-
'map_predefined-styles2',
66-
'map_scattercluster',
67-
'map_fonts-supported-open-sans',
68-
'map_fonts-supported-open-sans-weight'
69-
]);
63+
const disallowListPath = path.join(__dirname, 'disallow_list.json');
64+
const disallowList = new Set(JSON.parse(fs.readFileSync(disallowListPath)));
7065
const flakyList = new Set(['gl3d_bunny-hull']);
7166
const flakyListMaps = new Set([
7267
// more flaky

test/image/disallow_list.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
"map_angles",
3+
"map_fonts-supported-open-sans-weight",
4+
"map_fonts-supported-open-sans",
5+
"map_predefined-styles2",
6+
"map_scattercluster",
7+
"map_stamen-style"
8+
]

test/image/make_baseline.py

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,129 +5,132 @@
55
from convert_b64 import arraysToB64
66

77
args = []
8-
if len(sys.argv) == 2 :
8+
if len(sys.argv) == 2:
99
args = sys.argv[1].split()
10-
elif len(sys.argv) > 1 :
10+
elif len(sys.argv) > 1:
1111
args = sys.argv
1212

1313
root = os.getcwd()
1414

15-
virtual_webgl = os.path.join(root, 'node_modules', 'virtual-webgl', 'src', 'virtual-webgl.js')
16-
plotlyjs = os.path.join(root, 'build', 'plotly.js')
17-
plotlyjs_with_virtual_webgl = os.path.join(root, 'build', 'plotly_with_virtual-webgl.js')
15+
virtual_webgl = os.path.join(
16+
root, "node_modules", "virtual-webgl", "src", "virtual-webgl.js"
17+
)
18+
plotlyjs = os.path.join(root, "build", "plotly.js")
19+
plotlyjs_with_virtual_webgl = os.path.join(
20+
root, "build", "plotly_with_virtual-webgl.js"
21+
)
1822

19-
dirIn = os.path.join(root, 'test', 'image', 'mocks')
20-
dirOut = os.path.join(root, 'build', 'test_images')
23+
dirIn = os.path.join(root, "test", "image", "mocks")
24+
dirOut = os.path.join(root, "build", "test_images")
2125

2226
# N.B. equal is the falg to write to baselines not test_images
2327

24-
if '=' in args :
25-
args = args[args.index('=') + 1:]
26-
dirOut = os.path.join(root, 'test', 'image', 'baselines')
28+
if "=" in args:
29+
args = args[args.index("=") + 1 :]
30+
dirOut = os.path.join(root, "test", "image", "baselines")
2731

28-
if 'mathjax3=' in sys.argv :
29-
dirOut = os.path.join(root, 'test', 'image', 'baselines')
32+
if "mathjax3=" in sys.argv:
33+
dirOut = os.path.join(root, "test", "image", "baselines")
3034

31-
print('output to', dirOut)
35+
print("output to", dirOut)
3236

3337
mathjax_version = 2
34-
if 'mathjax3' in sys.argv or 'mathjax3=' in sys.argv :
38+
if "mathjax3" in sys.argv or "mathjax3=" in sys.argv:
3539
# until https://github.com/plotly/Kaleido/issues/124 is addressed
3640
# we are uanble to use local mathjax v3 installed in node_modules
3741
# for now let's download it from the internet:
38-
pio.kaleido.scope.mathjax = 'https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-svg.js'
42+
pio.kaleido.scope.mathjax = (
43+
"https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-svg.js"
44+
)
3945
mathjax_version = 3
40-
print('Kaleido using MathJax v3')
46+
print("Kaleido using MathJax v3")
4147

42-
virtual_webgl_version = 0 # i.e. virtual-webgl is not used
43-
if 'virtual-webgl' in sys.argv or 'virtual-webgl=' in sys.argv :
48+
virtual_webgl_version = 0 # i.e. virtual-webgl is not used
49+
if "virtual-webgl" in sys.argv or "virtual-webgl=" in sys.argv:
4450
virtual_webgl_version = 1
45-
print('using virtual-webgl for WebGL v1')
51+
print("using virtual-webgl for WebGL v1")
4652

47-
with open(plotlyjs_with_virtual_webgl, 'w') as fileOut:
53+
with open(plotlyjs_with_virtual_webgl, "w") as fileOut:
4854
for filename in [virtual_webgl, plotlyjs]:
49-
with open(filename, 'r') as fileIn:
55+
with open(filename, "r") as fileIn:
5056
for line in fileIn:
5157
fileOut.write(line)
5258

5359
plotlyjs = plotlyjs_with_virtual_webgl
5460

5561
pio.kaleido.scope.plotlyjs = plotlyjs
56-
pio.kaleido.scope.topojson = "file://" + os.path.join(root, 'topojson', 'dist')
57-
pio.templates.default = 'none'
62+
pio.kaleido.scope.topojson = "file://" + os.path.join(root, "topojson", "dist")
63+
pio.templates.default = "none"
5864

59-
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
65+
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith(".json")]
6066
ALL_MOCKS.sort()
6167

62-
if len(args) > 0 :
68+
if len(args) > 0:
6369
allNames = [a for a in args if a in ALL_MOCKS]
64-
else :
70+
else:
6571
allNames = ALL_MOCKS
6672

67-
# unable to generate baselines for the following mocks
68-
blacklist = [
69-
'map_stamen-style',
70-
'map_predefined-styles2',
71-
'map_scattercluster',
72-
'map_fonts-supported-open-sans',
73-
'map_fonts-supported-open-sans-weight',
74-
]
75-
allNames = [a for a in allNames if a not in blacklist]
76-
77-
if len(allNames) == 0 :
78-
print('error: Nothing to create!')
73+
with open(os.path.join(root, "test", "image", "disallow_list.json"), "r") as f:
74+
# unable to generate baselines for the following mocks
75+
disallowList = set(json.load(f))
76+
allNames = [a for a in allNames if a not in disallowList]
77+
78+
if len(allNames) == 0:
79+
print("error: Nothing to create!")
7980
sys.exit(1)
8081

8182
failed = []
82-
for name in allNames :
83+
for name in allNames:
8384
outName = name
84-
if mathjax_version == 3 :
85-
outName = 'mathjax3___' + name
85+
if mathjax_version == 3:
86+
outName = "mathjax3___" + name
8687

8788
print(outName)
8889

8990
created = False
9091

91-
MAX_RETRY = 2 # 1 means retry once
92-
for attempt in range(0, MAX_RETRY + 1) :
93-
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
92+
MAX_RETRY = 2 # 1 means retry once
93+
for attempt in range(0, MAX_RETRY + 1):
94+
with open(os.path.join(dirIn, name + ".json"), "r") as _in:
9495
fig = json.load(_in)
9596

9697
width = 700
9798
height = 500
98-
if 'layout' in fig :
99-
layout = fig['layout']
100-
if 'autosize' not in layout or layout['autosize'] != True :
101-
if 'width' in layout :
102-
width = layout['width']
103-
if 'height' in layout :
104-
height = layout['height']
105-
106-
if 'b64' in sys.argv or 'b64=' in sys.argv or 'b64-json' in sys.argv :
99+
if "layout" in fig:
100+
layout = fig["layout"]
101+
if "autosize" not in layout or layout["autosize"] != True:
102+
if "width" in layout:
103+
width = layout["width"]
104+
if "height" in layout:
105+
height = layout["height"]
106+
107+
if "b64" in sys.argv or "b64=" in sys.argv or "b64-json" in sys.argv:
107108
newFig = dict()
108109
arraysToB64(fig, newFig)
109110
fig = newFig
110-
if 'b64-json' in sys.argv and attempt == 0 : print(json.dumps(fig, indent = 2))
111+
if "b64-json" in sys.argv and attempt == 0:
112+
print(json.dumps(fig, indent=2))
111113

112-
try :
114+
try:
113115
pio.write_image(
114116
fig=fig,
115-
file=os.path.join(dirOut, outName + '.png'),
117+
file=os.path.join(dirOut, outName + ".png"),
116118
width=width,
117119
height=height,
118-
validate=False
120+
validate=False,
119121
)
120122
created = True
121-
except Exception as e :
123+
except Exception as e:
122124
print(e)
123-
if attempt < MAX_RETRY :
124-
print('retry', attempt + 1, '/', MAX_RETRY)
125-
else :
125+
if attempt < MAX_RETRY:
126+
print("retry", attempt + 1, "/", MAX_RETRY)
127+
else:
126128
failed.append(outName)
127129

128-
if(created) : break
130+
if created:
131+
break
129132

130-
if len(failed) > 0 :
131-
print('Failed at :')
133+
if len(failed) > 0:
134+
print("Failed at :")
132135
print(failed)
133136
sys.exit(1)

0 commit comments

Comments
 (0)