summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/scripts/tests/test_rules_tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/code-modernization/scripts/tests/test_rules_tools.py')
-rw-r--r--plugins/code-modernization/scripts/tests/test_rules_tools.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/plugins/code-modernization/scripts/tests/test_rules_tools.py b/plugins/code-modernization/scripts/tests/test_rules_tools.py
index 80590b0a..7ff5af6c 100644
--- a/plugins/code-modernization/scripts/tests/test_rules_tools.py
+++ b/plugins/code-modernization/scripts/tests/test_rules_tools.py
@@ -222,6 +222,29 @@ class ShardTests(unittest.TestCase):
shards = load(os.path.join(ws, 'analysis/s/extract-rules.modules.json'))
self.assertEqual([s.get('lines') for s in shards], [[1, 833], [834, 1666], [1667, 2500], None])
+ def test_both_depths_are_estimated(self):
+ with tempfile.TemporaryDirectory() as ws:
+ write(ws, 'legacy/tiny/a.sql', 'a\n' * 200)
+ self.assertIn('Standard 20 to 100 agents (about 0.3M to 1.6M tokens); Thorough 20 to 150 agents',
+ run('make_shards.py', 'tiny', '--workspace', ws).stdout)
+ write(ws, 'legacy/big/a.sql', 'a\n' * 10000)
+ self.assertIn('Standard 150 to 550 agents (about 2.4M to 8.8M tokens); Thorough 200 to 1900 agents (about 3.2M to 30.4M tokens)',
+ run('make_shards.py', 'big', '--workspace', ws).stdout)
+ for i in range(40):
+ write(ws, f'legacy/many/d{i}/a.sql', 'a\n' * 5)
+ self.assertIn('Standard 20 to 440 agents', run('make_shards.py', 'many', '--workspace', ws).stdout)
+ write(ws, 'legacy/small/a.sql', 'a\n' * 1001)
+ write(ws, 'legacy/small/x/b.sql', 'a\n' * 184)
+ self.assertIn('Standard 20 to 100 agents', run('make_shards.py', 'small', '--workspace', ws).stdout)
+
+ def test_the_estimate_counts_the_files_whatever_the_map_says(self):
+ with tempfile.TemporaryDirectory() as ws:
+ write(ws, 'legacy/s/A.cbl', 'a\n' * 1400)
+ for size in ({}, {'loc': 400}):
+ topology = {'root': {'kind': 'system', 'id': 'sys', 'children': [{'kind': 'module', 'id': 'A', 'name': 'A', 'file': 'A.cbl', **size}]}}
+ write(ws, 'analysis/s/topology.json', json.dumps(topology))
+ self.assertIn('Standard 30 to 80 agents', run('make_shards.py', 's', '--workspace', ws).stdout)
+
def test_missing_source_says_what_to_do(self):
with tempfile.TemporaryDirectory() as ws:
done = run('make_shards.py', 'nope', '--workspace', ws)
@@ -296,6 +319,14 @@ class RenderTests(unittest.TestCase):
with open(os.path.join(ws, 'analysis/s/BUSINESS_RULES.md'), encoding='utf-8') as handle:
self.assertIn('capped at 400.00', handle.read())
+ def test_the_depth_is_shown(self):
+ with tempfile.TemporaryDirectory() as ws:
+ for stats, times in (({'depth': 'thorough', 'agents': 7, 'estimate': 'Standard 20 to 100 agents;\nThorough 20 to 150'}, 1), ({}, 0)):
+ write(ws, 'analysis/s/rules_result.json', json.dumps({'confirmedRules': [], 'stats': stats}))
+ self.assertEqual(run('render_rules.py', 's', '--workspace', ws).returncode, 0)
+ with open(os.path.join(ws, 'analysis/s/BUSINESS_RULES.md'), encoding='utf-8') as handle:
+ self.assertEqual(handle.read().count('Extraction depth: thorough; 7 agents. Estimated before the run: Standard 20 to 100 agents; Thorough 20 to 150.'), times)
+
def test_unreadable_result_is_an_error(self):
with tempfile.TemporaryDirectory() as ws:
self.assertEqual(run('render_rules.py', 's', '--workspace', ws).returncode, 1)