From 7729afe9793632673c978b347ccbd999b5152042 Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Mon, 28 Feb 2022 16:26:43 -0700 Subject: Refactor docker-py compatibility tests * Add which python client is being used to run tests, see "python client" below. * Remove redundate code from test classes * Update/Add comments to modules and classes ======================================================= test session starts ======================================================== platform linux -- Python 3.10.0, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 python client -- DockerClient rootdir: /home/jhonce/Projects/go/src/github.com/containers/podman plugins: requests-mock-1.8.0 collected 33 items test/python/docker/compat/test_containers.py ...s.............. [ 54%] test/python/docker/compat/test_images.py ............ [ 90%] test/python/docker/compat/test_system.py ... [100%] Note: Follow-up PRs will verify the test results and expand the tests. Signed-off-by: Jhon Honce --- test/python/docker/__init__.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'test/python/docker/__init__.py') diff --git a/test/python/docker/__init__.py b/test/python/docker/__init__.py index 816667b82..d46f465f7 100644 --- a/test/python/docker/__init__.py +++ b/test/python/docker/__init__.py @@ -1,4 +1,6 @@ -import configparser +""" +Helpers for integration tests using DockerClient +""" import json import os import pathlib @@ -11,7 +13,7 @@ from docker import DockerClient from .compat import constant -class Podman(object): +class PodmanAPI: """ Instances hold the configuration and setup for running podman commands """ @@ -53,17 +55,13 @@ location = "mirror.localhost:5000" """ - with open(os.environ["CONTAINERS_REGISTRIES_CONF"], "w") as w: - w.write(conf) + with open(os.environ["CONTAINERS_REGISTRIES_CONF"], "w") as file: + file.write(conf) - os.environ["CNI_CONFIG_PATH"] = os.path.join( - self.anchor_directory, "cni", "net.d" - ) + os.environ["CNI_CONFIG_PATH"] = os.path.join(self.anchor_directory, "cni", "net.d") os.makedirs(os.environ["CNI_CONFIG_PATH"], exist_ok=True) self.cmd.append("--network-config-dir=" + os.environ["CNI_CONFIG_PATH"]) - cni_cfg = os.path.join( - os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist" - ) + cni_cfg = os.path.join(os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist") # json decoded and encoded to ensure legal json buf = json.loads( """ @@ -93,8 +91,8 @@ location = "mirror.localhost:5000" } """ ) - with open(cni_cfg, "w") as w: - json.dump(buf, w) + with open(cni_cfg, "w") as file: + json.dump(buf, file) def open(self, command, *args, **kwargs): """Podman initialized instance to run a given command @@ -111,6 +109,7 @@ location = "mirror.localhost:5000" shell = kwargs.get("shell", False) + # pylint: disable=consider-using-with return subprocess.Popen( cmd, shell=shell, @@ -144,9 +143,11 @@ location = "mirror.localhost:5000" ) def tear_down(self): + """Delete test environment.""" shutil.rmtree(self.anchor_directory, ignore_errors=True) def restore_image_from_cache(self, client: DockerClient): + """Populate images from cache.""" path = os.path.join(self.image_cache, constant.ALPINE_TARBALL) if not os.path.exists(path): img = client.images.pull(constant.ALPINE) @@ -157,5 +158,6 @@ location = "mirror.localhost:5000" self.run("load", "-i", path, check=True) def flush_image_cache(self): - for f in pathlib.Path(self.image_cache).glob("*.tar"): - f.unlink(f) + """Delete image cache.""" + for file in pathlib.Path(self.image_cache).glob("*.tar"): + file.unlink(missing_ok=True) -- cgit v1.2.3-54-g00ecf