How to use the mozregression.config.get_config function in mozregression

To help you get started, we’ve selected a few mozregression examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / mozregression / tests / unit / test_config.py View on Github external
def test_write_config(tmp, mocker, os_, bits, inputs, conf_dir_exists, results):
    mozinfo = mocker.patch("mozregression.config.mozinfo")
    mozinfo.os = os_
    mozinfo.bits = bits
    mocked_input = mocker.patch("mozregression.config.input")
    mocked_input.return_value = ""
    mocked_input.side_effect = inputs
    conf_path = os.path.join(tmp, "conf.cfg")
    if not conf_dir_exists:
        mozfile.remove(conf_path)
    write_config(conf_path)
    if "persist" in results and results["persist"] is None:
        # default persist is base on the directory of the conf file
        results["persist"] = os.path.join(tmp, "persist")
    conf = get_config(conf_path)
    for key in results:
        assert conf[key] == results[key]
    with open(conf_path) as f:
        # ensure we have comments
        assert "# ------ mozregression configuration file ------" in f.read()
github mozilla / mozregression / tests / unit / test_config.py View on Github external
def test_write_existing_conf(tmp, mocker):
    mocked_input = mocker.patch("mozregression.config.input")
    mocked_input.return_value = ""
    conf_path = os.path.join(tmp, "conf.cfg")
    write_config(conf_path)
    results = get_config(conf_path)
    assert results
    # write conf again
    write_config(conf_path)
    # nothing changed
    assert results == get_config(conf_path)
    with open(conf_path) as f:
        # ensure we have comments
        assert "# ------ mozregression configuration file ------" in f.read()
github mozilla / mozregression / tests / unit / test_config.py View on Github external
def test_write_existing_conf(tmp, mocker):
    mocked_input = mocker.patch("mozregression.config.input")
    mocked_input.return_value = ""
    conf_path = os.path.join(tmp, "conf.cfg")
    write_config(conf_path)
    results = get_config(conf_path)
    assert results
    # write conf again
    write_config(conf_path)
    # nothing changed
    assert results == get_config(conf_path)
    with open(conf_path) as f:
        # ensure we have comments
        assert "# ------ mozregression configuration file ------" in f.read()
github mozilla / mozregression / mozregression / mach_interface.py View on Github external
def parser():
    """
    Create and returns the mozregression ArgumentParser instance.
    """
    defaults = get_config(DEFAULT_CONF_FNAME)
    return create_parser(defaults=defaults)
github mozilla / mozregression / mozregression / tc_authenticate.py View on Github external
def tc_authenticate(logger):
    """
    Returns valid credentials for use with Taskcluster private builds.
    """
    # first, try to load credentials from mozregression config file
    defaults = get_config(DEFAULT_CONF_FNAME)
    client_id = defaults.get("taskcluster-clientid")
    access_token = defaults.get("taskcluster-accesstoken")
    if client_id and access_token:
        return dict(clientId=client_id, accessToken=access_token)

    try:
        # else, try to load a valid certificate locally
        with open(TC_CREDENTIALS_FNAME) as f:
            creds = json.load(f)
        if not tc_utils.isExpired(creds["certificate"]):
            return creds
    except Exception:
        pass

    # here we need to ask for a certificate, this require web browser
    # authentication
github mozilla / mozregression / gui / mozregui / global_prefs.py View on Github external
def get_prefs():
    """
    Return the global prefs as a dict.
    """
    settings = get_config(DEFAULT_CONF_FNAME)
    options = dict()
    options["persist"] = settings["persist"]
    options["http_timeout"] = float(settings["http-timeout"])
    options["persist_size_limit"] = float(settings["persist-size-limit"])
    options["background_downloads"] = (
        False if settings.get("background_downloads") == "no" else True
    )
    options["approx_policy"] = settings["approx-policy"] == "auto"
    options["archive_base_url"] = settings["archive-base-url"]
    options["cmdargs"] = settings["cmdargs"]
    options["enable_telemetry"] = not settings.get("enable-telemetry") in ["no", "0", "false"]

    return options
github mozilla / mozregression / mozregression / cli.py View on Github external
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None):
    """
    parse cli args basically and returns a :class:`Configuration`.

    if namespace is given, it will be used as a arg parsing result, so no
    arg parsing will be done.
    """
    config = get_config(conf_file)
    if namespace:
        options = namespace
    else:
        options = parse_args(argv=argv, defaults=config)
        if not options.cmdargs:
            # we don't set the cmdargs default to be that from the
            # configuration file, because then any new arguments
            # will be appended: https://bugs.python.org/issue16399
            options.cmdargs = config["cmdargs"]
    if conf_file and not os.path.isfile(conf_file):
        print("*" * 10)
        print(
            colorize(
                "You should use a config file. Please use the "
                + "{sBRIGHT}--write-config{sRESET_ALL}"
                + " command line flag to help you create one."