Skip to content

Commit 1572b3d

Browse files
authored
Merge pull request #1402 from p12tic/cleanup-tests
tests/unit: Cleanup assertions in get_net_args() tests
2 parents 4893b5c + 7795c6d commit 1572b3d

File tree

1 file changed

+89
-94
lines changed

1 file changed

+89
-94
lines changed

tests/unit/test_get_net_args.py

Lines changed: 89 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ def test_minimal(self) -> None:
4444
compose = get_networked_compose()
4545
container = get_minimal_container()
4646

47-
expected_args = [
48-
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}",
49-
]
50-
args = get_net_args(compose, container)
51-
self.assertListEqual(expected_args, args)
47+
self.assertEqual(
48+
get_net_args(compose, container),
49+
[f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}"],
50+
)
5251

5352
def test_default_net_is_None(self) -> None:
5453
compose = get_networked_compose()
@@ -59,69 +58,63 @@ def test_default_net_is_None(self) -> None:
5958

6059
compose.default_net = None
6160

62-
expected_args = [
63-
f"--network=bridge:alias={SERVICE_NAME},mac={mac_address}",
64-
]
65-
args = get_net_args(compose, container)
66-
self.assertListEqual(expected_args, args)
61+
self.assertEqual(
62+
get_net_args(compose, container),
63+
[f"--network=bridge:alias={SERVICE_NAME},mac={mac_address}"],
64+
)
6765

6866
def test_one_net(self) -> None:
6967
compose = get_networked_compose()
7068
container = get_minimal_container()
7169
container["networks"] = {"net0": {}}
7270

73-
expected_args = [
74-
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}",
75-
]
76-
args = get_net_args(compose, container)
77-
self.assertListEqual(expected_args, args)
71+
self.assertEqual(
72+
get_net_args(compose, container),
73+
[f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}"],
74+
)
7875

7976
def test_alias(self) -> None:
8077
compose = get_networked_compose()
8178
container = get_minimal_container()
8279
container["networks"] = {"net0": {}}
8380
container["_aliases"] = ["alias1", "alias2"]
8481

85-
expected_args = [
86-
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME},alias=alias1,alias=alias2",
87-
]
88-
args = get_net_args(compose, container)
89-
self.assertListEqual(expected_args, args)
82+
self.assertEqual(
83+
get_net_args(compose, container),
84+
[f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME},alias=alias1,alias=alias2"],
85+
)
9086

9187
def test_aliases_on_network_scope(self) -> None:
9288
compose = get_networked_compose()
9389
container = get_minimal_container()
9490
container["networks"] = {"net0": {"aliases": ["alias1"]}}
9591

96-
expected_args = [
97-
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME},alias=alias1",
98-
]
99-
args = get_net_args(compose, container)
100-
self.assertListEqual(expected_args, args)
92+
self.assertEqual(
93+
get_net_args(compose, container),
94+
[f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME},alias=alias1"],
95+
)
10196

10297
def test_one_ipv4(self) -> None:
10398
ip = "192.168.0.42"
10499
compose = get_networked_compose()
105100
container = get_minimal_container()
106101
container["networks"] = {"net0": {"ipv4_address": ip}}
107102

108-
expected_args = [
109-
f"--network={PROJECT_NAME}_net0:ip={ip},alias={SERVICE_NAME}",
110-
]
111-
args = get_net_args(compose, container)
112-
self.assertEqual(expected_args, args)
103+
self.assertEqual(
104+
get_net_args(compose, container),
105+
[f"--network={PROJECT_NAME}_net0:ip={ip},alias={SERVICE_NAME}"],
106+
)
113107

114108
def test_one_ipv6(self) -> None:
115109
ipv6_address = "fd00:0::42"
116110
compose = get_networked_compose()
117111
container = get_minimal_container()
118112
container["networks"] = {"net0": {"ipv6_address": ipv6_address}}
119113

120-
expected_args = [
121-
f"--network={PROJECT_NAME}_net0:ip6={ipv6_address},alias={SERVICE_NAME}",
122-
]
123-
args = get_net_args(compose, container)
124-
self.assertListEqual(expected_args, args)
114+
self.assertEqual(
115+
get_net_args(compose, container),
116+
[f"--network={PROJECT_NAME}_net0:ip6={ipv6_address},alias={SERVICE_NAME}"],
117+
)
125118

