Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ The following organizations or individuals have contributed to ScanCode:
- Yash Sharma @yasharmaster
- Yunus Rahbar @yns88
- Stefano Zacchiroli @zacchiro
- Harish Wargad @harishwargad
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Next release
``licensedcode-data``.
https://github.com/aboutcode-org/scancode-toolkit/pull/5056

- Ensure each license rule has a unique generated validation
test name, by renaming colliding rule files and adding a
regression test to prevent rule name collisions.
https://github.com/aboutcode-org/scancode-toolkit/issues/5257

- Improve copyright detection for statements with parens or trailing "authors"


Expand Down
21 changes: 21 additions & 0 deletions tests/licensedcode/test_rule_file_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from collections import defaultdict

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like more the rule renames at https://github.com/aboutcode-org/scancode-toolkit/pull/5258/changes
cnri-python-1.6_1.RULE -> cnri-python-1.6_19.RULE
proprietary_10_alt.RULE -> proprietary_155.RULE

from pathlib import Path

from commoncode.text import python_safe_name
from licensedcode.models import rules_data_dir


def test_rule_file_names_generate_unique_test_method_names():
method_to_files = defaultdict(list)

for rule_file in Path(rules_data_dir).glob("*.RULE"):
method_name = python_safe_name(rule_file.stem)
method_to_files[method_name].append(rule_file.name)

duplicate_names = [
(method_name, files)
for method_name, files in method_to_files.items()
if len(files) > 1
]

assert not duplicate_names, f"Duplicate test method names found: {duplicate_names}"