Debian Codegraph @

tests/unit/test_include.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2 # pylint: disable=protected-access
3 from __future__ import annotations
4
5 import argparse
6 import os
7 import unittest
8 from typing import Any
9
10 import yaml
11
12 from podman_compose import PodmanCompose
13
14
15 class TestIncludeDict(unittest.TestCase):
16 def setUp(self) -> None:
17 self.test_files: list[str] = []
18
19 def tearDown(self) -> None:
20 for f in self.test_files:
21 if os.path.exists(f):
22 os.remove(f)
23
24 def write_yaml(self, name: str, content: dict[str, Any]) -> None:
25 with open(name, "w", encoding="utf-8") as f:
26 yaml.safe_dump(content, f)
27 self.test_files.append(name)
28
29 def test_parse_compose_file_with_include_dict(self) -> None:
30 # 1. Create a base compose file to be included
31 include_content = {"services": {"base_web": {"image": "nginx:alpine"}}}
32 self.write_yaml("test-compose-include.yaml", include_content)
33
34 # 2. Create a main compose file with include detailed format (dictionary)
35 main_content = {
36 "version": "3.8",
37 "include": [{"path": "./test-compose-include.yaml"}],
38 "services": {"web": {"image": "alpine:latest"}},
39 }
40 self.write_yaml("test-compose-main.yaml", main_content)
41
42 podman_compose = PodmanCompose()
43 podman_compose.global_args = argparse.Namespace()
44 podman_compose.global_args.file = ["test-compose-main.yaml"]
45 podman_compose.global_args.project_name = "test_project"
46 podman_compose.global_args.env_file = None
47 podman_compose.global_args.profile = []
48 podman_compose.global_args.in_pod = "false"
49 podman_compose.global_args.pod_args = None
50 podman_compose.global_args.no_normalize = True
51
52 # It should run successfully without raising a TypeError
53 podman_compose._parse_compose_file()
54
55 self.assertIn("web", podman_compose.services)
56 self.assertIn("base_web", podman_compose.services)