126119
def test_one_mac(self) -> None:
127120
mac = "00:11:22:33:44:55"
@@ -130,11 +123,10 @@ def test_one_mac(self) -> None:
130123
container["networks"] = {"net0": {}}
131124
container["mac_address"] = mac
132125

133-
expected_args = [
134-
f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}",
135-
]
136-
args = get_net_args(compose, container)
137-
self.assertListEqual(expected_args, args)
126+
self.assertEqual(
127+
get_net_args(compose, container),
128+
[f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}"],
129+
)
138130

139131
def test_one_mac_two_nets(self) -> None:
140132
mac = "00:11:22:33:44:55"
@@ -143,12 +135,13 @@ def test_one_mac_two_nets(self) -> None:
143135
container["networks"] = {"net0": {}, "net1": {}}
144136
container["mac_address"] = mac
145137

146-
expected_args = [
147-
f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}",
148-
f"--network={PROJECT_NAME}_net1:alias={SERVICE_NAME}",
149-
]
150-
args = get_net_args(compose, container)
151-
self.assertListEqual(expected_args, args)
138+
self.assertEqual(
139+
get_net_args(compose, container),
140+
[
141+
f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}",
142+
f"--network={PROJECT_NAME}_net1:alias={SERVICE_NAME}",
143+
],
144+
)
152145

153146
@parameterized.expand([
154147
"mac_address",
@@ -160,35 +153,36 @@ def test_mac_on_network(self, mac_attr: str) -> None:
160153
container = get_minimal_container()
161154
container["networks"] = {"net0": {mac_attr: mac}}
162155

163-
expected_args = [
164-
f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}",
165-
]
166-
args = get_net_args(compose, container)
167-
self.assertListEqual(expected_args, args)
156+
self.assertEqual(
157+
get_net_args(compose, container),
158+
[f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}"],
159+
)
168160

169161
def test_two_nets_as_dict(self) -> None:
170162
compose = get_networked_compose(num_networks=2)
171163
container = get_minimal_container()
172164
container["networks"] = {"net0": {}, "net1": {}}
173165

174-
expected_args = [
175-
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}",
176-
f"--network={PROJECT_NAME}_net1:alias={SERVICE_NAME}",
177-
]
178-
args = get_net_args(compose, container)
179-
self.assertListEqual(expected_args, args)
166+
self.assertEqual(
167+
get_net_args(compose, container),
168+
[
169+
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}",
170+
f"--network={PROJECT_NAME}_net1:alias={SERVICE_NAME}",
171+
],
172+
)
180173

181174
def test_two_nets_as_list(self) -> None:
182175
compose = get_networked_compose(num_networks=2)
183176
container = get_minimal_container()
184177
container["networks"] = ["net0", "net1"]
185178

186-
expected_args = [
187-
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}",
188-
f"--network={PROJECT_NAME}_net1:alias={SERVICE_NAME}",
189-
]
190-
args = get_net_args(compose, container)
191-
self.assertListEqual(expected_args, args)
179+
self.assertEqual(
180+
get_net_args(compose, container),
181+
[
182+
f"--network={PROJECT_NAME}_net0:alias={SERVICE_NAME}",
183+
f"--network={PROJECT_NAME}_net1:alias={SERVICE_NAME}",
184+
],
185+
)
192186

193187
def test_two_ipv4(self) -> None:
194188
ip0 = "192.168.0.42"
@@ -197,12 +191,13 @@ def test_two_ipv4(self) -> None:
197191
container = get_minimal_container()
198192
container["networks"] = {"net0": {"ipv4_address": ip0}, "net1": {"ipv4_address": ip1}}
199193

200-
expected_args = [
201-
f"--network={PROJECT_NAME}_net0:ip={ip0},alias={SERVICE_NAME}",
202-
f"--network={PROJECT_NAME}_net1:ip={ip1},alias={SERVICE_NAME}",
203-
]
204-
args = get_net_args(compose, container)
205-
self.assertListEqual(expected_args, args)
194+
self.assertEqual(
195+
get_net_args(compose, container),
196+
[
197+
f"--network={PROJECT_NAME}_net0:ip={ip0},alias={SERVICE_NAME}",
198+
f"--network={PROJECT_NAME}_net1:ip={ip1},alias={SERVICE_NAME}",
199+
],
200+
)
206201

