Skip to content

Commit

Permalink
Convert Config.workingdir from str to pathlib.Path
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Aug 16, 2024
1 parent 4d8ff25 commit 1485aca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 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
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 1485aca

Please sign in to comment.