|
4 | 4 | import plotly.io as pio |
5 | 5 |
|
6 | 6 | root = os.getcwd() |
7 | | -dirIn = os.path.join(root, 'test', 'image', 'mocks') |
8 | | -dirOut = os.path.join(root, 'build', 'test_images') |
| 7 | +dirIn = os.path.join(root, "test", "image", "mocks") |
| 8 | +dirOut = os.path.join(root, "build", "test_images") |
9 | 9 | os.makedirs(dirOut, exist_ok=True) |
10 | 10 |
|
11 | | -pio.templates.default = 'none' |
12 | | -pio.kaleido.scope.plotlyjs = os.path.join(root, 'build', 'plotly.js') |
| 11 | +pio.templates.default = "none" |
| 12 | +pio.kaleido.scope.plotlyjs = os.path.join(root, "build", "plotly.js") |
13 | 13 |
|
14 | | -allFormats = ['svg', 'jpg', 'jpeg', 'webp', 'pdf'] |
| 14 | +allFormats = ["svg", "jpg", "jpeg", "webp", "pdf"] |
15 | 15 | # 'png' is tested by image-test |
16 | 16 |
|
17 | 17 | allNames = [ |
18 | | - 'plot_types', |
19 | | - 'annotations', |
20 | | - 'shapes', |
21 | | - 'range_slider', |
22 | | - 'contour_legend-colorscale', |
23 | | - 'layout_image', |
24 | | - 'image_astronaut_source', |
25 | | - 'gl2d_no-clustering2', |
26 | | - 'gl3d_surface-heatmap-treemap_transparent-colorscale', |
27 | | - 'map_density-multiple_legend', |
28 | | - 'smith_modes', |
29 | | - 'zsmooth_methods', |
30 | | - 'fonts', |
31 | | - 'worldcup', |
32 | | - 'mathjax' |
| 18 | + "plot_types", |
| 19 | + "annotations", |
| 20 | + "shapes", |
| 21 | + "range_slider", |
| 22 | + "contour_legend-colorscale", |
| 23 | + "layout_image", |
| 24 | + "image_astronaut_source", |
| 25 | + "gl2d_no-clustering2", |
| 26 | + "gl3d_surface-heatmap-treemap_transparent-colorscale", |
| 27 | + "map_density-multiple_legend", |
| 28 | + "smith_modes", |
| 29 | + "zsmooth_methods", |
| 30 | + "fonts", |
| 31 | + "worldcup", |
| 32 | + "mathjax", |
33 | 33 | ] |
34 | 34 |
|
35 | 35 | failed = 0 |
36 | | -for name in allNames : |
37 | | - for fmt in allFormats : |
38 | | - print(name + ' --> ' + fmt) |
| 36 | +for name in allNames: |
| 37 | + for fmt in allFormats: |
| 38 | + print(name + " --> " + fmt) |
39 | 39 |
|
40 | | - with open(os.path.join(dirIn, name + '.json'), 'r') as _in : |
| 40 | + with open(os.path.join(dirIn, name + ".json"), "r") as _in: |
41 | 41 | fig = json.load(_in) |
42 | 42 |
|
43 | 43 | width = 700 |
44 | 44 | height = 500 |
45 | | - if 'layout' in fig : |
46 | | - layout = fig['layout'] |
47 | | - if 'autosize' not in layout or layout['autosize'] != True : |
48 | | - if 'width' in layout : |
49 | | - width = layout['width'] |
50 | | - if 'height' in layout : |
51 | | - height = layout['height'] |
| 45 | + if "layout" in fig: |
| 46 | + layout = fig["layout"] |
| 47 | + if "autosize" not in layout or layout["autosize"] != True: |
| 48 | + if "width" in layout: |
| 49 | + width = layout["width"] |
| 50 | + if "height" in layout: |
| 51 | + height = layout["height"] |
52 | 52 |
|
53 | | - try : |
| 53 | + try: |
54 | 54 | pio.write_image( |
55 | 55 | fig=fig, |
56 | | - file=os.path.join(dirOut, name + '.' + fmt), |
| 56 | + file=os.path.join(dirOut, name + "." + fmt), |
57 | 57 | width=width, |
58 | 58 | height=height, |
59 | | - validate=False |
| 59 | + validate=False, |
60 | 60 | ) |
61 | 61 |
|
62 | | - except Exception as e : |
| 62 | + except Exception as e: |
63 | 63 | print(e) |
64 | 64 | failed += 1 |
65 | 65 |
|
66 | | -if failed > 0 : sys.exit(1) |
| 66 | +if failed > 0: |
| 67 | + sys.exit(1) |
0 commit comments