From 214dcd1d76e15c2728e6070a35ae73e274dfc5b6 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 18 Sep 2024 11:14:30 -0500 Subject: [PATCH] fixup! Add tests for rosdep checks --- test/test_rosdep_checks.py | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/test_rosdep_checks.py b/test/test_rosdep_checks.py index 9bf8249..c205d73 100644 --- a/test/test_rosdep_checks.py +++ b/test/test_rosdep_checks.py @@ -300,7 +300,8 @@ def test_control(rosdep_repo): repo_dir = Path(rosdep_repo.working_tree_dir) extension = RosdepAnalyzer() - for file_name, data in VIOLATIONS['*'].items(): + rules = _merge_two_rules(EXISTING_RULES, CONTROL_RULES) + for file_name, data in rules.items(): file_path = repo_dir / 'rosdep' / file_name with file_path.open('w') as f: yaml.dump(data, f) @@ -310,6 +311,46 @@ def test_control(rosdep_repo): assert all(Recommendation.APPROVE == c.recommendation for c in criteria) +def test_target_ref(rosdep_repo): + repo_dir = Path(rosdep_repo.working_tree_dir) + extension = RosdepAnalyzer() + + rules = _merge_two_rules(EXISTING_RULES, CONTROL_RULES) + for file_name, data in rules.items(): + file_path = repo_dir / 'rosdep' / file_name + with file_path.open('w') as f: + yaml.dump(data, f) + + rosdep_repo.index.add(file_path) + + rosdep_repo.index.commit('Add control rules') + + # Add some violations to the stage, choose set 'A' as candidate + rules = _merge_two_rules(rules, VIOLATIONS['A']) + for file_name, data in rules.items(): + file_path = repo_dir / 'rosdep' / file_name + with file_path.open('w') as f: + yaml.dump(data, f) + + criteria, annotations = extension.analyze(repo_dir, head_ref='HEAD') + assert criteria and not annotations + assert all(Recommendation.APPROVE == c.recommendation for c in criteria) + + criteria, annotations = extension.analyze(repo_dir) + assert criteria and annotations + assert any(Recommendation.APPROVE != c.recommendation for c in criteria) + + +def test_removal_only(rosdep_repo): + repo_dir = Path(rosdep_repo.working_tree_dir) + extension = RosdepAnalyzer() + + for file_name in EXISTING_RULES.keys(): + (repo_dir / 'rosdep' / file_name).write_text('') + + assert (None, None) == extension.analyze(repo_dir) + + def test_violation(rosdep_repo, violation_rules): repo_dir = Path(rosdep_repo.working_tree_dir) extension = RosdepAnalyzer()