Skip to content

Commit

Permalink
Fix Bug 1132867 - Allow using mozregression with a particular pref
Browse files Browse the repository at this point in the history
  • Loading branch information
imjalpreet authored and parkouss committed Feb 27, 2015
1 parent 1c32586 commit 9a99d82
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
10 changes: 6 additions & 4 deletions mozregression/launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ def _install(self, dest):
mozinstall.install(src=dest, dest=self.tempdir),
self.app_name)

def _start(self, profile=None, addons=(), cmdargs=()):
def _start(self, profile=None, addons=(), cmdargs=(), preferences=None):
if profile:
profile = self.profile_class(profile=profile, addons=addons)
profile = self.profile_class(profile=profile, addons=addons,
preferences=preferences)
elif len(addons):
profile = self.profile_class(addons=addons)
profile = self.profile_class(addons=addons,
preferences=preferences)
else:
profile = self.profile_class()
profile = self.profile_class(preferences=preferences)

self._logger.info("Launching %s" % self.binary)
process_args = {'processOutputLine': [self._logger.debug]}
Expand Down
37 changes: 37 additions & 0 deletions mozregression/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import atexit
import os

import mozprofile
from argparse import ArgumentParser
from ConfigParser import SafeConfigParser, Error
from mozlog.structured import commandline, get_default_logger
Expand Down Expand Up @@ -132,6 +133,15 @@ def parse_args(argv=None):
help=("a command-line argument to pass to the"
" application; repeat for multiple arguments."))

parser.add_argument('--pref', nargs='*', dest='prefs',
help=(" A preference to set. Must be a key-value pair"
" separated by a ':'"))

parser.add_argument('--preferences', nargs="*", dest='prefs_files',
help=("read preferences from a JSON or INI file. For"
" INI, use 'file.ini:section' to specify a"
" particular section."))

parser.add_argument("-n", "--app",
choices=FC_REGISTRY.names(),
default=defaults.get("app", "firefox"),
Expand Down Expand Up @@ -255,6 +265,32 @@ def bisect_nightlies(runner, logger):
return runner.bisect_nightlies(good_date, bad_date)


def preference(prefs_files, prefs_args):
"""
profile preferences
"""
# object that will hold the preferences
prefs = mozprofile.prefs.Preferences()

# add preferences files
if prefs_files:
for prefs_file in prefs_files:
prefs.add_file(prefs_file)

separator = ':'
cli_prefs = []
if prefs_args:
for pref in prefs_args:
if separator not in pref:
continue
cli_prefs.append(pref.split(separator, 1))

# string preferences
prefs.add(cli_prefs, cast=True)

return prefs()


def cli(argv=None):
"""
main entry point of mozregression command line.
Expand All @@ -281,6 +317,7 @@ def cli(argv=None):
addons=options.addons,
profile=options.profile,
cmdargs=options.cmdargs,
preferences=preference(options.prefs_files, options.prefs),
)
test_runner = ManualTestRunner(fetch_config,
persist=options.persist,
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,20 @@ def test_start_no_args(self, Runner):

@patch('mozregression.launchers.Runner')
def test_start_with_addons(self, Runner):
self.launcher_start(addons=['my-addon'])
self.profile_class.assert_called_once_with(addons=['my-addon'])
self.launcher_start(addons=['my-addon'], preferences='my-prefs')
self.profile_class.assert_called_once_with(addons=['my-addon'],
preferences='my-prefs')
# runner is started
self.launcher.runner.start.assert_called_once_with()
self.launcher.stop()

@patch('mozregression.launchers.Runner')
def test_start_with_profile_and_addons(self, Runner):
self.launcher_start(profile='my-profile', addons=['my-addon'])
self.launcher_start(profile='my-profile', addons=['my-addon'],
preferences='my-prefs')
self.profile_class.assert_called_once_with(profile='my-profile',
addons=['my-addon'])
addons=['my-addon'],
preferences='my-prefs')
# runner is started
self.launcher.runner.start.assert_called_once_with()
self.launcher.stop()
Expand Down

0 comments on commit 9a99d82

Please sign in to comment.