@@ -28,27 +28,34 @@ def __init__(self, url, form_factor='mobile', quiet=True):
2828 default is True
2929 """
3030
31+ assert form_factor in ['mobile' , 'desktop' ]
32+
3133 _ , self .__report_path = tempfile .mkstemp (suffix = '.json' )
3234 self ._run (url , form_factor , quiet )
3335 self .report = self ._get_report ()
3436 self ._clean ()
3537
3638 def _run (self , url , form_factor , quiet ):
37- subprocess .call ([
38- 'lighthouse' ,
39- url ,
40- '--quiet' if quiet else '' ,
41- '--chrome-flags' ,
42- '"--headless"' ,
43- '--preset' ,
44- 'full' ,
45- '--emulated-form-factor' ,
46- form_factor ,
47- '--output' ,
48- 'json' ,
49- '--output-path' ,
50- '{0}' .format (self .__report_path ),
51- ])
39+ report_path = self .__report_path
40+
41+ try :
42+ subprocess .check_call (' ' .join ([
43+ 'lighthouse' ,
44+ url ,
45+ '--quiet' if quiet else '' ,
46+ '--chrome-flags="--headless"' ,
47+ '--preset=full' ,
48+ '--emulated-form-factor={0}' .format (form_factor ),
49+ '--output=json' ,
50+ '--output-path={0}' .format (report_path ),
51+ ]), shell = True )
52+ except subprocess .CalledProcessError as exc :
53+ msg = '''
54+ Command "{0}"
55+ returned an error code: {1},
56+ output: {2}
57+ ''' .format (exc .cmd , exc .returncode , exc .output )
58+ raise RuntimeError (msg )
5259
5360 def _get_report (self ):
5461 with open (self .__report_path , 'r' ) as fil :
0 commit comments