Skip to content

Commit 59244ac

Browse files
committed
pylint refactoring
1 parent e6e7373 commit 59244ac

File tree

1 file changed

+85
-45
lines changed

1 file changed

+85
-45
lines changed

tests/performance_sitespeed_io.py

+85-45
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ def run_test(global_translation, lang_code, url):
109109

110110
if use_reference and reference_rating != None:
111111
validator_rating_overall = validator_rating.get_overall()
112-
if reference_rating < validator_rating_overall and validator_rating_overall != -1 and validator_rating_overall != -1:
112+
if reference_rating < validator_rating_overall and\
113+
validator_rating_overall != -1 and\
114+
validator_rating_overall != -1:
113115
rating.overall_review += '- [{2}] Advice: Rating may improve from {0} to {1} with {3} changes\r\n'.format(
114116
reference_rating, validator_rating_overall, reference_name, validator_name)
115117

@@ -126,32 +128,31 @@ def get_validators():
126128
base_directory.resolve(), 'sitespeed-rules.json')
127129
if not os.path.exists(config_file):
128130
return []
129-
with open(config_file) as json_config_file:
131+
with open(config_file, encoding='utf-8') as json_config_file:
130132
data = json.load(json_config_file)
131133
return data
132134

133135

134136
def validate_on_mobile_using_validator(url, validator_config):
135-
browertime_plugin_options = ''
136-
137-
if 'headers' in validator_config:
138-
index = 1
139-
for header in validator_config['headers']:
140-
browertime_plugin_options += ' --browsertime.webperf.header0{0} {1}={2}'.format(
141-
index, header['name'].replace(' ', '%20').replace('=', '%3D'), header['value'].replace(' ', '%20').replace('=', '%3D'))
142-
index += 1
143-
if 'htmls' in validator_config:
144-
index = 1
145-
for header in validator_config['htmls']:
146-
browertime_plugin_options += ' --browsertime.webperf.HTML0{0} {1}={2}'.format(
147-
index, header['replace'].replace(' ', '%20').replace('=', '%3D'), header['replaceWith'].replace(' ', '%20').replace('=', '%3D'))
148-
index += 1
149-
150-
arg = '--shm-size=1g -b chrome --mobile true --chrome.CPUThrottlingRate 3 --connectivity.profile 3gfast --visualMetrics true --plugins.remove screenshot --speedIndex true --xvfb --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} --preScript chrome-custom.cjs {1}{2}'.format(
151-
get_config_or_default('SITESPEED_ITERATIONS'), url, browertime_plugin_options)
152-
if 'nt' in os.name:
153-
arg = '--shm-size=1g -b chrome --mobile true --chrome.CPUThrottlingRate 3 --connectivity.profile 3gfast --visualMetrics true --plugins.remove screenshot --speedIndex true --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} --preScript chrome-custom.cjs {1}{2}'.format(
154-
get_config_or_default('SITESPEED_ITERATIONS'), url, browertime_plugin_options)
137+
browertime_plugin_options = get_browsertime_plugin_options(validator_config)
138+
arg = (
139+
'--shm-size=1g '
140+
'-b chrome '
141+
'--mobile true '
142+
'--chrome.CPUThrottlingRate 3 '
143+
'--connectivity.profile 3gfast '
144+
'--visualMetrics true '
145+
'--plugins.remove screenshot '
146+
'--speedIndex true '
147+
'--browsertime.videoParams.createFilmstrip false '
148+
'--browsertime.chrome.args ignore-certificate-errors '
149+
f'-n {get_config_or_default('SITESPEED_ITERATIONS')} '
150+
'--preScript chrome-custom.cjs '
151+
f'{url}'
152+
f'{browertime_plugin_options}'
153+
)
154+
if 'nt' not in os.name:
155+
arg = '--xvfb ' + arg
155156

156157
result_dict = get_result_dict(get_result(
157158
SITESPEED_USE_DOCKER, arg), validator_config['name'])
@@ -160,28 +161,46 @@ def validate_on_mobile_using_validator(url, validator_config):
160161

161162
return result_dict
162163

163-
164-
def validate_on_desktop_using_validator(url, validator_config):
164+
def get_browsertime_plugin_options(validator_config):
165165
browertime_plugin_options = ''
166-
167166
if 'headers' in validator_config:
168167
index = 1
169168
for header in validator_config['headers']:
170-
browertime_plugin_options += ' --browsertime.webperf.header0{0} {1}={2}'.format(
171-
index, header['name'].replace(' ', '%20').replace('=', '%3D'), header['value'].replace(' ', '%20').replace('=', '%3D'))
169+
browertime_plugin_options += (
170+
f' --browsertime.webperf.header0{index}'
171+
f' {header['name'].replace(' ', '%20').replace('=', '%3D')}='
172+
f'{header['value'].replace(' ', '%20').replace('=', '%3D')}')
172173
index += 1
173174
if 'htmls' in validator_config:
174175
index = 1
175176
for header in validator_config['htmls']:
176-
browertime_plugin_options += ' --browsertime.webperf.HTML0{0} {1}={2}'.format(
177-
index, header['replace'].replace(' ', '%20').replace('=', '%3D'), header['replaceWith'].replace(' ', '%20').replace('=', '%3D'))
177+
browertime_plugin_options += (
178+
f' --browsertime.webperf.HTML0{index}'
179+
f' {header['replace'].replace(' ', '%20').replace('=', '%3D')}='
180+
f'{header['replaceWith'].replace(' ', '%20').replace('=', '%3D')}')
178181
index += 1
182+
return browertime_plugin_options
183+
179184

