Skip to content

Commit b80470b

Browse files
committed
Fixup tests
1 parent 4a149a3 commit b80470b

File tree

8 files changed

+116
-161
lines changed

8 files changed

+116
-161
lines changed

tests/component/test_base.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_creation() -> None:
3737
(None, "CID1<_FakeComponent>"),
3838
("test-component", "CID1<_FakeComponent>:test-component"),
3939
],
40+
ids=["no-name", "with-name"],
4041
)
4142
def test_str(name: str | None, expected_str: str) -> None:
4243
"""Test string representation of a component."""
@@ -114,8 +115,8 @@ def test_default_values() -> None:
114115
assert component.category_specific_metadata == {}
115116

116117

117-
@pytest.mark.parametrize("status", list(ComponentStatus))
118-
@pytest.mark.parametrize("lifetime_active", [True, False])
118+
@pytest.mark.parametrize("status", list(ComponentStatus), ids=lambda s: s.name)
119+
@pytest.mark.parametrize("lifetime_active", [True, False], ids=["active", "inactive"])
119120
def test_active_at(
120121
status: ComponentStatus, lifetime_active: bool, caplog: pytest.LogCaptureFixture
121122
) -> None:
@@ -252,28 +253,19 @@ def test_active() -> None:
252253
category_specific_metadata=COMPONENT.category_specific_metadata,
253254
)
254255

255-
ALL_COMPONENTS = [
256-
COMPONENT,
257-
DIFFERENT_NONHASHABLE,
258-
DIFFERENT_STATUS,
259-
DIFFERENT_NAME,
260-
DIFFERENT_ID,
261-
DIFFERENT_MICROGRID_ID,
262-
DIFFERENT_BOTH_ID,
263-
]
264-
265256

266257
@pytest.mark.parametrize(
267258
"comp,expected",
268259
[
269-
(COMPONENT, True),
270-
(DIFFERENT_NONHASHABLE, False),
271-
(DIFFERENT_STATUS, False),
272-
(DIFFERENT_NAME, False),
273-
(DIFFERENT_ID, False),
274-
(DIFFERENT_MICROGRID_ID, False),
275-
(DIFFERENT_BOTH_ID, False),
260+
pytest.param(COMPONENT, True, id="self"),
261+
pytest.param(DIFFERENT_NONHASHABLE, False, id="other-nonhashable"),
262+
pytest.param(DIFFERENT_STATUS, False, id="other-status"),
263+
pytest.param(DIFFERENT_NAME, False, id="other-name"),
264+
pytest.param(DIFFERENT_ID, False, id="other-id"),
265+
pytest.param(DIFFERENT_MICROGRID_ID, False, id="other-microgrid-id"),
266+
pytest.param(DIFFERENT_BOTH_ID, False, id="other-both-ids"),
276267
],
268+
ids=lambda o: str(o.id) if isinstance(o, Component) else str(o),
277269
)
278270
def test_equality(comp: Component, expected: bool) -> None:
279271
"""Test component equality."""
@@ -286,13 +278,13 @@ def test_equality(comp: Component, expected: bool) -> None:
286278
@pytest.mark.parametrize(
287279
"comp,expected",
288280
[
289-
(COMPONENT, True),
290-
(DIFFERENT_NONHASHABLE, True),
291-
(DIFFERENT_STATUS, True),
292-
(DIFFERENT_NAME, True),
293-
(DIFFERENT_ID, False),
294-
(DIFFERENT_MICROGRID_ID, False),
295-
(DIFFERENT_BOTH_ID, False),
281+
pytest.param(COMPONENT, True, id="self"),
282+
pytest.param(DIFFERENT_NONHASHABLE, True, id="other-nonhashable"),
283+
pytest.param(DIFFERENT_STATUS, True, id="other-status"),
284+
pytest.param(DIFFERENT_NAME, True, id="other-name"),
285+
pytest.param(DIFFERENT_ID, False, id="other-id"),
286+
pytest.param(DIFFERENT_MICROGRID_ID, False, id="other-microgrid-id"),
287+
pytest.param(DIFFERENT_BOTH_ID, False, id="other-both-ids"),
296288
],
297289
)
298290
def test_identity(comp: Component, expected: bool) -> None:
@@ -301,8 +293,19 @@ def test_identity(comp: Component, expected: bool) -> None:
301293
assert comp.identity == (comp.id, comp.microgrid_id)
302294

