Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError on double deletion #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def case_insensitive_partial_match_set_diff(set_a, set_b):
for item_a in set_a:
for item_b in set_b:
if item_b.lower() in item_a.lower():
uncommon_items.remove(item_a)
uncommon_items.discard(item_a)
return uncommon_items


Expand Down
51 changes: 51 additions & 0 deletions test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,54 @@ def test_pyproject_toml_args_parsed_correctly():
assert args.fail_on == tool_conf["fail-on"]

os.unlink(temp_file.name)


def test_case_insensitive_partial_match_set_diff():
set_a = {"Python", "Java", "C++"}
set_b = {"Ruby", "JavaScript"}
result = case_insensitive_partial_match_set_diff(set_a, set_b)
assert (
result == set_a
), "When no overlap, the result should be the same as set_a."

set_a = {"Hello", "World"}
set_b = {"hello", "world"}
result = case_insensitive_partial_match_set_diff(set_a, set_b)
assert (
result == set()
), "When all items overlap, the result should be an empty set."

set_a = {"HelloWorld", "Python", "JavaScript"}
set_b = {"hello", "script"}
result = case_insensitive_partial_match_set_diff(set_a, set_b)
assert result == {
"Python"
}, "Only 'Python' should remain as it has no overlap with set_b."

set_a = {"HELLO", "world"}
set_b = {"hello"}
result = case_insensitive_partial_match_set_diff(set_a, set_b)
assert result == {
"world"
}, "The function should handle case-insensitive matches correctly."

set_a = set()
set_b = set()
result = case_insensitive_partial_match_set_diff(set_a, set_b)
assert (
result == set()
), "When both sets are empty, the result should also be empty."

set_a = {"Python", "Java"}
set_b = set()
result = case_insensitive_partial_match_set_diff(set_a, set_b)
assert (
result == set_a
), "If set_b is empty, result should be the same as set_a."

set_a = set()
set_b = {"Ruby"}
result = case_insensitive_partial_match_set_diff(set_a, set_b)
assert (
result == set()
), "If set_a is empty, result should be empty regardless of set_b."