33import argparse
44import copy
55import os
6- from pathlib import Path
76import yaml
87from podman_compose import (
98 normalize_service ,
1312 PodmanCompose ,
1413)
1514
16-
15+ cwd = os . path . abspath ( "." )
1716test_cases_simple_normalization = [
1817 ({"image" : "test-image" }, {"image" : "test-image" }),
1918 (
2019 {"build" : "." },
2120 {
22- "build" : {"context" : str ( Path . cwd ()) , "dockerfile" : "Dockerfile" },
21+ "build" : {"context" : cwd , "dockerfile" : "Dockerfile" },
2322 },
2423 ),
2524 (
2625 {"build" : "../relative" },
2726 {
2827 "build" : {
29- "context" : str (( Path . cwd () / "../relative" ). resolve ( )),
28+ "context" : os . path . normpath ( os . path . join ( cwd , "../relative" )),
3029 "dockerfile" : "Dockerfile" ,
3130 },
3231 },
3534 {"build" : "./relative" },
3635 {
3736 "build" : {
38- "context" : str (( Path . cwd () / "./relative" ). resolve ( )),
37+ "context" : os . path . normpath ( os . path . join ( cwd , "./relative" )),
3938 "dockerfile" : "Dockerfile" ,
4039 },
4140 },
5756 },
5857 {
5958 "build" : {
60- "context" : str ( Path . cwd ()) ,
59+ "context" : cwd ,
6160 "dockerfile" : "Dockerfile" ,
6261 },
6362 },
7069 },
7170 {
7271 "build" : {
73- "context" : str ( Path . cwd ()) ,
72+ "context" : cwd ,
7473 "dockerfile" : "Dockerfile" ,
7574 },
7675 },
8180 },
8281 {
8382 "build" : {
84- "context" : str (( Path . cwd () / "../" ). resolve ( )),
83+ "context" : os . path . normpath ( os . path . join ( cwd , "../" )),
8584 "dockerfile" : "test-dockerfile" ,
8685 },
8786 },
9291 },
9392 {
9493 "build" : {
95- "context" : str ( Path . cwd ()) ,
94+ "context" : cwd ,
9695 "dockerfile" : "./dev/test-dockerfile" ,
9796 },
9897 },
@@ -123,14 +122,14 @@ def test_pre_merge_normalize_does_not_affect_build_section() -> None:
123122# [service.build] is normalised after merges
124123#
125124def test_normalize_service_final_returns_absolute_path_in_context () -> None :
126- project_dir = str ( Path . cwd (). resolve ())
125+ project_dir = cwd
127126 for test_input , expected_service in copy .deepcopy (test_cases_simple_normalization ):
128127 actual_service = normalize_service_final (test_input , project_dir )
129128 assert expected_service == actual_service
130129
131130
132131def test_normalize_returns_absolute_path_in_context () -> None :
133- project_dir = str ( Path . cwd (). resolve ())
132+ project_dir = cwd
134133 for test_input , expected_result in copy .deepcopy (test_cases_simple_normalization ):
135134 compose_test = {"services" : {"test-service" : test_input }}
136135 compose_expected = {"services" : {"test-service" : expected_result }}
@@ -166,19 +165,19 @@ def test__parse_compose_file_when_single_compose() -> None:
166165 (
167166 {},
168167 {"build" : "." },
169- {"build" : {"context" : str ( Path . cwd ()) , "dockerfile" : "Dockerfile" }},
168+ {"build" : {"context" : cwd , "dockerfile" : "Dockerfile" }},
170169 ),
171170 (
172171 {"build" : "." },
173172 {},
174- {"build" : {"context" : str ( Path . cwd ()) , "dockerfile" : "Dockerfile" }},
173+ {"build" : {"context" : cwd , "dockerfile" : "Dockerfile" }},
175174 ),
176175 (
177176 {"build" : "/workspace/absolute" },
178177 {"build" : "./relative" },
179178 {
180179 "build" : {
181- "context" : str (( Path . cwd () / "./relative" ). resolve ( )),
180+ "context" : os . path . normpath ( os . path . join ( cwd , "./relative" )),
182181 "dockerfile" : "Dockerfile" ,
183182 }
184183 },
@@ -196,22 +195,22 @@ def test__parse_compose_file_when_single_compose() -> None:
196195 (
197196 {"build" : {"dockerfile" : "test-dockerfile" }},
198197 {},
199- {"build" : {"context" : str ( Path . cwd ()) , "dockerfile" : "test-dockerfile" }},
198+ {"build" : {"context" : cwd , "dockerfile" : "test-dockerfile" }},
200199 ),
201200 (
202201 {},
203202 {"build" : {"dockerfile" : "test-dockerfile" }},
204- {"build" : {"context" : str ( Path . cwd ()) , "dockerfile" : "test-dockerfile" }},
203+ {"build" : {"context" : cwd , "dockerfile" : "test-dockerfile" }},
205204 ),
206205 (
207206 {},
208207 {"build" : {"dockerfile" : "test-dockerfile" }},
209- {"build" : {"context" : str ( Path . cwd ()) , "dockerfile" : "test-dockerfile" }},
208+ {"build" : {"context" : cwd , "dockerfile" : "test-dockerfile" }},
210209 ),
211210 (
212211 {"build" : {"dockerfile" : "test-dockerfile-1" }},
213212 {"build" : {"dockerfile" : "test-dockerfile-2" }},
214- {"build" : {"context" : str ( Path . cwd ()) , "dockerfile" : "test-dockerfile-2" }},
213+ {"build" : {"context" : cwd , "dockerfile" : "test-dockerfile-2" }},
215214 ),
216215 (
217216 {"build" : "/workspace/absolute" },
@@ -223,11 +222,44 @@ def test__parse_compose_file_when_single_compose() -> None:
223222 {"build" : "/workspace/absolute" },
224223 {"build" : {"context" : "/workspace/absolute" , "dockerfile" : "test-dockerfile" }},
225224 ),
225+ (
226+ {"build" : {"dockerfile" : "./test-dockerfile-1" }},
227+ {"build" : {"dockerfile" : "./test-dockerfile-2" , "args" : ["ENV1=1" ]}},
228+ {
229+ "build" : {
230+ "context" : cwd ,
231+ "dockerfile" : "./test-dockerfile-2" ,
232+ "args" : ["ENV1=1" ],
233+ }
234+ },
235+ ),
236+ (
237+ {"build" : {"dockerfile" : "./test-dockerfile-1" , "args" : ["ENV1=1" ]}},
238+ {"build" : {"dockerfile" : "./test-dockerfile-2" }},
239+ {
240+ "build" : {
241+ "context" : cwd ,
242+ "dockerfile" : "./test-dockerfile-2" ,
243+ "args" : ["ENV1=1" ],
244+ }
245+ },
246+ ),
247+ (
248+ {"build" : {"dockerfile" : "./test-dockerfile-1" , "args" : ["ENV1=1" ]}},
249+ {"build" : {"dockerfile" : "./test-dockerfile-2" , "args" : ["ENV2=2" ]}},
250+ {
251+ "build" : {
252+ "context" : cwd ,
253+ "dockerfile" : "./test-dockerfile-2" ,
254+ "args" : ["ENV1=1" , "ENV2=2" ],
255+ }
256+ },
257+ ),
226258]
227259
228260
229261#
230- # running full parse over merged and extended compose files
262+ # running full parse over merged
231263#
232264def test__parse_compose_file_when_multiple_composes () -> None :
233265 for test_input , test_override , expected_result in copy .deepcopy (
@@ -274,5 +306,5 @@ def dump_yaml(compose: dict, name: str) -> None:
274306def test_clean_test_yamls () -> None :
275307 test_files = ["test-compose-1.yaml" , "test-compose-2.yaml" , "test-compose.yaml" ]
276308 for file in test_files :
277- if Path ( file ). exists ():
309+ if os . path . exists (file ):
278310 os .remove (file )
0 commit comments