Skip to content

Commit

Permalink
Merge pull request #220 from dcermak/workingdir-to-Path
Browse files Browse the repository at this point in the history
convert Config.workingdir property to pathlib.Path
  • Loading branch information
dcermak authored Aug 19, 2024
2 parents 659cee0 + 33e0477 commit 3216b4e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
3 changes: 2 additions & 1 deletion pytest_container/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pytest_container/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 8 additions & 11 deletions tests/test_container_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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"
)

Expand All @@ -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"
)

Expand All @@ -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()
)


Expand Down
5 changes: 3 additions & 2 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 3216b4e

Please sign in to comment.