Skip to content

Commit

Permalink
Adjust test for concept equality testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nanglo123 committed Sep 23, 2024
1 parent e56953f commit cae4842
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
11 changes: 0 additions & 11 deletions mira/metamodel/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,6 @@ class Concept(BaseModel):

model_config = ConfigDict(arbitrary_types_allowed=True)

def __eq__(self, other):
if isinstance(other, Concept):
return (self.name == other.name and
self.display_name == other.display_name and
self.description == other.description and
self.identifiers == other.identifiers and
self.context == other.context and
self.units == other.units)
else:
return False

def with_context(self, do_rename=False, curie_to_name_map=None,
inplace=False, **context) -> "Concept":
"""Return this concept with extra context.
Expand Down
34 changes: 24 additions & 10 deletions tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,33 @@ def test_stratify_full(self):
self.assertEqual(tm_stratified.parameters, actual.parameters)
self.assertTrue(actual.initials['infected_population_vaccinated'].expression.equals(
tm_stratified.initials['infected_population_vaccinated'].expression))
self.assertEqual(

def one_to_one_concept_mapping(strat_concepts, actual_concepts):
matched_concept_idxs = set()
for strat_concept in strat_concepts:
matched = False
for concept_idx, actual_concept in enumerate(actual_concepts):
if (strat_concept.is_equal_to(actual_concept) and
concept_idx not in matched_concept_idxs):
matched_concept_idxs.add(concept_idx)
matched = True
break
if not matched:
return False
return True

self.assertTrue(one_to_one_concept_mapping(
[t.subject for t in tm_stratified.templates],
[t.subject for t in actual.templates],
)
self.assertEqual(
[t.subject for t in actual.templates]))

self.assertTrue(one_to_one_concept_mapping(
[t.outcome for t in tm_stratified.templates],
[t.outcome for t in actual.templates],
)
self.assertEqual(
[t.outcome for t in actual.templates]))

self.assertTrue(one_to_one_concept_mapping(
[t.controller for t in tm_stratified.templates],
[t.controller for t in actual.templates],
)
self.assertEqual(tm_stratified.templates, actual.templates)
[t.controller for t in actual.templates]))


def test_stratify(self):
"""Test stratifying a template model by labels."""
Expand Down

0 comments on commit cae4842

Please sign in to comment.