Skip to content

Commit 053e899

Browse files
committed
Add kwarg for model subset testing
Since we only have a limited set of models that we are testing subsets of keys for, we should explicitly only allow subsets when testing those getters.
1 parent c02a749 commit 053e899

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

napalm/base/test/getters.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ def test_get_ntp_peers(self, test_case):
311311

312312
for peer, peer_details in get_ntp_peers.items():
313313
assert isinstance(peer, str)
314-
assert helpers.test_model(models.NTPPeerDict, peer_details)
314+
assert helpers.test_model(
315+
models.NTPPeerDict, peer_details, allow_subset=True
316+
)
315317

316318
return get_ntp_peers
317319

@@ -323,7 +325,9 @@ def test_get_ntp_servers(self, test_case):
323325

324326
for server, server_details in get_ntp_servers.items():
325327
assert isinstance(server, str)
326-
assert helpers.test_model(models.NTPServerDict, server_details)
328+
assert helpers.test_model(
329+
models.NTPServerDict, server_details, allow_subset=True
330+
)
327331

328332
return get_ntp_servers
329333

napalm/base/test/helpers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""Several methods to help with the tests."""
22

33

4-
def test_model(model, data):
4+
def test_model(model, data, allow_subset=False):
55
"""Return if the dictionary `data` complies with the `model`."""
66
# Access the underlying schema for a TypedDict directly
77
annotations = model.__annotations__
8-
if model.__total__:
9-
same_keys = set(annotations.keys()) == set(data.keys())
10-
else:
8+
if allow_subset:
119
same_keys = set(data.keys()) <= set(annotations.keys())
10+
source = data
11+
else:
12+
same_keys = set(annotations.keys()) == set(data.keys())
13+
source = annotations
1214

1315
if not same_keys:
1416
print(
@@ -18,7 +20,7 @@ def test_model(model, data):
1820
)
1921

2022
correct_class = True
21-
for key in data.keys():
23+
for key in source.keys():
2224
correct_class = isinstance(data[key], annotations[key]) and correct_class
2325
if not correct_class:
2426
print(

0 commit comments

Comments
 (0)