207202
def test_two_ipv6(self) -> None:
208203
ip0 = "fd00:0::42"
@@ -211,12 +206,13 @@ def test_two_ipv6(self) -> None:
211206
container = get_minimal_container()
212207
container["networks"] = {"net0": {"ipv6_address": ip0}, "net1": {"ipv6_address": ip1}}
213208

214-
expected_args = [
215-
f"--network={PROJECT_NAME}_net0:ip6={ip0},alias={SERVICE_NAME}",
216-
f"--network={PROJECT_NAME}_net1:ip6={ip1},alias={SERVICE_NAME}",
217-
]
218-
args = get_net_args(compose, container)
219-
self.assertListEqual(expected_args, args)
209+
self.assertEqual(
210+
get_net_args(compose, container),
211+
[
212+
f"--network={PROJECT_NAME}_net0:ip6={ip0},alias={SERVICE_NAME}",
213+
f"--network={PROJECT_NAME}_net1:ip6={ip1},alias={SERVICE_NAME}",
214+
],
215+
)
220216

221217
# custom extension; not supported by docker-compose
222218
def test_two_mac(self) -> None:
@@ -229,12 +225,13 @@ def test_two_mac(self) -> None:
229225
"net1": {"x-podman.mac_address": mac1},
230226
}
231227

232-
expected_args = [
233-
f"--network={PROJECT_NAME}_net0:mac={mac0},alias={SERVICE_NAME}",
234-
f"--network={PROJECT_NAME}_net1:mac={mac1},alias={SERVICE_NAME}",
235-
]
236-
args = get_net_args(compose, container)
237-
self.assertListEqual(expected_args, args)
228+
self.assertEqual(
229+
get_net_args(compose, container),
230+
[
231+
f"--network={PROJECT_NAME}_net0:mac={mac0},alias={SERVICE_NAME}",
232+
f"--network={PROJECT_NAME}_net1:mac={mac1},alias={SERVICE_NAME}",
233+
],
234+
)
238235

239236
def test_mixed_mac(self) -> None:
240237
ip4_0 = "192.168.0.42"
@@ -273,14 +270,15 @@ def test_mixed_config(self) -> None:
273270
}
274271
container["mac_address"] = mac
275272

276-
expected_args = [
277-
f"--network={PROJECT_NAME}_net0:ip={ip4_0},ip6={ip6_0},mac={mac},alias={SERVICE_NAME}",
278-
f"--network={PROJECT_NAME}_net1:ip={ip4_1},alias={SERVICE_NAME}",
279-
f"--network={PROJECT_NAME}_net2:ip6={ip6_2},alias={SERVICE_NAME}",
280-
f"--network={PROJECT_NAME}_net3:alias={SERVICE_NAME}",
281-
]
282-
args = get_net_args(compose, container)
283-
self.assertListEqual(expected_args, args)
273+
self.assertEqual(
274+
get_net_args(compose, container),
275+
[
276+
f"--network={PROJECT_NAME}_net0:ip={ip4_0},ip6={ip6_0},mac={mac},alias={SERVICE_NAME}",
277+
f"--network={PROJECT_NAME}_net1:ip={ip4_1},alias={SERVICE_NAME}",
278+
f"--network={PROJECT_NAME}_net2:ip6={ip6_2},alias={SERVICE_NAME}",
279+
f"--network={PROJECT_NAME}_net3:alias={SERVICE_NAME}",
280+
],
281+
)
284282

285283
@parameterized.expand([
286284
("bridge", [f"--network=bridge:alias={SERVICE_NAME},mac=11:22:33:44:55:66"]),
@@ -307,8 +305,7 @@ def test_network_modes(self, network_mode: str, expected_args: list) -> None:
307305
container["network_mode"] = network_mode
308306
container["mac_address"] = mac_address
309307

310-
args = get_net_args(compose, container)
311-
self.assertListEqual(expected_args, args)
308+
self.assertEqual(get_net_args(compose, container), expected_args)
312309

313310
def test_network_mode_invalid(self) -> None:
314311
compose = get_networked_compose()
@@ -328,6 +325,4 @@ def test_network__mode_service(self) -> None:
328325
container = get_minimal_container()
329326
container["network_mode"] = "service:service_2"
330327

331-
expected_args = ["--network=container:container_2"]
332-
args = get_net_args(compose, container)
333-
self.assertListEqual(expected_args, args)
328+
self.assertEqual(get_net_args(compose, container), ["--network=container:container_2"])

0 commit comments

Comments
 (0)