def test_merge_dict():
    assert merge_dict({"foo": "bar"}, {"bar": "baz"}) == {
        "foo": "bar",
        "bar": "baz"
    }
    assert merge_dict({"foo": "bar"}, {"foo": "baz"}) == {"foo": "baz"}
    assert merge_dict({1: 2}, {3: 4}, {5: 6}, {7: 8}) == {
        1: 2,
        3: 4,
        5: 6,
        7: 8
    }
    assert merge_dict({1: 2}, {1: 3}, {1: 4}, {1: 1}) == {1: 1}
Exemple #2
0
def proxy_grequest(*args, **kwargs):
    proxies = get_random_requests_proxies()

    # kwargs["headers"] = merge_dict(kwargs.get("headers", {}), {
    #     "User-Agent": user_agent.random })
    kwargs["proxies"] = merge_dict(kwargs.get("proxies", {}), proxies)

    return grequests.request(*args, **kwargs)
        def foobar(*args, **kwargs):
            args = get_args()
            params = merge_dict(args, override)

            for k, v in iteritems(values):
                assert params[k] == v

            if initial:
                for k in iterkeys(initial):
                    assert initial[k] == args[k]
Exemple #4
0
def command(fn):
    args = get_args()

    params = get_function_arguments(fn)

    params = merge_dict(params, args)

    def wrapper(*args, **kwargs):
        return fn(**params)

    return wrapper
Exemple #5
0
def to_params(kwargs):
    class O(object):
        pass

    params = O()

    kwargs = merge_dict(ARGUMENTS, kwargs)

    for k, v in iteritems(kwargs):
        setattr(params, k, v)

    return params
Exemple #6
0
def run_job(name, variables=None):
    job = [job for job in JOBS if job["name"] == name]
    if not job:
        raise ValueError("No job %s found." % name)
    else:
        job = job[0]

    variables = merge_dict(job.get("variables", {}), variables or {})

    popen(
        "%s -c 'from pipupgrade.util.imports import import_handler; import_handler(\"%s\")()'"
        % (sys.executable, "pipupgrade.jobs.%s.run" % name),
        env=variables)
Exemple #7
0
def _get_pypi_info(name, raise_err=True):
    url = "https://pypi.org/pypi/{}/json".format(name)
    res = req.get(url)

    info = None

    if res.ok:
        data = res.json()
        info = merge_dict(data["info"], {"releases": data["releases"]})
    else:
        if raise_err:
            res.raise_for_status()

    return info