From f6b6bee5c287d2d6806000ed3ce2b7c605a2bb35 Mon Sep 17 00:00:00 2001 From: Justin Ibarra <16747370+brokensound77@users.noreply.github.com> Date: Thu, 21 Sep 2023 12:22:39 -0700 Subject: [PATCH] update transform test to fail on missing transform (#3085) Co-authored-by: brokensound77 Co-authored-by: Jonhnathan <26856693+w0rk3r@users.noreply.github.com> Co-authored-by: Terrance DeJesus <99630311+terrancedejesus@users.noreply.github.com> --- tests/test_all_rules.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/test_all_rules.py b/tests/test_all_rules.py index 6e56a91c82f..eaf7a86c7fd 100644 --- a/tests/test_all_rules.py +++ b/tests/test_all_rules.py @@ -1177,20 +1177,29 @@ def test_plugin_placeholders_match_entries(self): for rule in self.production_rules.rules: has_transform = rule.contents.get('transform') is not None has_note = rule.contents.data.get('note') is not None + note = rule.contents.data.note - if has_transform and not has_note: - self.fail(f'{self.rule_str(rule)} transformed defined with no note') - elif not has_transform: - continue + if has_transform: + if not has_note: + self.fail(f'{self.rule_str(rule)} transformed defined with no note') + else: + if not has_note: + continue + + note_template = PatchedTemplate(note) + identifiers = [i for i in note_template.get_identifiers() if '_' in i] + + if not has_transform: + if identifiers: + self.fail(f'{self.rule_str(rule)} note contains plugin placeholders with no transform entries') + else: + continue transform = rule.contents.transform transform_counts = {plugin: len(entries) for plugin, entries in transform.to_dict().items()} - note = rule.contents.data.note - self.assertIsNotNone(note) - note_template = PatchedTemplate(note) note_counts = defaultdict(int) - for identifier in note_template.get_identifiers(): + for identifier in identifiers: # "$" is used for other things, so this verifies the pattern of a trailing "_" followed by ints if '_' not in identifier: continue