Skip to content

Commit

Permalink
Mark test_docker_containers as requiring docker package
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-grodek-dsai committed Aug 30, 2023
1 parent 2d1cd6e commit 77f0b5b
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ def test_generate_langchain_container_tag() -> None:
assert tag != new_tag, "Tags should be different"


@pytest.mark.requires("docker")
def test_docker_image_throws_for_bad_name() -> None:
with pytest.raises(ValueError):
DockerImage(name="docker_image_which_should_not_exist_42")


@pytest.mark.requires("docker")
def run_container_cowsay(image: DockerImage) -> None:
"""Helper for testing - runs cowsay command and verifies it works."""
# note that our `cowsay` adds moo prefix as commands are executed
Expand All @@ -39,18 +41,21 @@ def run_container_cowsay(image: DockerImage) -> None:
docker_client.images.remove(image.name)


@pytest.mark.requires("docker")
def test_build_image_from_dockerfile() -> None:
dockerfile_path = Path(__file__).parent / "docker_test_data/Dockerfile"
image = DockerImage.from_dockerfile(dockerfile_path, name="cow")
run_container_cowsay(image)


@pytest.mark.requires("docker")
def test_build_image_from_dockerfile_dirpath() -> None:
dockerfile_dir = Path(__file__).parent / "docker_test_data/"
image = DockerImage.from_dockerfile(dockerfile_dir)
run_container_cowsay(image)


@pytest.mark.requires("docker")
def test_docker_spawn_run_works() -> None:
container = DockerContainer(DockerImage.from_tag("alpine"))
status_code, logs = container.spawn_run(["echo", "hello", "world"])
Expand All @@ -62,13 +67,15 @@ def test_docker_spawn_run_works() -> None:
assert logs.find(b"good bye") >= 0


@pytest.mark.requires("docker")
def test_docker_spawn_run_return_nonzero_status_code() -> None:
container = DockerContainer(DockerImage.from_tag("alpine"))
status_code, logs = container.spawn_run("sh -c 'echo hey && exit 1'")
assert status_code == 1
assert logs.find(b"hey") >= 0


@pytest.mark.requires("docker")
def test_docker_container_background_run_works() -> None:
client = get_docker_client()
container_name: str
Expand Down

0 comments on commit 77f0b5b

Please sign in to comment.