Skip to content

Commit 2d1bcd8

Browse files
committed
change error message
Signed-off-by: zhen0427 <[email protected]>
1 parent abcb3f4 commit 2d1bcd8

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

tests/unit/converters/test_tabular_converter.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -108,50 +108,50 @@ def test_convert_table_to_component(converter: TabularConverter, tabular_data_no
108108
# if table does not exist in data _convert_table_to_component should return None
109109
none_data = converter._convert_table_to_component(
110110
data=tabular_data_no_units_no_substitutions,
111-
data_type="input",
111+
data_type=DatasetType.input,
112112
table="some_random_table",
113113
component=ComponentType.node,
114114
attributes={"key": "value"},
115115
extra_info=None,
116116
)
117117
assert none_data is None
118118
# wrong component
119-
with pytest.raises(KeyError, match="Invalid component type 'dummy' or data type 'input'"):
119+
with pytest.raises(KeyError, match="Invalid component type \'dummy\' or data type \'DatasetType.input\'"):
120120
converter._convert_table_to_component(
121121
data=tabular_data_no_units_no_substitutions,
122-
data_type="input",
122+
data_type=DatasetType.input,
123123
table="nodes",
124124
component="dummy",
125125
attributes={"key": "value"},
126126
extra_info=None,
127127
)
128128
# wrong data_type
129-
with pytest.raises(KeyError, match="Invalid component type 'node' or data type 'some_type'"):
129+
with pytest.raises(KeyError, match="Invalid component type \'ComponentType.node\' or data type 'some_type'"):
130130
converter._convert_table_to_component(
131131
data=tabular_data_no_units_no_substitutions,
132132
data_type="some_type",
133133
table="nodes",
134-
component="node",
134+
component=ComponentType.node,
135135
attributes={"key": "value"},
136136
extra_info=None,
137137
)
138138
# no 'id' in attributes
139-
with pytest.raises(KeyError, match="No mapping for the attribute 'id' for 'nodes'!"):
139+
with pytest.raises(KeyError, match="No mapping for the attribute \'id\' for \'ComponentType.nodes\'!"):
140140
converter._convert_table_to_component(
141141
data=tabular_data_no_units_no_substitutions,
142-
data_type="input",
142+
data_type=DatasetType.input,
143143
table="nodes",
144-
component="node",
144+
component=ComponentType.node,
145145
attributes={"key": "value"},
146146
extra_info=None,
147147
)
148148

149149
node_attributes: InstanceAttributes = {"id": "id_number", "u_rated": "u_nom"}
150150
pgm_node_data = converter._convert_table_to_component(
151151
data=tabular_data_no_units_no_substitutions,
152-
data_type="input",
152+
data_type=DatasetType.input,
153153
table="nodes",
154-
component="node",
154+
component=ComponentType.node,
155155
attributes=node_attributes,
156156
extra_info=None,
157157
)
@@ -182,7 +182,7 @@ def test_convert_table_to_component__filters(
182182
data=tabular_data_no_units_no_substitutions,
183183
data_type="input",
184184
table="nodes",
185-
component="node",
185+
component=ComponentType.node,
186186
attributes=node_attributes_with_filter,
187187
extra_info=None,
188188
)
@@ -213,9 +213,9 @@ def test_convert_table_to_component__filters_all_false(
213213
}
214214
actual = converter._convert_table_to_component(
215215
data=tabular_data_no_units_no_substitutions,
216-
data_type="input",
216+
data_type=DatasetType.input,
217217
table="nodes",
218-
component="node",
218+
component=ComponentType.node,
219219
attributes=node_attributes_with_filter,
220220
extra_info=None,
221221
)
@@ -236,13 +236,13 @@ def test_convert_col_def_to_attribute(
236236
):
237237
with pytest.raises(
238238
KeyError,
239-
match=r"Could not find attribute 'incorrect_attribute' for 'nodes'. \(choose from: id, u_rated\)",
239+
match=r"Could not find attribute \'incorrect_attribute\' for \'ComponentType.nodes\'. \(choose from: id, u_rated\)",
240240
):
241241
converter._convert_col_def_to_attribute(
242242
data=tabular_data_no_units_no_substitutions,
243-
pgm_data=pgm_node_empty["node"],
243+
pgm_data=pgm_node_empty[ComponentType.node],
244244
table="nodes",
245-
component="node",
245+
component=ComponentType.node,
246246
attr="incorrect_attribute",
247247
col_def="id_number",
248248
table_mask=None,
@@ -252,9 +252,9 @@ def test_convert_col_def_to_attribute(
252252
# test extra info
253253
converter._convert_col_def_to_attribute(
254254
data=tabular_data_no_units_no_substitutions,
255-
pgm_data=pgm_node_empty["node"],
255+
pgm_data=pgm_node_empty[ComponentType.node],
256256
table="nodes",
257-
component="node",
257+
component=ComponentType.node,
258258
attr="extra",
259259
col_def="u_nom",
260260
table_mask=None,
@@ -264,27 +264,27 @@ def test_convert_col_def_to_attribute(
264264
# test other attr
265265
converter._convert_col_def_to_attribute(
266266
data=tabular_data_no_units_no_substitutions,
267-
pgm_data=pgm_node_empty["node"],
267+
pgm_data=pgm_node_empty[ComponentType.node],
268268
table="nodes",
269-
component="node",
269+
component=ComponentType.node,
270270
attr="u_rated",
271271
col_def="u_nom",
272272
table_mask=None,
273273
extra_info=None,
274274
)
275275
assert len(pgm_node_empty) == 1
276-
assert (pgm_node_empty["node"]["u_rated"] == [10500.0, 400.0]).all()
276+
assert (pgm_node_empty[ComponentType.node]["u_rated"] == [10500.0, 400.0]).all()
277277

278278
with pytest.raises(
279279
ValueError,
280-
match=r"DataFrame for node.u_rated should contain a single column "
280+
match=r"DataFrame for ComponentType.node.u_rated should contain a single column "
281281
r"\(Index\(\['id_number', 'u_nom'\], dtype='object'\)\)",
282282
):
283283
converter._convert_col_def_to_attribute(
284284
data=tabular_data_no_units_no_substitutions,
285-
pgm_data=pgm_node_empty["node"],
285+
pgm_data=pgm_node_empty[ComponentType.node],
286286
table="nodes",
287-
component="node",
287+
component=ComponentType.node,
288288
attr="u_rated",
289289
col_def=["id_number", "u_nom"],
290290
table_mask=None,
@@ -340,16 +340,16 @@ def test_handle_extra_info__units(converter: TabularConverter, tabular_data: Tab
340340

341341

342342
def test_merge_pgm_data(converter: TabularConverter):
343-
nodes_1 = initialize_array("input", "node", 2)
343+
nodes_1 = initialize_array(DatasetType.input, ComponentType.node, 2)
344344
nodes_1["id"] = [0, 1]
345345

346-
nodes_2 = initialize_array("input", "node", 3)
346+
nodes_2 = initialize_array(DatasetType.input, ComponentType.node, 3)
347347
nodes_2["id"] = [2, 3, 4]
348-
data = {"node": [nodes_1, nodes_2]}
348+
data = {ComponentType.node: [nodes_1, nodes_2]}
349349

350350
merged = converter._merge_pgm_data(data)
351351
assert len(merged) == 1
352-
assert (merged["node"]["id"] == np.array([0, 1, 2, 3, 4])).all()
352+
assert (merged[ComponentType.node]["id"] == np.array([0, 1, 2, 3, 4])).all()
353353

354354

355355
def test_serialize_data(converter: TabularConverter, pgm_node_empty: SingleDataset):
@@ -364,12 +364,12 @@ def test_serialize_data(converter: TabularConverter, pgm_node_empty: SingleDatas
364364
):
365365
converter._serialize_data(data=[], extra_info=None) # type: ignore
366366

367-
pgm_node_empty["node"]["id"] = [1, 2]
368-
pgm_node_empty["node"]["u_rated"] = [3.0, 4.0]
367+
pgm_node_empty[ComponentType.node]["id"] = [1, 2]
368+
pgm_node_empty[ComponentType.node]["u_rated"] = [3.0, 4.0]
369369
tabular_data = converter._serialize_data(data=pgm_node_empty, extra_info=None)
370370
assert len(tabular_data) == 1
371-
assert (tabular_data["node"]["id"] == np.array([1, 2])).all()
372-
assert (tabular_data["node"]["u_rated"] == np.array([3.0, 4.0])).all()
371+
assert (tabular_data[ComponentType.node]["id"] == np.array([1, 2])).all()
372+
assert (tabular_data[ComponentType.node]["u_rated"] == np.array([3.0, 4.0])).all()
373373

374374

375375
def test_parse_col_def(converter: TabularConverter, tabular_data_no_units_no_substitutions: TabularData):

0 commit comments

Comments
 (0)