Skip to content

Commit d5b628a

Browse files
authored
Albrja/mic-5739/mypy-test-values (#615)
Albrja/mic-5739/mypy-test-values Fix mypy erros in tests/framework/test_values.py - *Category*: Type-hinting - *JIRA issue*: https://jira.ihme.washington.edu/browse/MIC-5973 Changes and notes -Fix mypy erros in tests/framework/test_values.py ### Testing <!-- Details on how code was verified, any unit tests local for the repo, regression testing, etc. At a minimum, this should include an integration test for a framework change. Consider: plots, images, (small) csv file. -->
1 parent 094e281 commit d5b628a

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
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.19 - 04/29/25**
2+
3+
- Type-hinting: Fix mypy errors in test/framework/test_values.py
4+
15
**3.3.18 - 04/24/25**
26

37
- Bugfix: Allow a component to require all state table columns and create a column.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ exclude = [
4242
'tests/framework/results/test_context.py',
4343
'tests/framework/test_engine.py',
4444
'tests/framework/test_event.py',
45-
'tests/framework/test_values.py',
4645
'tests/interface/test_utilities.py',
4746
]
4847

tests/framework/test_values.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Callable
4+
15
import numpy as np
26
import pandas as pd
37
import pytest
8+
from pytest_mock import MockFixture
49

510
from vivarium.framework.utilities import from_yearly
611
from vivarium.framework.values import (
@@ -14,27 +19,29 @@
1419

1520

1621
@pytest.fixture
17-
def static_step():
22+
def static_step() -> Callable[[pd.Index[int]], pd.Series[pd.Timedelta]]:
1823
return lambda idx: pd.Series(pd.Timedelta(days=6), index=idx)
1924

2025

2126
@pytest.fixture
22-
def variable_step():
27+
def variable_step() -> Callable[[pd.Index[int]], pd.Series[pd.Timedelta]]:
2328
return lambda idx: pd.Series(
2429
[pd.Timedelta(days=3) if i % 2 == 0 else pd.Timedelta(days=5) for i in idx], index=idx
2530
)
2631

2732

2833
@pytest.fixture
29-
def manager(mocker):
34+
def manager(mocker: MockFixture) -> ValuesManager:
3035
manager = ValuesManager()
3136
builder = mocker.MagicMock()
3237
manager.setup(builder)
3338
return manager
3439

3540

3641
@pytest.fixture
37-
def manager_with_step_size(mocker, request):
42+
def manager_with_step_size(
43+
mocker: MockFixture, request: pytest.FixtureRequest
44+
) -> ValuesManager:
3845
manager = ValuesManager()
3946
builder = mocker.MagicMock()
4047
builder.time.step_size = lambda: lambda: pd.Timedelta(days=6)
@@ -43,7 +50,7 @@ def manager_with_step_size(mocker, request):
4350
return manager
4451

4552

46-
def test_replace_combiner(manager):
53+
def test_replace_combiner(manager: ValuesManager) -> None:
4754
value = manager.register_value_producer("test", source=lambda: 1)
4855

4956
assert value() == 1
@@ -55,15 +62,15 @@ def test_replace_combiner(manager):
5562
assert value() == 84
5663

5764

58-
def test_joint_value(manager):
65+
def test_joint_value(manager: ValuesManager) -> None:
5966
# This is the normal configuration for PAF and disability weight type values
6067
index = pd.Index(range(10))
6168

6269
value = manager.register_value_producer(
6370
"test",
6471
source=lambda idx: [pd.Series(0.0, index=idx)],
6572
preferred_combiner=list_combiner,
66-
preferred_post_processor=union_post_processor,
73+
preferred_post_processor=union_post_processor, # type: ignore [arg-type]
6774
)
6875
assert np.all(value(index) == 0)
6976

@@ -74,7 +81,7 @@ def test_joint_value(manager):
7481
assert np.all(value(index) == 0.75)
7582

7683

77-
def test_contains(manager):
84+
def test_contains(manager: ValuesManager) -> None:
7885
value = "test_value"
7986
rate = "test_rate"
8087

@@ -86,7 +93,7 @@ def test_contains(manager):
8693
assert rate not in manager
8794

8895

89-
def test_returned_series_name(manager):
96+
def test_returned_series_name(manager: ValuesManager) -> None:
9097
value = manager.register_value_producer(
9198
"test",
9299
source=lambda idx: pd.Series(0.0, index=idx),
@@ -95,7 +102,7 @@ def test_returned_series_name(manager):
95102

96103

97104
@pytest.mark.parametrize("manager_with_step_size", ["static_step"], indirect=True)
98-
def test_rescale_post_processor_static(manager_with_step_size):
105+
def test_rescale_post_processor_static(manager_with_step_size: ValuesManager) -> None:
99106
index = pd.Index(range(10))
100107

101108
pipeline = manager_with_step_size.register_value_producer(
@@ -107,7 +114,7 @@ def test_rescale_post_processor_static(manager_with_step_size):
107114

108115

109116
@pytest.mark.parametrize("manager_with_step_size", ["variable_step"], indirect=True)
110-
def test_rescale_post_processor_variable(manager_with_step_size):
117+
def test_rescale_post_processor_variable(manager_with_step_size: ValuesManager) -> None:
111118
index = pd.Index(range(10))
112119

113120
pipeline = manager_with_step_size.register_value_producer(
@@ -122,7 +129,7 @@ def test_rescale_post_processor_variable(manager_with_step_size):
122129
assert np.all(odds == from_yearly(0.5, pd.Timedelta(days=5)))
123130

124131

125-
def test_unsourced_pipeline():
132+
def test_unsourced_pipeline() -> None:
126133
pipeline = Pipeline("some_name")
127134
assert pipeline.source.resource_id == "missing_value_source.some_name"
128135
with pytest.raises(

0 commit comments

Comments
 (0)