303295

304-
@pytest.mark.parametrize("comp1", ALL_COMPONENTS)
305-
@pytest.mark.parametrize("comp2", ALL_COMPONENTS)
296+
ALL_COMPONENTS_PARAMS = [
297+
pytest.param(COMPONENT, id="comp"),
298+
pytest.param(DIFFERENT_NONHASHABLE, id="nonhashable"),
299+
pytest.param(DIFFERENT_STATUS, id="status"),
300+
pytest.param(DIFFERENT_NAME, id="name"),
301+
pytest.param(DIFFERENT_ID, id="id"),
302+
pytest.param(DIFFERENT_MICROGRID_ID, id="microgrid_id"),
303+
pytest.param(DIFFERENT_BOTH_ID, id="both_ids"),
304+
]
305+
306+
307+
@pytest.mark.parametrize("comp1", ALL_COMPONENTS_PARAMS)
308+
@pytest.mark.parametrize("comp2", ALL_COMPONENTS_PARAMS)
306309
def test_hash(comp1: Component, comp2: Component) -> None:
307310
"""Test that the hash is consistent."""
308311
# We can only say the hash are the same if the components are equal, if they

tests/component/test_connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_validation() -> None:
4545
)
4646

4747

48-
@pytest.mark.parametrize("lifetime_active", [True, False])
48+
@pytest.mark.parametrize("lifetime_active", [True, False], ids=["active", "inactive"])
4949
def test_active_at(lifetime_active: bool) -> None:
5050
"""Test active_at behavior with lifetime.active values."""
5151
mock_lifetime = Mock(spec=Lifetime)
@@ -66,6 +66,7 @@ def test_active_at(lifetime_active: bool) -> None:
6666
@pytest.mark.parametrize(
6767
"lifetime_active",
6868
[True, False],
69+
ids=["active", "inactive"],
6970
)
7071
def test_active(lifetime_active: bool) -> None:
7172
"""Test the active property of ComponentConnection."""
@@ -106,15 +107,15 @@ def test_str() -> None:
106107
"destination_component_id": 2,
107108
"has_lifetime": True,
108109
},
109-
id="complete connection",
110+
id="full",
110111
),
111112
pytest.param(
112113
{
113114
"source_component_id": 1,
114115
"destination_component_id": 2,
115116
"has_lifetime": False,
116117
},
117-
id="missing lifetime",
118+
id="no_lifetime",
118119
),
119120
],
120121
)

