@@ -109,7 +109,9 @@ def run_test(global_translation, lang_code, url):
109
109
110
110
if use_reference and reference_rating != None :
111
111
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 :
113
115
rating .overall_review += '- [{2}] Advice: Rating may improve from {0} to {1} with {3} changes\r \n ' .format (
114
116
reference_rating , validator_rating_overall , reference_name , validator_name )
115
117
@@ -126,32 +128,31 @@ def get_validators():
126
128
base_directory .resolve (), 'sitespeed-rules.json' )
127
129
if not os .path .exists (config_file ):
128
130
return []
129
- with open (config_file ) as json_config_file :
131
+ with open (config_file , encoding = 'utf-8' ) as json_config_file :
130
132
data = json .load (json_config_file )
131
133
return data
132
134
133
135
134
136
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
155
156
156
157
result_dict = get_result_dict (get_result (
157
158
SITESPEED_USE_DOCKER , arg ), validator_config ['name' ])
@@ -160,28 +161,46 @@ def validate_on_mobile_using_validator(url, validator_config):
160
161
161
162
return result_dict
162
163
163
-
164
- def validate_on_desktop_using_validator (url , validator_config ):
164
+ def get_browsertime_plugin_options (validator_config ):
165
165
browertime_plugin_options = ''
166
-
167
166
if 'headers' in validator_config :
168
167
index = 1
169
168
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' )} ' )
172
173
index += 1
173
174
if 'htmls' in validator_config :
174
175
index = 1
175
176
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' )} ' )
178
181
index += 1
182
+ return browertime_plugin_options
183
+
179
184
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
185
204
186
205
result_dict = get_result_dict (get_result (
187
206
SITESPEED_USE_DOCKER , arg ), validator_config ['name' ])
@@ -192,11 +211,21 @@ def validate_on_desktop_using_validator(url, validator_config):
192
211
193
212
194
213
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
200
229
201
230
result_dict = get_result_dict (get_result (
202
231
SITESPEED_USE_DOCKER , arg ), 'desktop' )
@@ -205,11 +234,22 @@ def validate_on_desktop(url):
205
234
206
235
207
236
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
213
253
214
254
result_dict = get_result_dict (get_result (
215
255
SITESPEED_USE_DOCKER , arg ), 'mobile' )
@@ -220,7 +260,7 @@ def validate_on_mobile(url):
220
260
def rate_result_dict (result_dict , reference_result_dict , mode , global_translation , local_translation ):
221
261
limit = 500
222
262
223
- rating = Rating (_ )
263
+ rating = Rating (global_translation )
224
264
performance_review = ''
225
265
overview_review = ''
226
266
0 commit comments