fixed handling empty tags in TXT file
This commit is contained in:
parent
7f91a2b567
commit
169f1bb458
@ -124,6 +124,8 @@ class TagLine(str):
|
|||||||
filtered based on prefix or contained string.
|
filtered based on prefix or contained string.
|
||||||
"""
|
"""
|
||||||
tagstr = self[len(self.prefix):].strip()
|
tagstr = self[len(self.prefix):].strip()
|
||||||
|
if tagstr == '':
|
||||||
|
return set() # no tags, only prefix
|
||||||
separator = Tag.default_separator
|
separator = Tag.default_separator
|
||||||
# look for alternative separators and use the first one found
|
# look for alternative separators and use the first one found
|
||||||
# -> we don't support different separators in the same TagLine
|
# -> we don't support different separators in the same TagLine
|
||||||
|
|||||||
@ -556,6 +556,15 @@ This is an answer.
|
|||||||
This is a question.
|
This is a question.
|
||||||
{Answer.txt_header}
|
{Answer.txt_header}
|
||||||
This is an answer.
|
This is an answer.
|
||||||
|
""")
|
||||||
|
self.file_txt_tags_empty = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
||||||
|
self.file_path_txt_tags_empty = pathlib.Path(self.file_txt_tags_empty.name)
|
||||||
|
with open(self.file_path_txt_tags_empty, "w") as fd:
|
||||||
|
fd.write(f"""TAGS:
|
||||||
|
{Question.txt_header}
|
||||||
|
This is a question.
|
||||||
|
{Answer.txt_header}
|
||||||
|
This is an answer.
|
||||||
""")
|
""")
|
||||||
self.file_yaml = tempfile.NamedTemporaryFile(delete=False, suffix='.yaml')
|
self.file_yaml = tempfile.NamedTemporaryFile(delete=False, suffix='.yaml')
|
||||||
self.file_path_yaml = pathlib.Path(self.file_yaml.name)
|
self.file_path_yaml = pathlib.Path(self.file_yaml.name)
|
||||||
@ -594,6 +603,10 @@ This is an answer.
|
|||||||
tags = Message.tags_from_file(self.file_path_txt_no_tags)
|
tags = Message.tags_from_file(self.file_path_txt_no_tags)
|
||||||
self.assertSetEqual(tags, set())
|
self.assertSetEqual(tags, set())
|
||||||
|
|
||||||
|
def test_tags_from_file_txt_tags_empty(self) -> None:
|
||||||
|
tags = Message.tags_from_file(self.file_path_txt_tags_empty)
|
||||||
|
self.assertSetEqual(tags, set())
|
||||||
|
|
||||||
def test_tags_from_file_yaml(self) -> None:
|
def test_tags_from_file_yaml(self) -> None:
|
||||||
tags = Message.tags_from_file(self.file_path_yaml)
|
tags = Message.tags_from_file(self.file_path_yaml)
|
||||||
self.assertSetEqual(tags, {Tag('tag1'), Tag('tag2'), Tag('ptag3')})
|
self.assertSetEqual(tags, {Tag('tag1'), Tag('tag2'), Tag('ptag3')})
|
||||||
|
|||||||
@ -44,6 +44,10 @@ class TestTagLine(CmmTestCase):
|
|||||||
tags = tagline.tags()
|
tags = tagline.tags()
|
||||||
self.assertEqual(tags, {Tag('atag1'), Tag('btag2')})
|
self.assertEqual(tags, {Tag('atag1'), Tag('btag2')})
|
||||||
|
|
||||||
|
def test_tags_empty(self) -> None:
|
||||||
|
tagline = TagLine('TAGS:')
|
||||||
|
self.assertSetEqual(tagline.tags(), set())
|
||||||
|
|
||||||
def test_tags_with_newline(self) -> None:
|
def test_tags_with_newline(self) -> None:
|
||||||
tagline = TagLine('TAGS: tag1\n tag2')
|
tagline = TagLine('TAGS: tag1\n tag2')
|
||||||
tags = tagline.tags()
|
tags = tagline.tags()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user