Skip to content

Commit 4258c80

Browse files
committed
tests: fixes for repr
1 parent 6b09b74 commit 4258c80

File tree

4 files changed

+48
-32
lines changed

4 files changed

+48
-32
lines changed

execution_engine/fhir/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_coding(cc: CodeableConcept, system_uri: str | None = None) -> Coding:
1414

1515
if cc.coding is None or len(coding) != 1:
1616
raise ValueError(
17-
f"CodeableConcept must have exactly one coding, got {len(coding)}"
17+
f"CodeableConcept must have exactly one coding, got {len(coding) if cc.coding else 'None'}"
1818
)
1919

2020
return coding[0]

execution_engine/omop/criterion/combination/combination.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,12 @@ def _build_repr(
273273
lines.extend(criteria_lines)
274274
lines.append(f"{child_indent}],")
275275
else:
276-
assert len(criteria_lines) == 1
276+
assert len(criteria_lines) <= 1
277277
lines.extend(kw_lines)
278-
lines.append(
279-
f"{child_indent}{children_param_name}={criteria_lines[0].strip()}"
280-
)
278+
if criteria_lines:
279+
lines.append(
280+
f"{child_indent}{children_param_name}={criteria_lines[0].strip()}"
281+
)
281282

282283
lines.append(f"{indent})")
283284

tests/execution_engine/omop/criterion/combination/test_logical_combination.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,16 @@ def test_operator_str(self, operator, threshold):
203203
op = LogicalCriterionCombination.Operator(operator, threshold)
204204

205205
if operator in ["AT_LEAST", "AT_MOST", "EXACTLY"]:
206-
assert repr(op) == f'Operator(operator="{operator}", threshold={threshold})'
206+
assert (
207+
repr(op)
208+
== f'LogicalCriterionCombination.Operator(operator="{operator}", threshold={threshold})'
209+
)
207210
assert str(op) == f"{operator}(threshold={threshold})"
208211
else:
209-
assert repr(op) == f'Operator(operator="{operator}")'
212+
assert (
213+
repr(op)
214+
== f'LogicalCriterionCombination.Operator(operator="{operator}")'
215+
)
210216
assert str(op) == f"{operator}"
211217

212218
def test_repr(self):

tests/execution_engine/omop/criterion/combination/test_temporal_combination.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from execution_engine.omop.criterion.combination.temporal import (
1515
FixedWindowTemporalIndicatorCombination,
1616
PersonalWindowTemporalIndicatorCombination,
17-
TimeIntervalType, TemporalIndicatorCombination,
17+
TimeIntervalType,
1818
)
1919
from execution_engine.omop.criterion.condition_occurrence import ConditionOccurrence
2020
from execution_engine.omop.criterion.drug_exposure import DrugExposure
@@ -27,9 +27,9 @@
2727
from execution_engine.util.value import ValueNumber
2828
from tests._fixtures.concept import (
2929
concept_artificial_respiration,
30-
concept_delir_screening,
3130
concept_body_weight,
3231
concept_covid19,
32+
concept_delir_screening,
3333
concept_heparin_ingredient,
3434
concept_surgical_procedure,
3535
concept_unit_kg,
@@ -208,10 +208,16 @@ def test_operator_str(self, operator, threshold):
208208
op = FixedWindowTemporalIndicatorCombination.Operator(operator, threshold)
209209

210210
if operator in ["AT_LEAST", "AT_MOST", "EXACTLY"]:
211-
assert repr(op) == f'Operator(operator="{operator}", threshold={threshold})'
211+
assert (
212+
repr(op)
213+
== f'TemporalIndicatorCombination.Operator(operator="{operator}", threshold={threshold})'
214+
)
212215
assert str(op) == f"{operator}(threshold={threshold})"
213216
else:
214-
assert repr(op) == f'Operator(operator="{operator}")'
217+
assert (
218+
repr(op)
219+
== f'TemporalIndicatorCombination.Operator(operator="{operator}")'
220+
)
215221
assert str(op) == f"{operator}"
216222

217223
def test_repr(self):
@@ -228,9 +234,7 @@ def test_repr(self):
228234
" interval_type=TimeIntervalType.MORNING_SHIFT,\n"
229235
" start_time=None,\n"
230236
" end_time=None,\n"
231-
' operator=Operator(operator="AT_LEAST", threshold=1),\n'
232-
" criteria=[\n"
233-
" ],\n"
237+
' operator=TemporalIndicatorCombination.Operator(operator="AT_LEAST", threshold=1),\n'
234238
")"
235239
)
236240

@@ -245,9 +249,7 @@ def test_repr(self):
245249
" interval_type=None,\n"
246250
" start_time=datetime.time(8, 0),\n"
247251
" end_time=datetime.time(16, 0),\n"
248-
' operator=Operator(operator="AT_LEAST", threshold=1),\n'
249-
" criteria=[\n"
250-
" ],\n"
252+
' operator=TemporalIndicatorCombination.Operator(operator="AT_LEAST", threshold=1),\n'
251253
")"
252254
)
253255

