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

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
'Refactored by Sourcery'
  • Loading branch information
Sourcery AI committed May 27, 2022
commit 2015143cd8f80b79190bee34293b4de682148f93
35 changes: 15 additions & 20 deletions test/image/make_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,12 @@
pio.templates.default = 'none'
pio.kaleido.scope.plotlyjs = os.path.join(root, 'build', 'plotly.js')

_credentials = open(os.path.join(root, 'build', 'credentials.json'), 'r')
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
_credentials.close()

with open(os.path.join(root, 'build', 'credentials.json'), 'r') as _credentials:
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
ALL_MOCKS.sort()

if len(args) > 0 :
allNames = [a for a in args if a in ALL_MOCKS]
else :
allNames = ALL_MOCKS

allNames = [a for a in args if a in ALL_MOCKS] if len(args) > 0 else ALL_MOCKS
Comment on lines -39 to +44
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 39-131 refactored with the following changes:

# gl2d pointcloud and other non-regl gl2d mock(s)
# must be tested in certain order to work on CircleCI;
#
Expand Down Expand Up @@ -81,23 +75,23 @@
]
allNames = [a for a in allNames if a not in blacklist]

if len(allNames) == 0 :
if not allNames:
print('error: Nothing to create!')
sys.exit(1)

failed = []
for name in allNames :
MAX_RETRY = 2 # 1 means retry once
for name in allNames:
outName = name
if mathjax_version == 3 :
outName = 'mathjax3___' + name
if mathjax_version == 3:
outName = f'mathjax3___{name}'

print(outName)

created = False

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

width = 700
Expand All @@ -110,14 +104,15 @@
if 'height' in layout :
height = layout['height']

try :
try:
pio.write_image(
fig=fig,
file=os.path.join(dirOut, outName + '.png'),
file=os.path.join(dirOut, f'{outName}.png'),
width=width,
height=height,
validate=False
validate=False,
)

created = True
except Exception as e :
print(e)
Expand All @@ -128,7 +123,7 @@

if(created) : break

if len(failed) > 0 :
if failed:
print('Failed at :')
print(failed)
sys.exit(1)
21 changes: 10 additions & 11 deletions test/image/make_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
pio.templates.default = 'none'
pio.kaleido.scope.plotlyjs = os.path.join(root, 'build', 'plotly.js')

_credentials = open(os.path.join(root, 'build', 'credentials.json'), 'r')
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
_credentials.close()

with open(os.path.join(root, 'build', 'credentials.json'), 'r') as _credentials:
pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN']
Comment on lines -13 to +14
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 13-62 refactored with the following changes:

allFormats = ['svg', 'jpg', 'jpeg', 'webp', 'eps', 'pdf']
# 'png' is tested by image-test

Expand All @@ -36,11 +34,11 @@
]

failed = 0
for name in allNames :
for fmt in allFormats :
print(name + ' --> ' + fmt)
for name in allNames:
for fmt in allFormats:
print(f'{name} --> {fmt}')

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

width = 700
Expand All @@ -53,15 +51,16 @@
if 'height' in layout :
height = layout['height']

try :
try:
pio.write_image(
fig=fig,
file=os.path.join(dirOut, name + '.' + fmt),
file=os.path.join(dirOut, f'{name}.{fmt}'),
width=width,
height=height,
validate=False
validate=False,
)


except Exception as e :
print(e)
failed += 1
Expand Down