From a093f9b86777067439c04de7c3dfeaa5d3a2ec68 Mon Sep 17 00:00:00 2001 From: juk0de Date: Thu, 31 Aug 2023 15:47:29 +0200 Subject: [PATCH] tags: some clarification and new tests --- chatmastermind/tags.py | 3 ++- tests/test_tags.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/chatmastermind/tags.py b/chatmastermind/tags.py index bb45a08..5ea1a3a 100644 --- a/chatmastermind/tags.py +++ b/chatmastermind/tags.py @@ -77,7 +77,8 @@ def match_tags(tags: set[Tag], tags_or: Optional[set[Tag]], tags_and: Optional[s i. e. you can select a TagLine if it either contains one of the tags in 'tags_or' or all of the tags in 'tags_and' but it must never contain any of the tags in 'tags_not'. If 'tags_or' and 'tags_and' are 'None', they match all tags (tag - exclusion is still done if 'tags_not' is not 'None'). + exclusion is still done if 'tags_not' is not 'None'). If they are empty (set()), + they match no tags. """ required_tags_present = False excluded_tags_missing = False diff --git a/tests/test_tags.py b/tests/test_tags.py index eeab199..aa89a06 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -144,3 +144,20 @@ class TestTagLine(CmmTestCase): # Test case 9: 'tags_or' and 'tags_and' are None, match all tags except excluded tags tags_not = {Tag('tag2')} self.assertFalse(tagline.match_tags(None, None, tags_not)) + + # Test case 10: 'tags_or' and 'tags_and' are empty, match no tags + self.assertFalse(tagline.match_tags(set(), set(), None)) + + # Test case 11: 'tags_or' is empty, match no tags + self.assertFalse(tagline.match_tags(set(), None, None)) + + # Test case 12: 'tags_and' is empty, match no tags + self.assertFalse(tagline.match_tags(None, set(), None)) + + # Test case 13: 'tags_or' is empty, match 'tags_and' + tags_and = {Tag('tag1'), Tag('tag2')} + self.assertTrue(tagline.match_tags(None, tags_and, None)) + + # Test case 14: 'tags_and' is empty, match 'tags_or' + tags_or = {Tag('tag1'), Tag('tag2')} + self.assertTrue(tagline.match_tags(tags_or, None, None))