Compare commits
2 Commits
47ca1037db
...
87fc0fe075
| Author | SHA1 | Date | |
|---|---|---|---|
| 87fc0fe075 | |||
| 659ed2dac5 |
@ -103,24 +103,14 @@ class TagLine(str):
|
||||
new_tags.add(t[1])
|
||||
return self.from_set(set(sorted(new_tags)))
|
||||
|
||||
def match_tags(self, tags_or: set[Tag], tags_and: set[Tag], tags_not: set[Tag]) -> bool:
|
||||
"""
|
||||
Checks if the current TagLine matches the given tag requirements:
|
||||
- 'tags_or' : matches if this TagLine contains ANY of those tags
|
||||
- 'tags_and': matches if this TagLine contains ALL of those tags
|
||||
- 'tags_not': matches if this TagLine contains NONE of those tags
|
||||
|
||||
Note that it's sufficient if the TagLine matches one of 'tags_or' or 'tags_and',
|
||||
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'.
|
||||
"""
|
||||
tag_set = self.tags()
|
||||
required_tags_present = False
|
||||
excluded_tags_missing = False
|
||||
if ((tags_or and any(tag in tag_set for tag in tags_or))
|
||||
or (tags_and and all(tag in tag_set for tag in tags_and))): # noqa: W503
|
||||
required_tags_present = True
|
||||
if not any(tag in tag_set for tag in tags_not):
|
||||
excluded_tags_missing = True
|
||||
return required_tags_present and excluded_tags_missing
|
||||
# def match_tags(self, tags_or: set[Tag], tags_and:set[Tag], tags_not: set[Tag]) -> 'TagLine':
|
||||
# """
|
||||
# Checks if the current TagLine matches the given tag requirements:
|
||||
# - 'tags_or' : matches if this TagLine contains ANY of those tags
|
||||
# - 'tags_and': matches if this TagLine contains ALL of those tags
|
||||
# - 'tags_not': matches if this TagLine contains NONE of those tags
|
||||
#
|
||||
# Note that it's sufficient if the TagLine matches one of 'tags_or' or 'tags_and',
|
||||
# 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'.
|
||||
|
||||
@ -292,48 +292,3 @@ class TestTagLine(CmmTestCase):
|
||||
tagline = TagLine('TAGS: old1 old2')
|
||||
new_tagline = tagline.rename_tags({(Tag('old1'), Tag('new1')), (Tag('old2'), Tag('new2'))})
|
||||
self.assertEqual(new_tagline, 'TAGS: new1 new2')
|
||||
|
||||
def test_match_tags(self) -> None:
|
||||
tagline = TagLine('TAGS: tag1 tag2 tag3')
|
||||
|
||||
# Test case 1: Match any tag in 'tags_or'
|
||||
tags_or = {Tag('tag1'), Tag('tag4')}
|
||||
tags_and: set[Tag] = set()
|
||||
tags_not: set[Tag] = set()
|
||||
self.assertTrue(tagline.match_tags(tags_or, tags_and, tags_not))
|
||||
|
||||
# Test case 2: Match all tags in 'tags_and'
|
||||
tags_or = set()
|
||||
tags_and = {Tag('tag1'), Tag('tag2'), Tag('tag3')}
|
||||
tags_not = set()
|
||||
self.assertTrue(tagline.match_tags(tags_or, tags_and, tags_not))
|
||||
|
||||
# Test case 3: Match any tag in 'tags_or' and match all tags in 'tags_and'
|
||||
tags_or = {Tag('tag1'), Tag('tag4')}
|
||||
tags_and = {Tag('tag1'), Tag('tag2')}
|
||||
tags_not = set()
|
||||
self.assertTrue(tagline.match_tags(tags_or, tags_and, tags_not))
|
||||
|
||||
# Test case 4: Match any tag in 'tags_or', match all tags in 'tags_and', and exclude tags in 'tags_not'
|
||||
tags_or = {Tag('tag1'), Tag('tag4')}
|
||||
tags_and = {Tag('tag1'), Tag('tag2')}
|
||||
tags_not = {Tag('tag5')}
|
||||
self.assertTrue(tagline.match_tags(tags_or, tags_and, tags_not))
|
||||
|
||||
# Test case 5: No matching tags in 'tags_or'
|
||||
tags_or = {Tag('tag4'), Tag('tag5')}
|
||||
tags_and = set()
|
||||
tags_not = set()
|
||||
self.assertFalse(tagline.match_tags(tags_or, tags_and, tags_not))
|
||||
|
||||
# Test case 6: Not all tags in 'tags_and' are present
|
||||
tags_or = set()
|
||||
tags_and = {Tag('tag1'), Tag('tag2'), Tag('tag3'), Tag('tag4')}
|
||||
tags_not = set()
|
||||
self.assertFalse(tagline.match_tags(tags_or, tags_and, tags_not))
|
||||
|
||||
# Test case 7: Some tags in 'tags_not' are present
|
||||
tags_or = set()
|
||||
tags_and = set()
|
||||
tags_not = {Tag('tag2')}
|
||||
self.assertFalse(tagline.match_tags(tags_or, tags_and, tags_not))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user