@@ -309,6 +311,7 @@ def test_add_all(self):
309311
concept=concept_delir_screening,
310312
)
311313

314+
312315
class TestCriterionCombinationDatabase(TestCriterion):
313316
"""
314317
Test class for testing criterion combinations on the database.
@@ -323,13 +326,13 @@ def observation_window(self) -> TimeRange:
323326
@pytest.fixture
324327
def criteria(self, db_session):
325328
criteria = [
326-
c1,
327-
c2,
328-
c3,
329-
bodyweight_measurement_without_forward_fill,
330-
bodyweight_measurement_with_forward_fill,
331-
delir_screening,
332-
]
329+
c1,
330+
c2,
331+
c3,
332+
bodyweight_measurement_without_forward_fill,
333+
bodyweight_measurement_with_forward_fill,
334+
delir_screening,
335+
]
333336
for i, c in enumerate(criteria):
334337
if not c.is_persisted():
335338
c.set_id(i + 1)
@@ -1668,6 +1671,7 @@ def test_combination_on_database(
16681671
persons,
16691672
)
16701673

1674+
16711675
class TestTemporalCountNearObservationWindowEnd(TestCriterionCombinationDatabase):
16721676
"""This test ensures that counting criteria with minimum count
16731677
thresholds adapt to the temporal interval of the population
@@ -1683,13 +1687,17 @@ class TestTemporalCountNearObservationWindowEnd(TestCriterionCombinationDatabase
16831687

16841688
@pytest.fixture
16851689
def observation_window(self) -> TimeRange:
1686-
return TimeRange(name="observation", start="2025-02-18 13:55:00Z", end="2025-02-22 11:00:00Z")
1690+
return TimeRange(
1691+
name="observation", start="2025-02-18 13:55:00Z", end="2025-02-22 11:00:00Z"
1692+
)
16871693

16881694
def patient_events(self, db_session, visit_occurrence):
1689-
c1 = create_condition(vo=visit_occurrence,
1690-
condition_concept_id=concept_covid19.concept_id,
1691-
condition_start_datetime=pendulum.parse("2025-02-19 22:00:00+01:00"),
1692-
condition_end_datetime=pendulum.parse("2025-02-22 02:00:00+01:00"))
1695+
c1 = create_condition(
1696+
vo=visit_occurrence,
1697+
condition_concept_id=concept_covid19.concept_id,
1698+
condition_start_datetime=pendulum.parse("2025-02-19 22:00:00+01:00"),
1699+
condition_end_datetime=pendulum.parse("2025-02-22 02:00:00+01:00"),
1700+
)
16931701
# One screen on the 19th
16941702
e1 = create_procedure(
16951703
vo=visit_occurrence,
@@ -1725,7 +1733,7 @@ def patient_events(self, db_session, visit_occurrence):
17251733
start_datetime=pendulum.parse("2025-02-22 04:00:00+01:00"),
17261734
end_datetime=pendulum.parse("2025-02-22 04:01:00+01:00"),
17271735
)
1728-
db_session.add_all([c1,e1,e2,e3,e4,e5])
1736+
db_session.add_all([c1, e1, e2, e3, e4, e5])
17291737
db_session.commit()
17301738

17311739
@pytest.mark.parametrize(
@@ -1777,13 +1785,14 @@ def test_at_least_combination_on_database(
17771785
observation_window,
17781786
criteria,
17791787
):
1780-
persons = [person[0]] # only one person
1788+
persons = [person[0]] # only one person
17811789
vos = [
17821790
create_visit(
17831791
person_id=person.person_id,
17841792
visit_start_datetime=observation_window.start
17851793
+ datetime.timedelta(hours=3),
1786-
visit_end_datetime=observation_window.end - datetime.timedelta(hours=6.5),
1794+
visit_end_datetime=observation_window.end
1795+
- datetime.timedelta(hours=6.5),
17871796
visit_concept_id=concepts.INTENSIVE_CARE,
17881797
)
17891798
for person in persons

0 commit comments

Comments
 (0)