Skip to content

Commit

Permalink
modify: runner - added custom params option
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcupial committed Feb 22, 2019
1 parent 2cbf023 commit 3a26898
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
-
## [1.0.2] - 2019-02-22
### Changed
- added option to runner to pass custom parameters

## [1.0.1] - 2019-02-14
### Changed
Expand All @@ -18,3 +21,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[Unreleased]: https://github.com/adamcupial/lighthouse-python/compare/1.0.1...HEAD
[1.0.1]: https://github.com/adamcupial/lighthouse-python/compare/1.0.0...1.0.1
[1.0.2]: https://github.com/adamcupial/lighthouse-python/compare/1.0.1...1.0.2
17 changes: 12 additions & 5 deletions lighthouse/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,32 @@ class LighthouseRunner(object):
report (LighthouseReport): object with simplified report
"""

def __init__(self, url, form_factor='mobile', quiet=True):
def __init__(self, url, form_factor='mobile', quiet=True,
additional_settings=None):
"""
Args:
url (str): url to test
form_factor (str, optional): either mobile or desktop,
default is mobile
quiet (bool, optional): should not output anything to stdout,
default is True
additional_settings (list, optional): list of additional params
"""

assert form_factor in ['mobile', 'desktop']

_, self.__report_path = tempfile.mkstemp(suffix='.json')
self._run(url, form_factor, quiet)
self._run(url, form_factor, quiet, additional_settings)
self.report = self._get_report()
self._clean()

def _run(self, url, form_factor, quiet):
def _run(self, url, form_factor, quiet, additional_settings=None):
report_path = self.__report_path

additional_settings = additional_settings or []

try:
subprocess.check_call(' '.join([
command = [
'lighthouse',
url,
'--quiet' if quiet else '',
Expand All @@ -48,7 +52,10 @@ def _run(self, url, form_factor, quiet):
'--emulated-form-factor={0}'.format(form_factor),
'--output=json',
'--output-path={0}'.format(report_path),
]), shell=True)
]

command = command + additional_settings
subprocess.check_call(' '.join(command), shell=True)
except subprocess.CalledProcessError as exc:
msg = '''
Command "{0}"
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python

# this python file uses the following encoding utf-8
from setuptools import setup, find_packages

setup(
name='lighthouse',
version='1.0.1',
version='1.0.2',
description='Lightouse runner',
author='Adam Cupiał',
author='Adam Cupial',
author_email='[email protected]',
url='n/a',
packages=find_packages(),
Expand Down

0 comments on commit 3a26898

Please sign in to comment.