Skip to content

Commit e31904a

Browse files
authored
Typing tests/helpers.py (#612)
* fix typing * add cl * lint * Update CHANGELOG.rst
1 parent da97810 commit e31904a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**3.3.16 - 04/21/25**
2+
3+
- Type-hinting: Fix mypy errors in tests/helpers.py
4+
15
**3.3.15 - 04/14/25**
26

37
- Type-hinting: Fix mypy errors in src/vivarium/interface/cli.py

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ exclude = [
4444
'tests/framework/test_event.py',
4545
'tests/framework/test_lifecycle.py',
4646
'tests/framework/test_values.py',
47-
'tests/helpers.py',
4847
'tests/interface/test_utilities.py',
4948
]
5049

tests/helpers.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# mypy: ignore-errors
21
from __future__ import annotations
32

43
from typing import Any
54

65
import pandas as pd
6+
from layered_config_tree import ConfigurationError
77

88
from vivarium import Component, Observer
99
from vivarium.framework.engine import Builder
@@ -22,7 +22,7 @@ def name(self) -> str:
2222
def configuration_defaults(self) -> dict[str, Any]:
2323
return {}
2424

25-
def __init__(self, *args, name: str = "mock_component_a") -> None:
25+
def __init__(self, *args: Any, name: str = "mock_component_a") -> None:
2626
super().__init__()
2727
self._name = name
2828
self.args = args
@@ -43,14 +43,13 @@ class MockComponentB(Observer):
4343
def name(self) -> str:
4444
return self._name
4545

46-
def __init__(self, *args, name: str = "mock_component_b") -> None:
46+
def __init__(self, *args: Any, name: str = "mock_component_b") -> None:
4747
super().__init__()
4848
self._name = name
4949
self.args = args
50-
self.builder_used_for_setup = None
50+
self.builder_used_for_setup: Builder | None = None
5151
if len(self.args) > 1:
52-
for arg in self.args:
53-
self._sub_components.append(MockComponentB(arg, name=arg))
52+
self._sub_components = [MockComponentB(arg, name=arg) for arg in self.args]
5453

5554
def setup(self, builder: Builder) -> None:
5655
self.builder_used_for_setup = builder
@@ -91,7 +90,7 @@ def configuration_defaults(self) -> dict[str, Any]:
9190
def __init__(self, name: str):
9291
super().__init__()
9392
self._name = name
94-
self.builder_used_for_setup = None
93+
self.builder_used_for_setup: Builder | None = None
9594

9695
def setup(self, builder: Builder) -> None:
9796
self.builder_used_for_setup = builder
@@ -102,7 +101,7 @@ def __eq__(self, other: Any) -> bool:
102101

103102

104103
class Listener(MockComponentB):
105-
def __init__(self, *args, name: str = "test_listener"):
104+
def __init__(self, *args: Any, name: str = "test_listener"):
106105
super().__init__(*args, name=name)
107106
self.post_setup_called = False
108107
self.time_step_prepare_called = False
@@ -111,7 +110,7 @@ def __init__(self, *args, name: str = "test_listener"):
111110
self.collect_metrics_called = False
112111
self.simulation_end_called = False
113112

114-
self.event_indexes = {
113+
self.event_indexes: dict[str, pd.Index[int] | None] = {
115114
"time_step_prepare": None,
116115
"time_step": None,
117116
"time_step_cleanup": None,
@@ -177,6 +176,10 @@ class LookupCreator(ColumnCreator):
177176

178177
def build_all_lookup_tables(self, builder: "Builder") -> None:
179178
super().build_all_lookup_tables(builder)
179+
if not self.configuration:
180+
raise ConfigurationError(
181+
"Configuration not set. This may break tests using the lookup table creator helper."
182+
)
180183
self.lookup_tables["favorite_list"] = self.build_lookup_table(
181184
builder,
182185
self.configuration["alternate_data_sources"]["favorite_list"],
@@ -273,7 +276,7 @@ def columns_required(self) -> list[str]:
273276

274277
class FilteredPopulationView(ColumnRequirer):
275278
@property
276-
def population_view_query(self) -> str | None:
279+
def population_view_query(self) -> str:
277280
return "test_column_1 == 5"
278281

279282

0 commit comments

Comments
 (0)