180-
arg = '--shm-size=1g -b chrome --connectivity.profile native --visualMetrics true --plugins.remove screenshot --speedIndex true --xvfb --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} --preScript chrome-custom.cjs {1}{2}'.format(
181-
get_config_or_default('SITESPEED_ITERATIONS'), url, browertime_plugin_options)
182-
if 'nt' in os.name:
183-
arg = '--shm-size=1g -b chrome --connectivity.profile native --visualMetrics true --plugins.remove screenshot --speedIndex true --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} --preScript chrome-custom.cjs {1}{2}'.format(
184-
get_config_or_default('SITESPEED_ITERATIONS'), url, browertime_plugin_options)
185+
def validate_on_desktop_using_validator(url, validator_config):
186+
browertime_plugin_options = get_browsertime_plugin_options(validator_config)
187+
188+
arg = (
189+
'--shm-size=1g '
190+
'-b chrome '
191+
'--connectivity.profile native '
192+
'--visualMetrics true '
193+
'--plugins.remove screenshot '
194+
'--speedIndex true '
195+
'--browsertime.videoParams.createFilmstrip false '
196+
'--browsertime.chrome.args ignore-certificate-errors '
197+
f'-n {get_config_or_default('SITESPEED_ITERATIONS')} '
198+
'--preScript chrome-custom.cjs '
199+
f'{url}'
200+
f'{browertime_plugin_options}'
201+
)
202+
if 'nt' not in os.name:
203+
arg = '--xvfb ' + arg
185204

186205
result_dict = get_result_dict(get_result(
187206
SITESPEED_USE_DOCKER, arg), validator_config['name'])
@@ -192,11 +211,21 @@ def validate_on_desktop_using_validator(url, validator_config):
192211

193212

194213
def validate_on_desktop(url):
195-
arg = '--shm-size=1g -b chrome --connectivity.profile native --visualMetrics true --plugins.remove screenshot --speedIndex true --xvfb --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} {1}'.format(
196-
get_config_or_default('SITESPEED_ITERATIONS'), url)
197-
if 'nt' in os.name:
198-
arg = '--shm-size=1g -b chrome --connectivity.profile native --visualMetrics true --plugins.remove screenshot --speedIndex true --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} {1}'.format(
199-
get_config_or_default('SITESPEED_ITERATIONS'), url)
214+
arg = (
215+
'--shm-size=1g '
216+
'-b chrome '
217+
'--connectivity.profile native '
218+
'--visualMetrics true '
219+
'--plugins.remove screenshot '
220+
'--speedIndex true '
221+
'--browsertime.videoParams.createFilmstrip false '
222+
'--browsertime.chrome.args ignore-certificate-errors '
223+
f'-n {get_config_or_default('SITESPEED_ITERATIONS')} '
224+
'--preScript chrome-custom.cjs '
225+
f'{url}'
226+
)
227+
if 'nt' not in os.name:
228+
arg = '--xvfb ' + arg
200229

201230
result_dict = get_result_dict(get_result(
202231
SITESPEED_USE_DOCKER, arg), 'desktop')
@@ -205,11 +234,22 @@ def validate_on_desktop(url):
205234

206235

207236
def validate_on_mobile(url):
208-
arg = '--shm-size=1g -b chrome --mobile true --connectivity.profile 3gfast --visualMetrics true --plugins.remove screenshot --speedIndex true --xvfb --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} {1}'.format(
209-
get_config_or_default('SITESPEED_ITERATIONS'), url)
210-
if 'nt' in os.name:
211-
arg = '--shm-size=1g -b chrome --mobile true --connectivity.profile 3gfast --visualMetrics true --plugins.remove screenshot --speedIndex true --browsertime.videoParams.createFilmstrip false --browsertime.chrome.args ignore-certificate-errors -n {0} {1}'.format(
212-
get_config_or_default('SITESPEED_ITERATIONS'), url)
237+
arg = (
238+
'--shm-size=1g '
239+
'-b chrome '
240+
'--mobile true '
241+
'--connectivity.profile 3gfast '
242+
'--visualMetrics true '
243+
'--plugins.remove screenshot '
244+
'--speedIndex true '
245+
'--browsertime.videoParams.createFilmstrip false '
246+
'--browsertime.chrome.args ignore-certificate-errors '
247+
f'-n {get_config_or_default('SITESPEED_ITERATIONS')} '
248+
'--preScript chrome-custom.cjs '
249+
f'{url}'
250+
)
251+
if 'nt' not in os.name:
252+
arg = '--xvfb ' + arg
213253

214254
result_dict = get_result_dict(get_result(
215255
SITESPEED_USE_DOCKER, arg), 'mobile')
@@ -220,7 +260,7 @@ def validate_on_mobile(url):
220260
def rate_result_dict(result_dict, reference_result_dict, mode, global_translation, local_translation):
221261
limit = 500
222262

223-
rating = Rating(_)
263+
rating = Rating(global_translation)
224264
performance_review = ''
225265
overview_review = ''
226266

0 commit comments

Comments
 (0)