Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2015143

Browse files
author
Sourcery AI
committed
'Refactored by Sourcery'
1 parent 31e7086 commit 2015143

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

test/image/make_baseline.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,12 @@
3636
pio.templates.default = 'none'
3737
pio.kaleido.scope.plotlyjs = os.path.join(root, 'build', 'plotly.js')
3838

39-
_credentials = open(os.path.join(root, 'build', 'credentials.json'), 'r')
40-
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
41-
_credentials.close()
42-
39+
with open(os.path.join(root, 'build', 'credentials.json'), 'r') as _credentials:
40+
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
4341
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
4442
ALL_MOCKS.sort()
4543

46-
if len(args) > 0 :
47-
allNames = [a for a in args if a in ALL_MOCKS]
48-
else :
49-
allNames = ALL_MOCKS
50-
44+
allNames = [a for a in args if a in ALL_MOCKS] if len(args) > 0 else ALL_MOCKS
5145
# gl2d pointcloud and other non-regl gl2d mock(s)
5246
# must be tested in certain order to work on CircleCI;
5347
#
@@ -81,23 +75,23 @@
8175
]
8276
allNames = [a for a in allNames if a not in blacklist]
8377

84-
if len(allNames) == 0 :
78+
if not allNames:
8579
print('error: Nothing to create!')
8680
sys.exit(1)
8781

8882
failed = []
89-
for name in allNames :
83+
MAX_RETRY = 2 # 1 means retry once
84+
for name in allNames:
9085
outName = name
91-
if mathjax_version == 3 :
92-
outName = 'mathjax3___' + name
86+
if mathjax_version == 3:
87+
outName = f'mathjax3___{name}'
9388

9489
print(outName)
9590

9691
created = False
9792

98-
MAX_RETRY = 2 # 1 means retry once
99-
for attempt in range(0, MAX_RETRY + 1) :
100-
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
93+
for attempt in range(MAX_RETRY + 1):
94+
with open(os.path.join(dirIn, f'{name}.json'), 'r') as _in:
10195
fig = json.load(_in)
10296

10397
width = 700
@@ -110,14 +104,15 @@
110104
if 'height' in layout :
111105
height = layout['height']
112106

113-
try :
107+
try:
114108
pio.write_image(
115109
fig=fig,
116-
file=os.path.join(dirOut, outName + '.png'),
110+
file=os.path.join(dirOut, f'{outName}.png'),
117111
width=width,
118112
height=height,
119-
validate=False
113+
validate=False,
120114
)
115+
121116
created = True
122117
except Exception as e :
123118
print(e)
@@ -128,7 +123,7 @@
128123

129124
if(created) : break
130125

131-
if len(failed) > 0 :
126+
if failed:
132127
print('Failed at :')
133128
print(failed)
134129
sys.exit(1)

test/image/make_exports.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
pio.templates.default = 'none'
1111
pio.kaleido.scope.plotlyjs = os.path.join(root, 'build', 'plotly.js')
1212

13-
_credentials = open(os.path.join(root, 'build', 'credentials.json'), 'r')
14-
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
15-
_credentials.close()
16-
13+
with open(os.path.join(root, 'build', 'credentials.json'), 'r') as _credentials:
14+
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
1715
allFormats = ['svg', 'jpg', 'jpeg', 'webp', 'eps', 'pdf']
1816
# 'png' is tested by image-test
1917

@@ -36,11 +34,11 @@
3634
]
3735

3836
failed = 0
39-
for name in allNames :
40-
for fmt in allFormats :
41-
print(name + ' --> ' + fmt)
37+
for name in allNames:
38+
for fmt in allFormats:
39+
print(f'{name} --> {fmt}')
4240

43-
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
41+
with open(os.path.join(dirIn, f'{name}.json'), 'r') as _in:
4442
fig = json.load(_in)
4543

4644
width = 700
@@ -53,15 +51,16 @@
5351
if 'height' in layout :
5452
height = layout['height']
5553

56-
try :
54+
try:
5755
pio.write_image(
5856
fig=fig,
59-
file=os.path.join(dirOut, name + '.' + fmt),
57+
file=os.path.join(dirOut, f'{name}.{fmt}'),
6058
width=width,
6159
height=height,
62-
validate=False
60+
validate=False,
6361
)
6462

63+
6564
except Exception as e :
6665
print(e)
6766
failed += 1

0 commit comments

Comments
 (0)