From 57501f2725b2bb917c99006cd283cc7c6ba0e72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20W=C3=BCnsche?= Date: Mon, 16 Dec 2024 13:15:13 +0100 Subject: [PATCH] Fix KeyError on double deletion --- piplicenses.py | 2 +- test_piplicenses.py | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/piplicenses.py b/piplicenses.py index b2e09ef..bbd3285 100755 --- a/piplicenses.py +++ b/piplicenses.py @@ -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 diff --git a/test_piplicenses.py b/test_piplicenses.py index ca5623b..f473d95 100644 --- a/test_piplicenses.py +++ b/test_piplicenses.py @@ -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."