コード例 #1
0
    def cli_parser():
        import os
        import pickle
        import sys
        from ptvsd.server import cli, options

        try:
            sys.argv[1:] = cli.parse(sys.argv[1:])
        except Exception as exc:
            os.write(1, pickle.dumps(exc))
            sys.exit(1)
        else:
            # We only care about options that correspond to public switches.
            options = {
                name: getattr(options, name)
                for name in [
                    "target_kind",
                    "target",
                    "host",
                    "port",
                    "client",
                    "wait",
                    "multiprocess",
                ]
            }
            os.write(1, pickle.dumps([sys.argv[1:], options]))
コード例 #2
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
コード例 #3
0
def test_port_default():
    reload(options)
    cli.parse(["--host", "localhost", "spam.py"])
    assert options.port == 5678
コード例 #4
0
def test_host_empty():
    reload(options)
    cli.parse(["--host", "", "--port", "8888", "spam.py"])
    assert options.host == ""
コード例 #5
0
def test_host_required():
    reload(options)
    with pytest.raises(Exception):
        cli.parse(["--port", "8888", "-m", "spam"])
コード例 #6
0
def test_unsupported_arg():
    reload(options)
    with pytest.raises(Exception):
        cli.parse(["--port", "8888", "--xyz", "123", "spam.py"])