mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00
Refactor python tests to run against python3.9
* Introduce sub-package compat to meet packaging and import requirements * Update documenation for running tests * Add requirements.txt to improve IDE support Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
0
test/python/__init__.py
Normal file
0
test/python/__init__.py
Normal file
@ -8,7 +8,7 @@ import tempfile
|
||||
|
||||
from docker import DockerClient
|
||||
|
||||
from test.python.docker import constant
|
||||
from .compat import constant
|
||||
|
||||
|
||||
class Podman(object):
|
||||
@ -39,7 +39,9 @@ class Podman(object):
|
||||
self.cmd.append("--root=" + os.path.join(self.anchor_directory, "crio"))
|
||||
self.cmd.append("--runroot=" + os.path.join(self.anchor_directory, "crio-run"))
|
||||
|
||||
os.environ["REGISTRIES_CONFIG_PATH"] = os.path.join(self.anchor_directory, "registry.conf")
|
||||
os.environ["REGISTRIES_CONFIG_PATH"] = os.path.join(
|
||||
self.anchor_directory, "registry.conf"
|
||||
)
|
||||
p = configparser.ConfigParser()
|
||||
p.read_dict(
|
||||
{
|
||||
@ -51,10 +53,14 @@ class Podman(object):
|
||||
with open(os.environ["REGISTRIES_CONFIG_PATH"], "w") as w:
|
||||
p.write(w)
|
||||
|
||||
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("--cni-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(
|
||||
"""
|
||||
|
@ -13,26 +13,26 @@ To run the tests locally in your sandbox (Fedora 32,33):
|
||||
|
||||
### Run the entire test suite
|
||||
|
||||
All commands are run from the root of the repository.
|
||||
|
||||
```shell
|
||||
# python3 -m unittest discover test/python/docker
|
||||
# python3 -m unittest discover -s test/python/docker
|
||||
```
|
||||
|
||||
Passing the -v option to your test script will instruct unittest.main() to enable a higher level of verbosity, and produce detailed output:
|
||||
|
||||
```shell
|
||||
# python3 -m unittest -v discover test/python/docker
|
||||
# python3 -m unittest -v discover -s test/python/docker
|
||||
```
|
||||
|
||||
### Run a specific test class
|
||||
|
||||
```shell
|
||||
# cd test/python/docker
|
||||
# python3 -m unittest -v tests.test_images
|
||||
# python3 -m unittest -v test.python.docker.compat.test_images.TestImages
|
||||
```
|
||||
|
||||
### Run a specific test within the test class
|
||||
|
||||
```shell
|
||||
# cd test/python/docker
|
||||
# python3 -m unittest tests.test_images.TestImages.test_import_image
|
||||
# python3 -m unittest test.python.docker.compat.test_images.TestImages.test_tag_valid_image
|
||||
```
|
0
test/python/docker/compat/__init__.py
Normal file
0
test/python/docker/compat/__init__.py
Normal file
@ -1,10 +1,12 @@
|
||||
from docker import DockerClient
|
||||
|
||||
from test.python.docker import constant
|
||||
from test.python.docker.compat import constant
|
||||
|
||||
|
||||
def run_top_container(client: DockerClient):
|
||||
c = client.containers.create(constant.ALPINE, command="top", detach=True, tty=True, name="top")
|
||||
c = client.containers.create(
|
||||
constant.ALPINE, command="top", detach=True, tty=True, name="top"
|
||||
)
|
||||
c.start()
|
||||
return c.id
|
||||
|
@ -5,7 +5,8 @@ import unittest
|
||||
|
||||
from docker import DockerClient, errors
|
||||
|
||||
from test.python.docker import Podman, common, constant
|
||||
from test.python.docker import Podman
|
||||
from test.python.docker.compat import common, constant
|
||||
|
||||
|
||||
class TestContainers(unittest.TestCase):
|
||||
@ -87,9 +88,11 @@ class TestContainers(unittest.TestCase):
|
||||
self.assertEqual(len(containers), 2)
|
||||
|
||||
def test_start_container_with_random_port_bind(self):
|
||||
container = self.client.containers.create(image=constant.ALPINE,
|
||||
name="containerWithRandomBind",
|
||||
ports={'1234/tcp': None})
|
||||
container = self.client.containers.create(
|
||||
image=constant.ALPINE,
|
||||
name="containerWithRandomBind",
|
||||
ports={"1234/tcp": None},
|
||||
)
|
||||
containers = self.client.containers.list(all=True)
|
||||
self.assertTrue(container in containers)
|
||||
|
@ -7,7 +7,8 @@ import unittest
|
||||
|
||||
from docker import DockerClient, errors
|
||||
|
||||
from test.python.docker import Podman, common, constant
|
||||
from test.python.docker import Podman
|
||||
from test.python.docker.compat import common, constant
|
||||
|
||||
|
||||
class TestImages(unittest.TestCase):
|
||||
@ -78,7 +79,9 @@ class TestImages(unittest.TestCase):
|
||||
self.assertEqual(len(self.client.images.list()), 2)
|
||||
|
||||
# List images with filter
|
||||
self.assertEqual(len(self.client.images.list(filters={"reference": "alpine"})), 1)
|
||||
self.assertEqual(
|
||||
len(self.client.images.list(filters={"reference": "alpine"})), 1
|
||||
)
|
||||
|
||||
def test_search_image(self):
|
||||
"""Search for image"""
|
||||
@ -91,7 +94,7 @@ class TestImages(unittest.TestCase):
|
||||
r = self.client.images.search("bogus/bogus")
|
||||
except:
|
||||
return
|
||||
self.assertTrue(len(r)==0)
|
||||
self.assertTrue(len(r) == 0)
|
||||
|
||||
def test_remove_image(self):
|
||||
"""Remove image"""
|
@ -5,7 +5,8 @@ import unittest
|
||||
|
||||
from docker import DockerClient
|
||||
|
||||
from test.python.docker import Podman, common, constant
|
||||
from test.python.docker import Podman, constant
|
||||
from test.python.docker.compat import common
|
||||
|
||||
|
||||
class TestSystem(unittest.TestCase):
|
6
test/python/requirements.txt
Normal file
6
test/python/requirements.txt
Normal file
@ -0,0 +1,6 @@
|
||||
docker~=4.4.3
|
||||
|
||||
requests~=2.20.0
|
||||
setuptools~=50.3.2
|
||||
python-dateutil~=2.8.1
|
||||
PyYAML~=5.4.1
|
Reference in New Issue
Block a user