tests/integration: Reduce base path calculation duplication

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
This commit is contained in:
Monika Kairaityte 2024-07-03 07:50:52 +03:00
parent 137c6207b2
commit 2056e703d5

View File

@ -2,14 +2,13 @@
import os import os
import unittest import unittest
from pathlib import Path
from .test_utils import RunSubprocessMixin from .test_utils import RunSubprocessMixin
def base_path(): def base_path():
"""Returns the base path for the project""" """Returns the base path for the project"""
return Path(__file__).parent.parent.parent return os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
def test_path(): def test_path():
@ -33,16 +32,17 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose will not create a pod, when x-podman in_pod=false and command line Test that podman-compose will not create a pod, when x-podman in_pod=false and command line
does not provide this option does not provide this option
""" """
main_path = Path(__file__).parent.parent.parent
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_false", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_false",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -52,10 +52,13 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
"python3", "python3",
podman_compose_path(), podman_compose_path(),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_false", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_false",
"docker-compose.yml",
), ),
"down", "down",
] ]
@ -74,18 +77,19 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose does not allow pod creating even with command line in_pod=True Test that podman-compose does not allow pod creating even with command line in_pod=True
when --userns and --pod are set together: throws an error when --userns and --pod are set together: throws an error
""" """
main_path = Path(__file__).parent.parent.parent
# FIXME: creates a pod anyway, although it should not # FIXME: creates a pod anyway, although it should not
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=True", "--in-pod=True",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_false", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_false",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -105,17 +109,18 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
""" """
Test that podman-compose will not create a pod as command line sets in_pod=False Test that podman-compose will not create a pod as command line sets in_pod=False
""" """
main_path = Path(__file__).parent.parent.parent
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=False", "--in-pod=False",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_false", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_false",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -125,10 +130,13 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
"python3", "python3",
podman_compose_path(), podman_compose_path(),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_false", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_false",
"docker-compose.yml",
), ),
"down", "down",
] ]
@ -147,17 +155,18 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose will not create a pod, when x-podman in_pod=false and command line Test that podman-compose will not create a pod, when x-podman in_pod=false and command line
command line in_pod="" command line in_pod=""
""" """
main_path = Path(__file__).parent.parent.parent
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=", "--in-pod=",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_false", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_false",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -167,10 +176,13 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
"python3", "python3",
podman_compose_path(), podman_compose_path(),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_false", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_false",
"docker-compose.yml",
), ),
"down", "down",
] ]
@ -190,18 +202,19 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose does not allow pod creating when --userns and --pod are set Test that podman-compose does not allow pod creating when --userns and --pod are set
together even when x-podman in_pod=true: throws an error together even when x-podman in_pod=true: throws an error
""" """
main_path = Path(__file__).parent.parent.parent
# FIXME: creates a pod anyway, although it should not # FIXME: creates a pod anyway, although it should not
# Container is not created, so command 'down' is not needed # Container is not created, so command 'down' is not needed
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_true", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_true",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -222,19 +235,20 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose does not allow pod creating when --userns and --pod are set Test that podman-compose does not allow pod creating when --userns and --pod are set
together even when x-podman in_pod=true and and command line in_pod=True: throws an error together even when x-podman in_pod=true and and command line in_pod=True: throws an error
""" """
main_path = Path(__file__).parent.parent.parent
# FIXME: creates a pod anyway, although it should not # FIXME: creates a pod anyway, although it should not
# Container is not created, so command 'down' is not needed # Container is not created, so command 'down' is not needed
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=True", "--in-pod=True",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_true", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_true",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -254,17 +268,18 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
""" """
Test that podman-compose will not create a pod as command line sets in_pod=False Test that podman-compose will not create a pod as command line sets in_pod=False
""" """
main_path = Path(__file__).parent.parent.parent
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=False", "--in-pod=False",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_true", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_true",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -274,10 +289,13 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
"python3", "python3",
podman_compose_path(), podman_compose_path(),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_true", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_true",
"docker-compose.yml",
), ),
"down", "down",
] ]
@ -296,19 +314,20 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose does not allow pod creating when --userns and --pod are set Test that podman-compose does not allow pod creating when --userns and --pod are set
together even when x-podman in_pod=true and command line in_pod="": throws an error together even when x-podman in_pod=true and command line in_pod="": throws an error
""" """
main_path = Path(__file__).parent.parent.parent
# FIXME: creates a pod anyway, although it should not # FIXME: creates a pod anyway, although it should not
# Container is not created, so command 'down' is not needed # Container is not created, so command 'down' is not needed
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=", "--in-pod=",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "integration", "in_pod", "custom_x-podman_true", "docker-compose.yml" "tests",
) "integration",
"in_pod",
"custom_x-podman_true",
"docker-compose.yml",
), ),
"up", "up",
"-d", "-d",
@ -330,22 +349,19 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose does not allow pod creating when --userns and --pod are set Test that podman-compose does not allow pod creating when --userns and --pod are set
together: throws an error together: throws an error
""" """
main_path = Path(__file__).parent.parent.parent
# FIXME: creates a pod anyway, although it should not # FIXME: creates a pod anyway, although it should not
# Container is not created, so command 'down' is not needed # Container is not created, so command 'down' is not needed
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "tests",
"integration", "integration",
"in_pod", "in_pod",
"custom_x-podman_not_exists", "custom_x-podman_not_exists",
"docker-compose.yml", "docker-compose.yml",
)
), ),
"up", "up",
"-d", "-d",
@ -366,23 +382,20 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose does not allow pod creating when --userns and --pod are set Test that podman-compose does not allow pod creating when --userns and --pod are set
together even when x-podman in_pod=true: throws an error together even when x-podman in_pod=true: throws an error
""" """
main_path = Path(__file__).parent.parent.parent
# FIXME: creates a pod anyway, although it should not # FIXME: creates a pod anyway, although it should not
# Container was not created, so command 'down' is not needed # Container was not created, so command 'down' is not needed
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=True", "--in-pod=True",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "tests",
"integration", "integration",
"in_pod", "in_pod",
"custom_x-podman_not_exists", "custom_x-podman_not_exists",
"docker-compose.yml", "docker-compose.yml",
)
), ),
"up", "up",
"-d", "-d",
@ -402,21 +415,18 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
""" """
Test that podman-compose will not create a pod as command line sets in_pod=False Test that podman-compose will not create a pod as command line sets in_pod=False
""" """
main_path = Path(__file__).parent.parent.parent
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=False", "--in-pod=False",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "tests",
"integration", "integration",
"in_pod", "in_pod",
"custom_x-podman_not_exists", "custom_x-podman_not_exists",
"docker-compose.yml", "docker-compose.yml",
)
), ),
"up", "up",
"-d", "-d",
@ -426,14 +436,13 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
"python3", "python3",
podman_compose_path(), podman_compose_path(),
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "tests",
"integration", "integration",
"in_pod", "in_pod",
"custom_x-podman_not_exists", "custom_x-podman_not_exists",
"docker-compose.yml", "docker-compose.yml",
)
), ),
"down", "down",
] ]
@ -453,23 +462,20 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose does not allow pod creating when --userns and --pod are set Test that podman-compose does not allow pod creating when --userns and --pod are set
together: throws an error together: throws an error
""" """
main_path = Path(__file__).parent.parent.parent
# FIXME: creates a pod anyway, although it should not # FIXME: creates a pod anyway, although it should not
# Container was not created, so command 'down' is not needed # Container was not created, so command 'down' is not needed
command_up = [ command_up = [
"python3", "python3",
str(main_path.joinpath("podman_compose.py")), os.path.join(base_path(), "podman_compose.py"),
"--in-pod=", "--in-pod=",
"-f", "-f",
str( os.path.join(
main_path.joinpath( base_path(),
"tests", "tests",
"integration", "integration",
"in_pod", "in_pod",
"custom_x-podman_not_exists", "custom_x-podman_not_exists",
"docker-compose.yml", "docker-compose.yml",
)
), ),
"up", "up",
"-d", "-d",