зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1641134 - [tryselect] Fix Python 3 compatibility issues with |mach try --pernosco|, r=mhentges
Differential Revision: https://phabricator.services.mozilla.com/D77364
This commit is contained in:
Родитель
12faf95015
Коммит
b2e6e5eb9d
|
@ -156,15 +156,22 @@ class TrySelect(MachCommandBase):
|
|||
|
||||
def handle_try_config(self, **kwargs):
|
||||
from tryselect.util.dicttools import merge
|
||||
|
||||
to_validate = []
|
||||
kwargs.setdefault('try_config', {})
|
||||
for cls in six.itervalues(self.parser.task_configs):
|
||||
try_config = cls.try_config(**kwargs)
|
||||
if try_config is not None:
|
||||
to_validate.append(cls)
|
||||
kwargs['try_config'] = merge(kwargs['try_config'], try_config)
|
||||
|
||||
for name in cls.dests:
|
||||
del kwargs[name]
|
||||
|
||||
# Validate task_configs after they have all been parsed to avoid
|
||||
# depending on the order they were processed.
|
||||
for cls in to_validate:
|
||||
cls.validate(**kwargs)
|
||||
return kwargs
|
||||
|
||||
def run(self, **kwargs):
|
||||
|
|
|
@ -47,6 +47,9 @@ class TryConfig(object):
|
|||
def try_config(self, **kwargs):
|
||||
pass
|
||||
|
||||
def validate(self, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class Artifact(TryConfig):
|
||||
|
||||
|
@ -112,17 +115,13 @@ class Pernosco(TryConfig):
|
|||
return
|
||||
|
||||
if pernosco:
|
||||
if not kwargs['no_artifact'] and (kwargs['artifact'] or Artifact.is_artifact_build()):
|
||||
print("Pernosco does not support artifact builds at this time. "
|
||||
"Please try again with '--no-artifact'.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
# The Pernosco service currently requires a Mozilla e-mail address to
|
||||
# log in. Prevent people with non-Mozilla addresses from using this
|
||||
# flag so they don't end up consuming time and resources only to
|
||||
# realize they can't actually log in and see the reports.
|
||||
output = subprocess.check_output(['ssh', '-G', 'hg.mozilla.org']).splitlines()
|
||||
cmd = ['ssh', '-G', 'hg.mozilla.org']
|
||||
output = subprocess.check_output(cmd, universal_newlines=True).splitlines()
|
||||
address = [l.rsplit(' ', 1)[-1] for l in output if l.startswith('user')][0]
|
||||
if not address.endswith('@mozilla.com'):
|
||||
print(dedent("""\
|
||||
|
@ -137,7 +136,7 @@ class Pernosco(TryConfig):
|
|||
print("warning: failed to detect current user for 'hg.mozilla.org'")
|
||||
print("Pernosco requires a Mozilla e-mail address to view its reports.")
|
||||
while True:
|
||||
answer = raw_input("Do you have an @mozilla.com address? [Y/n]: ").lower()
|
||||
answer = input("Do you have an @mozilla.com address? [Y/n]: ").lower()
|
||||
if answer == 'n':
|
||||
sys.exit(1)
|
||||
elif answer == 'y':
|
||||
|
@ -149,6 +148,12 @@ class Pernosco(TryConfig):
|
|||
}
|
||||
}
|
||||
|
||||
def validate(self, **kwargs):
|
||||
if kwargs['try_config'].get('use-artifact-builds'):
|
||||
print("Pernosco does not support artifact builds at this time. "
|
||||
"Please try again with '--no-artifact'.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class Path(TryConfig):
|
||||
|
||||
|
|
|
@ -9,8 +9,10 @@ from argparse import ArgumentParser
|
|||
|
||||
import mozunit
|
||||
import pytest
|
||||
import subprocess
|
||||
from textwrap import dedent
|
||||
|
||||
from tryselect.task_config import all_task_configs
|
||||
from tryselect.task_config import all_task_configs, Pernosco
|
||||
|
||||
|
||||
# task configs have a list of tests of the form (input, expected)
|
||||
|
@ -34,6 +36,9 @@ TASK_CONFIG_TESTS = {
|
|||
{'env': {'MOZHARNESS_TEST_PATHS': '{"xpcshell": ["dom/indexedDB", "testing"]}'}}),
|
||||
(['invalid/path'], SystemExit),
|
||||
],
|
||||
'pernosco': [
|
||||
([], None),
|
||||
],
|
||||
'rebuild': [
|
||||
([], None),
|
||||
(['--rebuild', '10'], {'rebuild': 10}),
|
||||
|
@ -89,5 +94,32 @@ def test_task_configs(config_patch_resolver, task_config, args, expected):
|
|||
assert cfg.try_config(**vars(args)) == expected
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patch_pernosco_email_check(monkeypatch):
|
||||
|
||||
def inner(val):
|
||||
|
||||
def fake_check_output(*args, **kwargs):
|
||||
return val
|
||||
|
||||
monkeypatch.setattr(subprocess, 'check_output', fake_check_output)
|
||||
|
||||
return inner
|
||||
|
||||
|
||||
def test_pernosco(patch_pernosco_email_check):
|
||||
patch_pernosco_email_check(dedent("""
|
||||
user foobar@mozilla.com
|
||||
hostname hg.mozilla.com
|
||||
"""))
|
||||
|
||||
parser = ArgumentParser()
|
||||
|
||||
cfg = Pernosco()
|
||||
cfg.add_arguments(parser)
|
||||
args = parser.parse_args(['--pernosco'])
|
||||
assert cfg.try_config(**vars(args)) == {"env": {"PERNOSCO": "1"}}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mozunit.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче