Skip to content

Commit 0ea3e44

Browse files
committed
Convert from file load, fix tests, fix Key and Value vartypes
1 parent ce29d3b commit 0ea3e44

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

logprep/processor/generic_resolver/rule.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ def _add_from_path(self, path: str):
234234

235235
def _get_additions_from_path(self, path: str) -> dict:
236236
try:
237-
additions = GetterFactory.from_string(path).get_dict()
237+
additions = GetterFactory.from_string(path).get_collection()
238+
additions = convert_ordered_mapping_or_keep_mapping(additions)
238239
except ValueError as error:
239240
raise InvalidConfigurationError(
240241
f"Error loading additions from '{path}': {error}"

logprep/util/converters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
from logprep.factory_error import InvalidConfigurationError
44

5-
KeyTypeT = TypeVar("KeyTypeT")
6-
ValueTypeT = TypeVar("ValueTypeT")
5+
Key = TypeVar("Key")
6+
Value = TypeVar("Value")
77

88

99
def convert_ordered_mapping_or_keep_mapping(
10-
dict_or_sequence: dict[KeyTypeT, ValueTypeT] | list[dict[KeyTypeT, ValueTypeT]],
11-
) -> dict[KeyTypeT, ValueTypeT]:
10+
dict_or_sequence: dict[Key, Value] | list[dict[Key, Value]],
11+
) -> dict[Key, Value]:
1212
if isinstance(dict_or_sequence, dict):
1313
return dict_or_sequence
1414

@@ -18,7 +18,7 @@ def convert_ordered_mapping_or_keep_mapping(
1818
return convert_ordered_mapping(dict_or_sequence)
1919

2020

21-
def convert_ordered_mapping(dicts: list[dict[KeyTypeT, ValueTypeT]]) -> dict[KeyTypeT, ValueTypeT]:
21+
def convert_ordered_mapping(dicts: list[dict[Key, Value]]) -> dict[Key, Value]:
2222
ordered_mapping = {}
2323
for element in dicts:
2424
keys = list(element.keys())

tests/unit/processor/generic_resolver/test_generic_resolver_rule.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,8 @@ def test_rules_equality(self, rule_definition, other_rule_definition, is_equal):
240240
},
241241
},
242242
},
243-
InvalidConfigurationError,
244-
r"Error loading additions from '.+resolve_mapping_list\.yml': "
245-
r"Value is not a dictionary",
243+
None,
244+
"",
246245
id="error_loading_not_dict_value",
247246
),
248247
],

0 commit comments

Comments
 (0)