tests/metrics/test_bounds.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,28 @@ def test_hash() -> None:
8181
"case",
8282
[
8383
ProtoConversionTestCase(
84-
name="all fields present",
84+
name="full",
8585
has_lower=True,
8686
has_upper=True,
8787
lower=-10.0,
8888
upper=10.0,
8989
),
9090
ProtoConversionTestCase(
91-
name="only lower bound",
91+
name="no_upper_bound",
9292
has_lower=True,
9393
has_upper=False,
9494
lower=-10.0,
9595
upper=None,
9696
),
9797
ProtoConversionTestCase(
98-
name="only upper bound",
98+
name="no_lower_bound",
9999
has_lower=False,
100100
has_upper=True,
101101
lower=None,
102102
upper=10.0,
103103
),
104104
ProtoConversionTestCase(
105-
name="no bounds",
105+
name="no_both_bounds",
106106
has_lower=False,
107107
has_upper=False,
108108
lower=None,
@@ -116,9 +116,6 @@ def test_from_proto(case: ProtoConversionTestCase) -> None:
116116
117117
Args:
118118
case: Test case parameters
119-
120-
Raises:
121-
AssertionError: If the conversion doesn't match expected values
122119
"""
123120
proto = bounds_pb2.Bounds()
124121
if case.has_lower and case.lower is not None:

tests/metrics/test_sample.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,26 +230,26 @@ def test_metric_sample_multiple_bounds(now: datetime) -> None:
230230
"case",
231231
[
232232
AggregatedValueTestCase(
233-
name="complete data",
233+
name="full",
234234
avg_value=5.0,
235235
min_value=1.0,
236236
max_value=10.0,
237237
raw_values=[1.0, 5.0, 10.0],
238238
),
239239
AggregatedValueTestCase(
240-
name="minimal data",
240+
name="minimal",
241241
avg_value=5.0,
242242
has_min=False,
243243
has_max=False,
244244
),
245245
AggregatedValueTestCase(
246-
name="only min additional",
246+
name="only_min",
247247
avg_value=5.0,
248248
has_max=False,
249249
min_value=1.0,
250250
),
251251
AggregatedValueTestCase(
252-
name="only max additional",
252+
name="only_max",
253253
avg_value=5.0,
254254
has_min=False,
255255
max_value=10.0,
@@ -262,9 +262,6 @@ def test_aggregated_metric_value_from_proto(case: AggregatedValueTestCase) -> No
262262
263263
Args:
264264
case: Test case parameters
265-
266-
Raises:
267-
AssertionError: If the conversion doesn't match expected values
268265
"""
269266
proto = metric_sample_pb2.AggregatedMetricValue(
270267
avg_value=case.avg_value,
@@ -288,28 +285,28 @@ def test_aggregated_metric_value_from_proto(case: AggregatedValueTestCase) -> No
288285
"case",
289286
[
290287
MetricSampleTestCase(
291-
name="simple value",
288+
name="simple_value",
292289
has_simple_value=True,
293290
has_aggregated_value=False,
294291
has_source=False,
295292
metric=Metric.AC_ACTIVE_POWER,
296293
),
297294
MetricSampleTestCase(
298-
name="aggregated value",
295+
name="aggregated_value",
299296
has_simple_value=False,
300297
has_aggregated_value=True,
301298
has_source=True,
302299
metric=Metric.AC_ACTIVE_POWER,
303300
),
304301
MetricSampleTestCase(
305-
name="no value",
302+
name="no_value",
306303
has_simple_value=False,
307304
has_aggregated_value=False,
308305
has_source=False,
309306
metric=Metric.AC_ACTIVE_POWER,
310307
),
311308
MetricSampleTestCase(
312-
name="unrecognized metric",
309+
name="unrecognized_metric",
313310
has_simple_value=True,
314311
has_aggregated_value=False,
315312
has_source=False,
@@ -335,9 +332,6 @@ def test_metric_sample_from_proto(
335332
mock_enum_from_proto: Mock for enum conversion
336333
mock_bounds_from_proto: Mock for bounds conversion
337334
case: Test case parameters
338-
339-
Raises:
340-
AssertionError: If the conversion doesn't match expected values
341335
"""
342336
now = datetime.now(timezone.utc)
343337
mock_to_datetime.return_value = now

tests/test_delivery_area.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,31 @@ class ProtoConversionTestCase:
5656
"case",
5757
[
5858
DeliveryAreaTestCase(
59-
name="valid EIC code",
59+
name="valid_EIC_code",
6060
code="10Y1001A1001A450",
6161
code_type=EnergyMarketCodeType.EUROPE_EIC,
6262
expected_str="10Y1001A1001A450[EUROPE_EIC]",
6363
),
6464
DeliveryAreaTestCase(
65-
name="valid NERC code",
65+
name="valid_NERC_code",
6666
code="PJM",
6767
code_type=EnergyMarketCodeType.US_NERC,
6868
expected_str="PJM[US_NERC]",
6969
),
7070
DeliveryAreaTestCase(
71-
name="unspecified code type",
72-
code="TEST",
73-
code_type=EnergyMarketCodeType.UNSPECIFIED,
74-
expected_str="TEST[UNSPECIFIED]",
75-
),
76-
DeliveryAreaTestCase(
77-
name="no code",
71+
name="no_code",
7872
code=None,
7973
code_type=EnergyMarketCodeType.EUROPE_EIC,
8074
expected_str="<NO CODE>[EUROPE_EIC]",
8175
),
8276
DeliveryAreaTestCase(
83-
name="unknown code type",
77+
name="unspecified_code_type",
78+
code="TEST",
79+
code_type=EnergyMarketCodeType.UNSPECIFIED,
80+
expected_str="TEST[UNSPECIFIED]",
81+
),
82+
DeliveryAreaTestCase(
83+
name="unknown_code_type",
8484
code="TEST",
8585
code_type=999,
8686
expected_str="TEST[type=999]",
@@ -93,9 +93,6 @@ def test_creation(case: DeliveryAreaTestCase) -> None:
9393
9494
Args:
9595
case: Test case parameters
96-
97-
Raises:
98-
AssertionError: If any of the test assertions fail
9996
"""
10097
area = DeliveryArea(code=case.code, code_type=case.code_type)
10198
assert area.code == case.code
@@ -107,39 +104,39 @@ def test_creation(case: DeliveryAreaTestCase) -> None:
107104
"case",
108105
[
109106
ProtoConversionTestCase(
110-
name="valid EIC code",
107+
name="valid_EIC_code",
111108
code="10Y1001A1001A450",
112109
code_type=delivery_area_pb2.EnergyMarketCodeType.ENERGY_MARKET_CODE_TYPE_EUROPE_EIC,
113110
expected_code="10Y1001A1001A450",
114111
expected_code_type=EnergyMarketCodeType.EUROPE_EIC,
115112
expect_warning=False,
116113
),
117114
ProtoConversionTestCase(
118-
name="valid NERC code",
115+
name="valid_NERC_code",
119116
code="PJM",
120117
code_type=delivery_area_pb2.EnergyMarketCodeType.ENERGY_MARKET_CODE_TYPE_US_NERC,
121118
expected_code="PJM",
122119
expected_code_type=EnergyMarketCodeType.US_NERC,
123120
expect_warning=False,
124121
),
125122
ProtoConversionTestCase(
126-
name="no code",
123+
name="no_code",
127124
code=None,
128125
code_type=delivery_area_pb2.EnergyMarketCodeType.ENERGY_MARKET_CODE_TYPE_EUROPE_EIC,
129126
expected_code=None,
130127
expected_code_type=EnergyMarketCodeType.EUROPE_EIC,
131128
expect_warning=True,
132129
),
133130
ProtoConversionTestCase(
134-
name="unspecified type",
131+
name="unspecified_code_type",
135132
code="TEST",
136133
code_type=delivery_area_pb2.EnergyMarketCodeType.ENERGY_MARKET_CODE_TYPE_UNSPECIFIED,
137134
expected_code="TEST",
138135
expected_code_type=EnergyMarketCodeType.UNSPECIFIED,
139136
expect_warning=True,
140137
),
141138
ProtoConversionTestCase(
142-
name="unknown code type",
139+
name="unknown_code_type",
143140
code="TEST",
144141
code_type=999,
145142
expected_code="TEST",
@@ -157,9 +154,6 @@ def test_from_proto(
157154
Args:
158155
caplog: Fixture to capture log messages
159156
case: Test case parameters
160-
161-
Raises:
162-
AssertionError: If any of the test assertions fail
163157
"""
164158
# We do the type-ignore here because we want to test the case of an
165159
# arbitrary int too.

0 commit comments

Comments
 (0)