예제 #1
0
def test_create_reject_large_model_def(requests_mock: requests_mock.Mocker,
                                       tmp_path: Path) -> None:
    requests_mock.get("/info", status_code=200, json={"version": "1.0"})

    requests_mock.get("/users/me",
                      status_code=200,
                      json={"username": constants.DEFAULT_DETERMINED_USER})

    requests_mock.post("/experiments",
                       status_code=requests.codes.created,
                       headers={"Location": "/experiments/1"})

    with tempfile.NamedTemporaryFile() as model_def_file:
        model_def_file.write(os.urandom(constants.MAX_CONTEXT_SIZE + 1))
        with FileTree(tmp_path, {"config.yaml": MINIMAL_CONFIG
                                 }) as tree, pytest.raises(SystemExit):
            cli.main([
                "experiment", "create",
                str(tree.joinpath("config.yaml")), model_def_file.name
            ])
예제 #2
0
def test_create_with_model_def(requests_mock: requests_mock.Mocker,
                               tmp_path: Path) -> None:
    requests_mock.get("/info", status_code=200, json={"version": "1.0"})

    requests_mock.get("/users/me",
                      status_code=200,
                      json={"username": constants.DEFAULT_DETERMINED_USER})

    requests_mock.post("/login", status_code=200, json={"token": "fake-token"})

    requests_mock.post("/experiments",
                       status_code=requests.codes.created,
                       headers={"Location": "/experiments/1"})

    tempfile.mkstemp(dir=str(tmp_path))
    tempfile.mkstemp(dir=str(tmp_path))
    tempfile.mkstemp(dir=str(tmp_path))

    with FileTree(tmp_path, {"config.yaml": MINIMAL_CONFIG}) as tree:
        cli.main([
            "experiment", "create", "--paused",
            str(tree.joinpath("config.yaml")),
            str(tmp_path)
        ])
예제 #3
0
def test_cli_args_exist() -> None:
    valid_cmds = [
        "auth",
        "agent",
        "a",
        "command",
        "cmd",
        "checkpoint",
        "c",
        "deploy",
        "d",
        "experiment",
        "e",
        "master",
        "m",
        "model",
        "m",
        "notebook",
        "oauth",
        "resources",
        "res",
        "shell",
        "slot",
        "s",
        "task",
        "template",
        "tpl",
        "tensorboard",
        "trial",
        "t",
        "user",
        "u",
    ]
    for cmd in valid_cmds:
        cli.main([cmd, "help"])

    cli.main([])
    for cmd in ["version", "help"]:
        cli.main([cmd])

    with pytest.raises(SystemExit) as e:
        cli.main(["preview-search", "-h"])
    assert e.value.code == 0
예제 #4
0
def test_uuid_prefix(requests_mock: requests_mock.Mocker) -> None:
    # Create two UUIDs that are different at a known index.
    fake_uuid1 = str(uuid.uuid4())
    replace_ind = 4
    fake_uuid2 = (fake_uuid1[:replace_ind] +
                  ("1" if fake_uuid1[replace_ind] == "0" else "0") +
                  fake_uuid1[replace_ind + 1:])

    requests_mock.get("/info", status_code=200, json={"version": "1.0"})
    requests_mock.get("/users/me",
                      status_code=200,
                      json={"username": constants.DEFAULT_DETERMINED_USER})

    requests_mock.get(
        "/api/v1/shells",
        status_code=requests.codes.ok,
        json={"shells": [{
            "id": fake_uuid1
        }, {
            "id": fake_uuid2
        }]},
    )

    requests_mock.get(
        f"/api/v1/shells/{fake_uuid1}",
        status_code=requests.codes.ok,
        json={"config": None},
    )

    # Succeed with a full UUID.
    cli.main(["shell", "config", fake_uuid1])
    # Succeed with a partial unique prefix.
    cli.main(["shell", "config", fake_uuid1[:replace_ind + 1]])
    # Fail with an existing but nonunique prefix.
    with pytest.raises(SystemExit):
        cli.main(["shell", "config", fake_uuid1[:replace_ind]])
    # Fail with a nonexistent prefix.
    with pytest.raises(SystemExit):
        cli.main(["shell", "config", "x"])
예제 #5
0
from determined.cli.cli import main

if __name__ == "__main__":
    main()