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

Skip to content

Sourcery refactored master branch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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