Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Added more specific error messages to the duplicate id asserts #2428

Closed
22 changes: 18 additions & 4 deletions test/general/test_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class TestIDs(unittest.TestCase):
def test_unique_items(self):
"""Tests that every game has a unique ID per item in the datapackage"""
known_item_ids = set()
for gamename, world_type in AutoWorldRegister.world_types.items():
for world_type in AutoWorldRegister.world_types.values():
current = len(known_item_ids)
known_item_ids |= set(world_type.item_id_to_name)
self.assertEqual(len(known_item_ids) - len(world_type.item_id_to_name), current)

def test_unique_locations(self):
"""Tests that every game has a unique ID per location in the datapackage"""
known_location_ids = set()
for gamename, world_type in AutoWorldRegister.world_types.items():
for world_type in AutoWorldRegister.world_types.values():
current = len(known_location_ids)
known_location_ids |= set(world_type.location_id_to_name)
self.assertEqual(len(known_location_ids) - len(world_type.location_id_to_name), current)
Expand Down Expand Up @@ -59,10 +59,24 @@ def test_duplicate_item_ids(self):
"""Test that a game doesn't have item id overlap within its own datapackage"""
for gamename, world_type in AutoWorldRegister.world_types.items():
with self.subTest(game=gamename):
self.assertEqual(len(world_type.item_id_to_name), len(world_type.item_name_to_id))
Jarno458 marked this conversation as resolved.
Show resolved Hide resolved
overlap = False
if len(world_type.item_id_to_name) != len(world_type.item_name_to_id):
overlap = \
set(world_type.item_id_to_name.values()) \
.symmetric_difference(set(world_type.item_name_to_id.keys())) or \
set(world_type.item_id_to_name.keys()) \
.symmetric_difference(set(world_type.item_name_to_id.values()))
self.assertFalse(overlap)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of this style of creating boolean values and asserting them, when the real check is actually the if. What was wrong with the suggested code above?


def test_duplicate_location_ids(self):
"""Test that a game doesn't have location id overlap within its own datapackage"""
for gamename, world_type in AutoWorldRegister.world_types.items():
with self.subTest(game=gamename):
self.assertEqual(len(world_type.location_id_to_name), len(world_type.location_name_to_id))
overlap = False
if len(world_type.item_id_to_name) != len(world_type.item_name_to_id):
overlap = \
set(world_type.location_id_to_name.values()) \
.symmetric_difference(set(world_type.location_name_to_id.keys())) or \
set(world_type.location_id_to_name.keys()) \
.symmetric_difference(set(world_type.location_name_to_id.values()))
self.assertFalse(overlap)
Loading