Skip to content

Commit

Permalink
Merge pull request #235 from dcermak/use-removeprefix
Browse files Browse the repository at this point in the history
Use partion & add python 3.13
  • Loading branch information
dcermak authored Nov 8, 2024
2 parents b2d4c22 + 52e7615 commit 7d7ad34
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 28 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
container_runtime: ["podman", "docker"]
update_runtime: [ true, false ]
without_buildah: [ false ]
Expand Down Expand Up @@ -137,13 +137,17 @@ jobs:
python_version: "3.12"
update_runtime: true
without_buildah: false
- container_runtime: "docker"
python_version: "3.13"
update_runtime: true
without_buildah: false

include:
- python_version: "3.12"
- python_version: "3.13"
container_runtime: "podman"
update_runtime: true
without_buildah: true
- python_version: "3.12"
- python_version: "3.13"
container_runtime: "podman"
update_runtime: false
without_buildah: true
Expand Down Expand Up @@ -243,7 +247,7 @@ jobs:
fail-fast: false
matrix:
os_version: ["ubuntu-latest"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os_version: "ubuntu-20.04"
python_version: "3.6"
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from nox_poetry import session


@session(python=["3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"])
@session(python=["3.13", "3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"])
@nox.parametrize(
"container_runtime",
[nox.param(runtime, id=runtime) for runtime in ("podman", "docker")],
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing"
]
Expand Down
44 changes: 24 additions & 20 deletions pytest_container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
images or software in container images with pytest.
"""
from .build import GitRepositoryBuild
from .build import MultiStageBuild
from .container import BindMount
from .container import Container
from .container import container_and_marks_from_pytest_param
from .container import container_from_pytest_param
from .container import container_to_pytest_param
from .container import ContainerVolume
from .container import DerivedContainer
from .helpers import add_extra_run_and_build_args_options
from .helpers import add_logging_level_options
from .helpers import auto_container_parametrize
from .helpers import get_extra_build_args
from .helpers import get_extra_run_args
from .helpers import set_logging_level_from_cli_args
from .inspect import PortForwarding
from .runtime import DockerRuntime
from .runtime import get_selected_runtime
from .runtime import OciRuntimeBase
from .runtime import PodmanRuntime
from .runtime import Version

__all__ = [
"GitRepositoryBuild",
"MultiStageBuild",
Expand All @@ -22,24 +44,6 @@
"OciRuntimeBase",
"PodmanRuntime",
"Version",
"ContainerVolume",
"BindMount",
]

from .build import GitRepositoryBuild
from .build import MultiStageBuild
from .container import Container
from .container import container_and_marks_from_pytest_param
from .container import container_from_pytest_param
from .container import container_to_pytest_param
from .container import DerivedContainer
from .helpers import add_extra_run_and_build_args_options
from .helpers import add_logging_level_options
from .helpers import auto_container_parametrize
from .helpers import get_extra_build_args
from .helpers import get_extra_run_args
from .helpers import set_logging_level_from_cli_args
from .inspect import PortForwarding
from .runtime import DockerRuntime
from .runtime import get_selected_runtime
from .runtime import OciRuntimeBase
from .runtime import PodmanRuntime
from .runtime import Version
7 changes: 5 additions & 2 deletions pytest_container/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,12 @@ class ContainerBase:
_is_local: bool = False

def __post_init__(self) -> None:
if self.url.split(":", maxsplit=1)[0] == "containers-storage":
local_prefix = "containers-storage:"
if self.url.startswith(local_prefix):
self._is_local = True
self.url = self.url.replace("containers-storage:", "")
# returns before_separator, separator, after_separator
before, sep, self.url = self.url.partition(local_prefix)
assert before == "" and sep == local_prefix

def __str__(self) -> str:
return self.url or self.container_id
Expand Down
3 changes: 2 additions & 1 deletion source/prerequisites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ the `dataclasses <https://pypi.org/project/dataclasses/>`_ module.
Tests leveraging `pytest_container` need to have access to a container
runtime. Currently the following ones are supported:

- `podman <https://podman.io/>`_ and `buildah <https://buildah.io/>`_
- `podman <https://podman.io/>`_ and `buildah <https://buildah.io/>`_ (buildah
is optional and if missing, podman is leveraged for building container images)
- `docker <https://www.docker.com/>`_

.. _runtime selection rules:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@ def test_baseurl(
container_instance: Union[DerivedContainer, Container], url: Optional[str]
) -> None:
assert container_instance.baseurl == url


def test_url_does_not_loose_containers_storage_part():
local_prefix = "containers-storage"
path = f"this/is/a/fake/image/with/{local_prefix}:latest"
ctr = Container(url=f"{local_prefix}:{path}")
assert ctr.local_image
assert ctr.url == path

0 comments on commit 7d7ad34

Please sign in to comment.