summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/code-modernization/scripts')
-rw-r--r--plugins/code-modernization/scripts/render_rules.py7
-rw-r--r--plugins/code-modernization/scripts/tests/test_rules_tools.py3
2 files changed, 7 insertions, 3 deletions
diff --git a/plugins/code-modernization/scripts/render_rules.py b/plugins/code-modernization/scripts/render_rules.py
index da375f55..88d75625 100644
--- a/plugins/code-modernization/scripts/render_rules.py
+++ b/plugins/code-modernization/scripts/render_rules.py
@@ -5,7 +5,7 @@
Reads analysis/<system>/rules_result.json (the object the workflow returned, saved by the
command) and writes analysis/<system>/BUSINESS_RULES.md and DATA_OBJECTS.md. Rules are
-numbered RULE-001, RULE-002, ... in priority then category order and the heading is always
+numbered RULE-001, RULE-002, ... in the order they appear (by category, then priority) and the heading is always
`### RULE-NNN: <name>`, the pattern later commands and the pane look for. Every value comes
from analysis of untrusted code, so it is written as plain text on one line where it is
a heading or a table cell. Standard library only.
@@ -83,9 +83,10 @@ def main(argv):
print(f'Cannot read {result_path}: {error}', file=sys.stderr)
return 1
+ # Numbered in the order they appear in the document (by category, then priority), so RULE-001.. read in sequence.
rules = sorted(result.get('confirmedRules') or [],
- key=lambda r: (PRIORITY.get(r.get('priority'), 1),
- CATEGORIES.index(r['category']) if r.get('category') in CATEGORIES else 9,
+ key=lambda r: (CATEGORIES.index(r['category']) if r.get('category') in CATEGORIES else 9,
+ PRIORITY.get(r.get('priority'), 1),
str(r.get('source'))))
numbered = [(i + 1, r) for i, r in enumerate(rules)]
rendered = {n: render_rule(n, r) for n, r in numbered}
diff --git a/plugins/code-modernization/scripts/tests/test_rules_tools.py b/plugins/code-modernization/scripts/tests/test_rules_tools.py
index f0bbc391..632b2250 100644
--- a/plugins/code-modernization/scripts/tests/test_rules_tools.py
+++ b/plugins/code-modernization/scripts/tests/test_rules_tools.py
@@ -1,5 +1,6 @@
import json
import os
+import re
import subprocess
import sys
import tempfile
@@ -149,6 +150,8 @@ class RenderTests(unittest.TestCase):
headings = [line for line in text.splitlines() if line.startswith('### ')]
self.assertEqual(len(headings), 2, headings)
self.assertNotIn('\n# injected heading', text)
+ ids = [int(n) for n in re.findall(r'^### RULE-(\d+): ', text, re.M)]
+ self.assertEqual(ids, list(range(1, len(ids) + 1)), 'rule numbers read in sequence down the document')
self.assertIn('Rules requiring SME confirmation', text)
self.assertIn('Is it 5 or 6?', text)
self.assertIn('Coverage gaps', text)