Skip to content

Commit

Permalink
feat(launch): Creates a --build flag for building an image then pus…
Browse files Browse the repository at this point in the history
…hing to a queue (#4061)
  • Loading branch information
gtarpenning authored and andrewtruong committed Dec 2, 2022
1 parent a0ae755 commit 3d1d06b
Show file tree
Hide file tree
Showing 13 changed files with 867 additions and 133 deletions.
100 changes: 81 additions & 19 deletions tests/unit_tests/tests_launch/test_launch.py
@@ -1,36 +1,98 @@
import os

import pytest
import wandb
from wandb.errors import LaunchError
from wandb.sdk.internal.internal_api import Api as InternalApi
from wandb.sdk.launch.launch_add import launch_add
from wandb.sdk.launch.launch import run


def test_launch_delete_queued_run(relay_server, runner, user, monkeypatch):
def test_launch_repository(
relay_server, runner, user, monkeypatch, wandb_init, test_settings
):
queue = "default"
proj = "test"
proj = "test1"
repo = "testing123"
uri = "https://github.com/wandb/examples.git"
entry_point = ["python", "/examples/examples/launch/launch-quickstart/train.py"]

settings = test_settings({"project": proj})
api = InternalApi()
os.environ["WANDB_PROJECT"] = proj # required for artifact query

# create project
run = wandb.init(project=proj)
run.finish()
monkeypatch.setattr(
wandb.sdk.launch.builder.build,
"validate_docker_installation",
lambda: None,
)

monkeypatch.setattr(
wandb.docker,
"build",
lambda tags, file, context_path: None,
)

def patched_docker_push(reg, tag):
assert reg == repo

monkeypatch.setattr(
wandb.docker,
"push",
lambda reg, tag: patched_docker_push(reg, tag),
)

with relay_server():
wandb_init(settings=settings).finish()
api.create_run_queue(
entity=user, project=proj, queue_name=queue, access="PROJECT"
)

queued_run = launch_add(
uri=uri,
entity=user,
project=proj,
queue_name=queue,
entry_point=entry_point,
)
with pytest.raises(LaunchError) as e_info:
run(
api,
uri=uri,
entity=user,
project=proj,
entry_point=entry_point,
repository=repo,
)

assert "Failed to push image to repository" in str(e_info)


def test_launch_incorrect_backend(
relay_server, runner, user, monkeypatch, wandb_init, test_settings
):
proj = "test1"
uri = "https://github.com/wandb/examples.git"
entry_point = ["python", "/examples/examples/launch/launch-quickstart/train.py"]
settings = test_settings({"project": proj})
api = InternalApi()

monkeypatch.setattr(
"wandb.sdk.launch.launch.fetch_and_validate_project",
lambda _1, _2: "something",
)

monkeypatch.setattr(
wandb.sdk.launch.builder.build,
"validate_docker_installation",
lambda: None,
)

monkeypatch.setattr(
"wandb.docker",
lambda: None,
)

with relay_server():
r = wandb_init(settings=settings)

assert queued_run.state == "pending"
with pytest.raises(LaunchError) as e_info:
run(
api,
uri=uri,
entity=user,
project=proj,
entry_point=entry_point,
resource="testing123",
)

queued_run.delete()
assert "Resource name not among available resources" in str(e_info)
r.finish()

0 comments on commit 3d1d06b

Please sign in to comment.