Skip to content

Commit 5ea2849

Browse files
committed
Update tests and add doc
1 parent d013de4 commit 5ea2849

File tree

2 files changed

+67
-22
lines changed

2 files changed

+67
-22
lines changed

logprep/processor/generic_resolver/rule.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
resolve_list:
2929
.*Hello.*: Greeting
3030
31+
Alternatively for yaml compliance it is possible to declare the resolve_list like so, to keep
32+
ordering when using the config from different programs. Both styles will be supported in the
33+
future, this one is recommended for clarity and yaml compliance.
34+
.. code-block:: yaml
35+
:linenos:
36+
:caption: Example
37+
38+
filter: to_resolve
39+
generic_resolver:
40+
field_mapping:
41+
to_resolve: resolved
42+
resolve_list:
43+
- .*Hello.*: Greeting
44+
3145
Alternatively, a YML file with a resolve list and a regex pattern can be used to resolve values.
3246
For this, a field :code:`resolve_from_file` with the subfields :code:`path` and :code:`pattern`
3347
must be added.

tests/unit/processor/generic_resolver/test_generic_resolver_rule.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ def fixture_rule_definition():
3636

3737
class TestGenericResolverRule:
3838
@pytest.mark.parametrize(
39-
"testcase, other_rule_definition, is_equal",
39+
["other_rule_definition", "is_equal"],
4040
[
41-
(
42-
"Should be equal cause the same",
41+
pytest.param(
4342
{
4443
"filter": "message",
4544
"generic_resolver": {
@@ -53,9 +52,9 @@ class TestGenericResolverRule:
5352
},
5453
},
5554
True,
55+
id="should_be_equal_same",
5656
),
57-
(
58-
"Should be equal cause without merge_with_target, since default is the same",
57+
pytest.param(
5958
{
6059
"filter": "message",
6160
"generic_resolver": {
@@ -68,9 +67,9 @@ class TestGenericResolverRule:
6867
},
6968
},
7069
True,
70+
id="should_be_equal_default_same",
7171
),
72-
(
73-
"Should be not equal cause of other filter",
72+
pytest.param(
7473
{
7574
"filter": "other_message",
7675
"generic_resolver": {
@@ -84,9 +83,9 @@ class TestGenericResolverRule:
8483
},
8584
},
8685
False,
86+
id="should_not_be_equal_other_filter",
8787
),
88-
(
89-
"Should be not equal cause of other field_mapping",
88+
pytest.param(
9089
{
9190
"filter": "message",
9291
"generic_resolver": {
@@ -100,9 +99,9 @@ class TestGenericResolverRule:
10099
},
101100
},
102101
False,
102+
id="should_not_be_equal_other_field_mapping",
103103
),
104-
(
105-
"Should be not equal cause of other resolve_list",
104+
pytest.param(
106105
{
107106
"filter": "message",
108107
"generic_resolver": {
@@ -116,9 +115,9 @@ class TestGenericResolverRule:
116115
},
117116
},
118117
False,
118+
id="should_not_be_equal_other_resolve_list",
119119
),
120-
(
121-
"Should be not equal cause of no resolve_list",
120+
pytest.param(
122121
{
123122
"filter": "message",
124123
"generic_resolver": {
@@ -131,9 +130,9 @@ class TestGenericResolverRule:
131130
},
132131
},
133132
False,
133+
id="should_not_be_equal_no_resolve_list",
134134
),
135-
(
136-
"Should be not equal cause of other resolve_from_file",
135+
pytest.param(
137136
{
138137
"filter": "message",
139138
"generic_resolver": {
@@ -147,9 +146,9 @@ class TestGenericResolverRule:
147146
},
148147
},
149148
False,
149+
id="should_not_be_equal_other_resolve_from_file",
150150
),
151-
(
152-
"Should be not equal cause of no resolve_from_file",
151+
pytest.param(
153152
{
154153
"filter": "message",
155154
"generic_resolver": {
@@ -159,18 +158,47 @@ class TestGenericResolverRule:
159158
},
160159
},
161160
False,
161+
id="should_not_be_equal_no_resolve_from_file",
162+
),
163+
pytest.param(
164+
{
165+
"filter": "message",
166+
"generic_resolver": {
167+
"field_mapping": {"to_resolve": "resolved"},
168+
"resolve_list": [{"pattern": "result"}, {"pattern2": "result2"}],
169+
"merge_with_target": False,
170+
},
171+
},
172+
False,
173+
id="should_not_be_equal_no_resolve_from_file_with_resolve_list_sequence",
174+
),
175+
pytest.param(
176+
{
177+
"filter": "message",
178+
"generic_resolver": {
179+
"field_mapping": {"to_resolve": "resolved"},
180+
"resolve_list": [{"pattern": "result"}],
181+
"resolve_from_file": {
182+
"path": "tests/testdata/unit/generic_resolver/resolve_mapping.yml",
183+
"pattern": r"\d*(?P<mapping>[a-z]+)\d*",
184+
},
185+
"merge_with_target": False,
186+
},
187+
},
188+
True,
189+
id="should_be_equal_same_with_resolve_list_sequence",
162190
),
163191
],
164192
)
165-
def test_rules_equality(self, rule_definition, testcase, other_rule_definition, is_equal):
193+
def test_rules_equality(self, rule_definition, other_rule_definition, is_equal):
166194
rule1 = GenericResolverRule.create_from_dict(rule_definition)
167195
rule2 = GenericResolverRule.create_from_dict(other_rule_definition)
168-
assert (rule1 == rule2) == is_equal, testcase
196+
assert (rule1 == rule2) == is_equal
169197

170198
@pytest.mark.parametrize(
171199
["rule", "error", "message"],
172200
[
173-
(
201+
pytest.param(
174202
{
175203
"filter": "to_resolve",
176204
"generic_resolver": {
@@ -184,8 +212,9 @@ def test_rules_equality(self, rule_definition, testcase, other_rule_definition,
184212
},
185213
InvalidConfigurationError,
186214
"Mapping group is missing in mapping",
215+
id="missing_mapping_group",
187216
),
188-
(
217+
pytest.param(
189218
{
190219
"filter": "to.resolve",
191220
"generic_resolver": {
@@ -198,8 +227,9 @@ def test_rules_equality(self, rule_definition, testcase, other_rule_definition,
198227
},
199228
InvalidConfigurationError,
200229
"Additions file 'foo' not found",
230+
id="no_additional_file_found",
201231
),
202-
(
232+
pytest.param(
203233
{
204234
"filter": "to.resolve",
205235
"generic_resolver": {
@@ -213,6 +243,7 @@ def test_rules_equality(self, rule_definition, testcase, other_rule_definition,
213243
InvalidConfigurationError,
214244
r"Error loading additions from '.+resolve_mapping_list\.yml': "
215245
r"Value is not a dictionary",
246+
id="error_loading_not_dict_value",
216247
),
217248
],
218249
)

0 commit comments

Comments
 (0)