Exemplo n.º 1
0
def test_targets(target_kind, client, wait, subprocesses, extra):
    args = ["--host", "localhost", "--port", "8888"]

    if client:
        args += ["--client"]

    if wait:
        args += ["--wait"]

    if not subprocesses:
        args += ["--no-subprocesses"]

    if target_kind == "file":
        target = "spam.py"
        args += [target]
    elif target_kind == "module":
        target = "spam"
        args += ["-m", target]
    elif target_kind == "code":
        target = "123"
        args += ["-c", target]
    else:
        pytest.fail(target_kind)

    if extra:
        extra = [
            "ham",
            "--client",
            "--wait",
            "-y",
            "spam",
            "--",
            "--host",
            "--port",
            "-c",
            "--something",
            "-m",
        ]
        args += extra
    else:
        extra = []

    log.debug("args = {0!r}", args)
    reload(options)
    rest = list(cli.parse(args))
    assert rest == extra

    expected_options = {
        "target_kind": target_kind,
        "target": target,
        "host": "localhost",
        "port": 8888,
        "wait": bool(wait),
        "multiprocess": bool(subprocesses),
    }
    actual_options = {name: vars(options)[name] for name in expected_options}
    assert expected_options == actual_options
Exemplo n.º 2
0
def test_port_default():
    reload(options)
    cli.parse(["--host", "localhost", "spam.py"])
    assert options.port == 5678
Exemplo n.º 3
0
def test_host_empty():
    reload(options)
    cli.parse(["--host", "", "--port", "8888", "spam.py"])
    assert options.host == ""
Exemplo n.º 4
0
def test_host_required():
    reload(options)
    with pytest.raises(Exception):
        cli.parse(["--port", "8888", "-m", "spam"])
Exemplo n.º 5
0
def test_unsupported_arg():
    reload(options)
    with pytest.raises(Exception):
        cli.parse(["--port", "8888", "--xyz", "123", "spam.py"])