Skip to content

Commit 6521958

Browse files
committed
fix tests
1 parent 92949ac commit 6521958

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

podman_compose.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,17 +2058,17 @@ def resolve_pod_name(self) -> str | None:
20582058
# - docker-compose.yml x-podman.in_pod
20592059
# - Default value of true
20602060
in_pod_arg = self.global_args.in_pod or self.x_podman.get(
2061-
PodmanCompose.XPodmanSettingKey.IN_POD, True)
2061+
PodmanCompose.XPodmanSettingKey.IN_POD, True
2062+
)
20622063

20632064
in_pod_arg_parsed = try_parse_bool(in_pod_arg)
20642065
if in_pod_arg_parsed is True:
20652066
return f"pod_{self.project_name}"
2066-
elif in_pod_arg_parsed is False:
2067+
if in_pod_arg_parsed is False:
20672068
return None
2068-
else:
2069-
# Arg is a non-emty string that does not parse to a boolean,
2070-
# so we treat it as a pod name.
2071-
return in_pod_arg
2069+
# Arg is a non-emty string that does not parse to a boolean,
2070+
# so we treat it as a pod name.
2071+
return in_pod_arg
20722072

20732073
def resolve_pod_args(self) -> list[str]:
20742074
# Priorities:
@@ -2087,10 +2087,10 @@ def join_name_parts(self, *parts: str) -> str:
20872087
sep = "-"
20882088
else:
20892089
sep = "_"
2090-
20912090
return sep.join(parts)
20922091

20932092
def format_name(self, *parts: str) -> str:
2093+
assert self.project_name is not None
20942094
return self.join_name_parts(self.project_name, *parts)
20952095

20962096
def _parse_x_podman_settings(self, compose: dict[str, Any], environ: dict[str, str]) -> None:
@@ -2942,15 +2942,15 @@ async def pod_exists(compose: PodmanCompose, name: str) -> bool:
29422942
return exit_code == 0
29432943

29442944

2945-
async def create_pods(compose: PodmanCompose, args: argparse.Namespace) -> None:
2945+
async def create_pods(compose: PodmanCompose) -> None:
29462946
for pod in compose.pods:
29472947
if await pod_exists(compose, pod["name"]):
29482948
continue
29492949

29502950
podman_args = [
29512951
"create",
29522952
"--name=" + pod["name"],
2953-
]+ compose.resolve_pod_args()
2953+
] + compose.resolve_pod_args()
29542954

29552955
ports = pod.get("ports", [])
29562956
if isinstance(ports, str):
@@ -3084,7 +3084,7 @@ async def compose_up(compose: PodmanCompose, args: argparse.Namespace) -> int |
30843084
log.info("recreating: done\n\n")
30853085
# args.no_recreate disables check for changes (which is not implemented)
30863086

3087-
await create_pods(compose, args)
3087+
await create_pods(compose)
30883088
exit_code = 0
30893089
for cnt in compose.containers:
30903090
if cnt["_service"] in excluded:
@@ -3328,7 +3328,7 @@ async def compose_ps(compose: PodmanCompose, args: argparse.Namespace) -> None:
33283328
"create a container similar to a service to run a one-off command",
33293329
)
33303330
async def compose_run(compose: PodmanCompose, args: argparse.Namespace) -> None:
3331-
await create_pods(compose, args)
3331+
await create_pods(compose)
33323332
compose.assert_services(args.service)
33333333
container_names = compose.container_names_by_service[args.service]
33343334
container_name = container_names[0]
@@ -3373,7 +3373,7 @@ def compose_run_update_container_from_args(
33733373
compose: PodmanCompose, cnt: dict, args: argparse.Namespace
33743374
) -> None:
33753375
# adjust one-off container options
3376-
name0 = compose.format_name(args.service, str(random.randrange(0, 65536)))
3376+
name0 = compose.format_name(args.service, f'tmp{random.randrange(0, 65536)}')
33773377
cnt["name"] = args.name or name0
33783378
if args.entrypoint:
33793379
cnt["entrypoint"] = args.entrypoint

tests/integration/name_separator_compat/test_podman_compose_name_separator_compat.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212

1313
class TestComposeNameSeparatorCompat(unittest.TestCase, RunSubprocessMixin):
1414
@parameterized.expand([
15-
('default', { }, '_'),
16-
('default', { 'PODMAN_COMPOSE_NAME_SEPARATOR_COMPAT': '1' }, '-'),
17-
('compat', { }, '-'),
18-
('compat', { 'PODMAN_COMPOSE_NAME_SEPARATOR_COMPAT': '1' }, '-'),
19-
('compat', { 'PODMAN_COMPOSE_NAME_SEPARATOR_COMPAT': '0' }, '_'),
15+
('default', {}, '_'),
16+
('default', {'PODMAN_COMPOSE_NAME_SEPARATOR_COMPAT': '1'}, '-'),
17+
('compat', {}, '-'),
18+
('compat', {'PODMAN_COMPOSE_NAME_SEPARATOR_COMPAT': '1'}, '-'),
19+
('compat', {'PODMAN_COMPOSE_NAME_SEPARATOR_COMPAT': '0'}, '_'),
2020
])
2121
def test_container_name(self, file: str, env: dict[str, str], expected_sep: str) -> None:
2222
compose_yaml_path = os.path.join(
23-
test_path(),
24-
"name_separator_compat",
25-
f"docker-compose_{file}.yaml")
23+
test_path(), "name_separator_compat", f"docker-compose_{file}.yaml"
24+
)
2625

2726
try:
2827
self.run_subprocess_assert_returncode(
@@ -47,11 +46,14 @@ def test_container_name(self, file: str, env: dict[str, str], expected_sep: str)
4746

4847
self.assertEqual(container_name, expected_container_name)
4948
finally:
50-
self.run_subprocess_assert_returncode([
51-
podman_compose_path(),
52-
"-f",
53-
compose_yaml_path,
54-
"down",
55-
"-t",
56-
"0",
57-
], env=env)
49+
self.run_subprocess_assert_returncode(
50+
[
51+
podman_compose_path(),
52+
"-f",
53+
compose_yaml_path,
54+
"down",
55+
"-t",
56+
"0",
57+
],
58+
env=env,
59+
)

tests/unit/test_compose_run_update_container_from_args.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def get_minimal_container() -> dict:
5656

5757

5858
def get_minimal_compose() -> PodmanCompose:
59-
return PodmanCompose()
59+
compose = PodmanCompose()
60+
compose.project_name = "test_project"
61+
return compose
6062

6163

6264
def get_minimal_args() -> argparse.Namespace:
@@ -67,7 +69,7 @@ def get_minimal_args() -> argparse.Namespace:
6769
env=None,
6870
name="default_name",
6971
rm=None,
70-
service=None,
72+
service="test_service",
7173
publish=None,
7274
service_ports=None,
7375
user=None,

tests/unit/test_container_to_args.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def create_compose_mock(project_name: str = "test_project_name") -> PodmanCompos
2020
compose.default_net = None
2121
compose.networks = {}
2222
compose.x_podman = {}
23+
compose.join_name_parts = mock.Mock(side_effect=lambda *args: '_'.join(args))
24+
compose.format_name = mock.Mock(side_effect=lambda *args: '_'.join([project_name, *args]))
2325

2426
async def podman_output(*args: Any, **kwargs: Any) -> None:
2527
pass

0 commit comments

Comments
 (0)