Skip to content

Commit 9fb9e43

Browse files
Return warnings for duplicate and empty license aliases
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
1 parent 2efada2 commit 9fb9e43

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/license_expression/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,8 +1764,8 @@ def validate_symbols(symbols, validate_keys=False):
17641764
errors.append(f"Invalid key: a key cannot be an expression keyword: {ikw}.")
17651765

17661766
warnings = []
1767-
for dupe_alias in sorted(dupe_aliases):
1768-
errors.append(f"Duplicated or empty aliases ignored for license key: {dupe_alias!r}.")
1767+
for key in sorted(warning_dupe_aliases):
1768+
warnings.append(f"Duplicated or empty aliases ignored for license key: {key!r}.")
17691769

17701770
return warnings, errors
17711771

tests/test_license_expression.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,3 +2640,29 @@ def test_combine_expressions_with_duplicated_elements(self):
26402640

26412641
def test_combine_expressions_with_or_relationship(self):
26422642
assert str(combine_expressions(["mit", "apache-2.0"], "OR")) == "mit OR apache-2.0"
2643+
2644+
2645+
def test_validate_symbols_reports_duplicate_and_empty_alias_warnings():
2646+
symbols = [
2647+
LicenseSymbol("mit", aliases=["MIT license", "mit license"]),
2648+
LicenseSymbol("apache-2.0", aliases=[""]),
2649+
]
2650+
warnings, errors = validate_symbols(symbols)
2651+
assert errors == []
2652+
assert warnings == [
2653+
"Duplicated or empty aliases ignored for license key: 'apache-2.0'.",
2654+
"Duplicated or empty aliases ignored for license key: 'mit'.",
2655+
]
2656+
2657+
2658+
def test_validate_symbols_keeps_conflicting_aliases_as_errors():
2659+
warnings, errors = validate_symbols(
2660+
[
2661+
LicenseSymbol("mit", aliases=["shared"]),
2662+
LicenseSymbol("apache-2.0", aliases=["shared"]),
2663+
]
2664+
)
2665+
assert warnings == []
2666+
assert errors == [
2667+
"Invalid duplicated alias pointing to multiple keys: " "shared point to keys: 'apache-2.0'."
2668+
]

0 commit comments

Comments
 (0)