From 61b5cfffb94c889f01e169a1d74d10c6d6d17f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 16 Aug 2024 17:44:56 +0200 Subject: [PATCH] Convert Config.workingdir from str to pathlib.Path --- pytest_container/inspect.py | 3 ++- pytest_container/runtime.py | 5 +++-- tests/test_inspect.py | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) 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_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(