diff --git a/pytest_container/inspect.py b/pytest_container/inspect.py index 2eed592..8b9d208 100644 --- a/pytest_container/inspect.py +++ b/pytest_container/inspect.py @@ -7,6 +7,7 @@ from dataclasses import dataclass from dataclasses import field from datetime import timedelta +from pathlib import Path from typing import Dict from typing import List from typing import Optional @@ -232,7 +233,7 @@ class Config: stop_signal: Union[int, str] #: The working directory of the container - workingdir: str + workingdir: Path #: optional healthcheck defined for the underlying container image healthcheck: Optional[HealthCheck] = None diff --git a/pytest_container/runtime.py b/pytest_container/runtime.py index 517f712..dd55a01 100644 --- a/pytest_container/runtime.py +++ b/pytest_container/runtime.py @@ -11,6 +11,7 @@ from dataclasses import dataclass from dataclasses import field from os import getenv +from pathlib import Path from subprocess import check_output from typing import Any from typing import Callable @@ -522,7 +523,7 @@ def inspect_container(self, container_id: str) -> ContainerInspect: image=config["Image"], entrypoint=entrypoint, labels=config["Labels"], - workingdir=config["WorkingDir"], + workingdir=Path(config["WorkingDir"]), env=dict([env.split("=", maxsplit=1) for env in config["Env"]]), stop_signal=self._stop_signal_from_inspect_conf(config), healthcheck=healthcheck, @@ -609,7 +610,7 @@ def inspect_container(self, container_id: str) -> ContainerInspect: labels=config["Labels"], # docker sometimes omits the working directory, # then it defaults to - workingdir=config["WorkingDir"] or "/", + workingdir=Path(config["WorkingDir"] or "/"), stop_signal=self._stop_signal_from_inspect_conf(config), env=env, healthcheck=healthcheck, diff --git a/tests/test_container_build.py b/tests/test_container_build.py index 1632e59..1c7a4f1 100644 --- a/tests/test_container_build.py +++ b/tests/test_container_build.py @@ -194,7 +194,7 @@ def test_auto_container_fixture(auto_container: ContainerData): "container", [BUSYBOX_WITH_ENTRYPOINT], indirect=["container"] ) def test_custom_entry_point(container: ContainerData): - container.connection.run_expect([0], "true") + container.connection.check_output("true") @pytest.mark.parametrize( @@ -209,7 +209,7 @@ def test_default_entry_point(container: ContainerData): @pytest.mark.parametrize("container", [CONTAINER_THAT_STOPS], indirect=True) def test_container_that_stops(container: ContainerData) -> None: # it should just be alive - container.connection.run_expect([0], "true") + container.connection.check_output("true") def test_container_size( @@ -280,10 +280,9 @@ def test_multistage_build_target( extra_build_args=get_extra_build_args(pytestconfig), ) assert ( - LOCALHOST.run_expect( - [0], + LOCALHOST.check_output( f"{container_runtime.runner_binary} run --rm {first_target}", - ).stdout.strip() + ).strip() == "foobar" ) @@ -297,10 +296,9 @@ def test_multistage_build_target( assert first_target != second_target assert ( - LOCALHOST.run_expect( - [0], + LOCALHOST.check_output( f"{container_runtime.runner_binary} run --rm {second_target} /bin/test.sh", - ).stdout.strip() + ).strip() == "foobar" ) @@ -310,11 +308,10 @@ def test_multistage_build_target( ): assert ( distro - in LOCALHOST.run_expect( - [0], + in LOCALHOST.check_output( f"{container_runtime.runner_binary} run --rm --entrypoint= {target} " "cat /etc/os-release", - ).stdout.strip() + ).strip() ) diff --git a/tests/test_inspect.py b/tests/test_inspect.py index 93aae6e..321f219 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -1,5 +1,6 @@ # pylint: disable=missing-function-docstring,missing-module-docstring,line-too-long import json +from pathlib import Path from typing import List import pytest @@ -67,7 +68,7 @@ def test_inspect( assert inspect.config.image == expected_img assert inspect.config.cmd == ["/bin/sh"] - assert inspect.config.workingdir == "/foobar/" + assert Path("/foobar/") == inspect.config.workingdir assert ( not inspect.state.paused @@ -94,7 +95,7 @@ def test_inspect_unset_workdir(container: ContainerData) -> None: docker sometimes omits the workingdir setting. """ - assert container.inspect.config.workingdir == "/" + assert container.inspect.config.workingdir == Path("/") @pytest.mark.parametrize(