test_message: changed all tests to use the new '.msg' suffix
This commit is contained in:
parent
ffcf500acb
commit
68aab144ca
@ -1,11 +1,16 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import pathlib
|
import pathlib
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import itertools
|
||||||
from typing import cast
|
from typing import cast
|
||||||
from chatmastermind.message import source_code, Message, MessageError, Question, Answer, AILine, ModelLine, MessageFilter, message_in
|
from chatmastermind.message import source_code, Message, MessageError, Question, Answer, AILine, ModelLine,\
|
||||||
|
MessageFilter, message_in, message_valid_formats
|
||||||
from chatmastermind.tags import Tag, TagLine
|
from chatmastermind.tags import Tag, TagLine
|
||||||
|
|
||||||
|
|
||||||
|
msg_suffix: str = Message.file_suffix_write
|
||||||
|
|
||||||
|
|
||||||
class SourceCodeTestCase(unittest.TestCase):
|
class SourceCodeTestCase(unittest.TestCase):
|
||||||
def test_source_code_with_include_delims(self) -> None:
|
def test_source_code_with_include_delims(self) -> None:
|
||||||
text = """
|
text = """
|
||||||
@ -101,7 +106,7 @@ class AnswerTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
class MessageToFileTxtTestCase(unittest.TestCase):
|
class MessageToFileTxtTestCase(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.file = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
self.file = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path = pathlib.Path(self.file.name)
|
self.file_path = pathlib.Path(self.file.name)
|
||||||
self.message_complete = Message(Question('This is a question.'),
|
self.message_complete = Message(Question('This is a question.'),
|
||||||
Answer('This is an answer.'),
|
Answer('This is an answer.'),
|
||||||
@ -117,7 +122,7 @@ class MessageToFileTxtTestCase(unittest.TestCase):
|
|||||||
self.file_path.unlink()
|
self.file_path.unlink()
|
||||||
|
|
||||||
def test_to_file_txt_complete(self) -> None:
|
def test_to_file_txt_complete(self) -> None:
|
||||||
self.message_complete.to_file(self.file_path)
|
self.message_complete.to_file(self.file_path, mformat='txt')
|
||||||
|
|
||||||
with open(self.file_path, "r") as fd:
|
with open(self.file_path, "r") as fd:
|
||||||
content = fd.read()
|
content = fd.read()
|
||||||
@ -132,7 +137,7 @@ This is an answer.
|
|||||||
self.assertEqual(content, expected_content)
|
self.assertEqual(content, expected_content)
|
||||||
|
|
||||||
def test_to_file_txt_min(self) -> None:
|
def test_to_file_txt_min(self) -> None:
|
||||||
self.message_min.to_file(self.file_path)
|
self.message_min.to_file(self.file_path, mformat='txt')
|
||||||
|
|
||||||
with open(self.file_path, "r") as fd:
|
with open(self.file_path, "r") as fd:
|
||||||
content = fd.read()
|
content = fd.read()
|
||||||
@ -141,11 +146,17 @@ This is a question.
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(content, expected_content)
|
self.assertEqual(content, expected_content)
|
||||||
|
|
||||||
def test_to_file_unsupported_file_type(self) -> None:
|
def test_to_file_unsupported_file_suffix(self) -> None:
|
||||||
unsupported_file_path = pathlib.Path("example.doc")
|
unsupported_file_path = pathlib.Path("example.doc")
|
||||||
with self.assertRaises(MessageError) as cm:
|
with self.assertRaises(MessageError) as cm:
|
||||||
self.message_complete.to_file(unsupported_file_path)
|
self.message_complete.to_file(unsupported_file_path)
|
||||||
self.assertEqual(str(cm.exception), "File type '.doc' is not supported")
|
self.assertEqual(str(cm.exception), "File suffix '.doc' is not supported")
|
||||||
|
|
||||||
|
def test_to_file_unsupported_file_format(self) -> None:
|
||||||
|
unsupported_file_format = pathlib.Path(f"example{msg_suffix}")
|
||||||
|
with self.assertRaises(MessageError) as cm:
|
||||||
|
self.message_complete.to_file(unsupported_file_format, mformat='doc') # type: ignore [arg-type]
|
||||||
|
self.assertEqual(str(cm.exception), "File format 'doc' is not supported")
|
||||||
|
|
||||||
def test_to_file_no_file_path(self) -> None:
|
def test_to_file_no_file_path(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -159,10 +170,24 @@ This is a question.
|
|||||||
# reset the internal file_path
|
# reset the internal file_path
|
||||||
self.message_complete.file_path = self.file_path
|
self.message_complete.file_path = self.file_path
|
||||||
|
|
||||||
|
def test_to_file_txt_auto_suffix(self) -> None:
|
||||||
|
"""
|
||||||
|
Test if suffix is auto-generated if omitted.
|
||||||
|
"""
|
||||||
|
file_path_no_suffix = self.file_path.with_suffix('')
|
||||||
|
# test with file_path member
|
||||||
|
self.message_min.file_path = file_path_no_suffix
|
||||||
|
self.message_min.to_file(mformat='txt')
|
||||||
|
self.assertEqual(self.message_min.file_path.suffix, msg_suffix)
|
||||||
|
# test with explicit file_path
|
||||||
|
self.message_min.file_path = file_path_no_suffix
|
||||||
|
self.message_min.to_file(file_path=file_path_no_suffix, mformat='txt')
|
||||||
|
self.assertEqual(self.message_min.file_path.suffix, msg_suffix)
|
||||||
|
|
||||||
|
|
||||||
class MessageToFileYamlTestCase(unittest.TestCase):
|
class MessageToFileYamlTestCase(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.file = tempfile.NamedTemporaryFile(delete=False, suffix='.yaml')
|
self.file = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path = pathlib.Path(self.file.name)
|
self.file_path = pathlib.Path(self.file.name)
|
||||||
self.message_complete = Message(Question('This is a question.'),
|
self.message_complete = Message(Question('This is a question.'),
|
||||||
Answer('This is an answer.'),
|
Answer('This is an answer.'),
|
||||||
@ -184,7 +209,7 @@ class MessageToFileYamlTestCase(unittest.TestCase):
|
|||||||
self.file_path.unlink()
|
self.file_path.unlink()
|
||||||
|
|
||||||
def test_to_file_yaml_complete(self) -> None:
|
def test_to_file_yaml_complete(self) -> None:
|
||||||
self.message_complete.to_file(self.file_path)
|
self.message_complete.to_file(self.file_path, mformat='yaml')
|
||||||
|
|
||||||
with open(self.file_path, "r") as fd:
|
with open(self.file_path, "r") as fd:
|
||||||
content = fd.read()
|
content = fd.read()
|
||||||
@ -199,7 +224,7 @@ class MessageToFileYamlTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(content, expected_content)
|
self.assertEqual(content, expected_content)
|
||||||
|
|
||||||
def test_to_file_yaml_multiline(self) -> None:
|
def test_to_file_yaml_multiline(self) -> None:
|
||||||
self.message_multiline.to_file(self.file_path)
|
self.message_multiline.to_file(self.file_path, mformat='yaml')
|
||||||
|
|
||||||
with open(self.file_path, "r") as fd:
|
with open(self.file_path, "r") as fd:
|
||||||
content = fd.read()
|
content = fd.read()
|
||||||
@ -218,17 +243,31 @@ class MessageToFileYamlTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(content, expected_content)
|
self.assertEqual(content, expected_content)
|
||||||
|
|
||||||
def test_to_file_yaml_min(self) -> None:
|
def test_to_file_yaml_min(self) -> None:
|
||||||
self.message_min.to_file(self.file_path)
|
self.message_min.to_file(self.file_path, mformat='yaml')
|
||||||
|
|
||||||
with open(self.file_path, "r") as fd:
|
with open(self.file_path, "r") as fd:
|
||||||
content = fd.read()
|
content = fd.read()
|
||||||
expected_content = f"{Question.yaml_key}: This is a question.\n"
|
expected_content = f"{Question.yaml_key}: This is a question.\n"
|
||||||
self.assertEqual(content, expected_content)
|
self.assertEqual(content, expected_content)
|
||||||
|
|
||||||
|
def test_to_file_yaml_auto_suffix(self) -> None:
|
||||||
|
"""
|
||||||
|
Test if suffix is auto-generated if omitted.
|
||||||
|
"""
|
||||||
|
file_path_no_suffix = self.file_path.with_suffix('')
|
||||||
|
# test with file_path member
|
||||||
|
self.message_min.file_path = file_path_no_suffix
|
||||||
|
self.message_min.to_file(mformat='yaml')
|
||||||
|
self.assertEqual(self.message_min.file_path.suffix, msg_suffix)
|
||||||
|
# test with explicit file_path
|
||||||
|
self.message_min.file_path = file_path_no_suffix
|
||||||
|
self.message_min.to_file(file_path=file_path_no_suffix, mformat='yaml')
|
||||||
|
self.assertEqual(self.message_min.file_path.suffix, msg_suffix)
|
||||||
|
|
||||||
|
|
||||||
class MessageFromFileTxtTestCase(unittest.TestCase):
|
class MessageFromFileTxtTestCase(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.file = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
self.file = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path = pathlib.Path(self.file.name)
|
self.file_path = pathlib.Path(self.file.name)
|
||||||
with open(self.file_path, "w") as fd:
|
with open(self.file_path, "w") as fd:
|
||||||
fd.write(f"""{TagLine.prefix} tag1 tag2
|
fd.write(f"""{TagLine.prefix} tag1 tag2
|
||||||
@ -239,7 +278,7 @@ This is a question.
|
|||||||
{Answer.txt_header}
|
{Answer.txt_header}
|
||||||
This is an answer.
|
This is an answer.
|
||||||
""")
|
""")
|
||||||
self.file_min = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
self.file_min = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path_min = pathlib.Path(self.file_min.name)
|
self.file_path_min = pathlib.Path(self.file_min.name)
|
||||||
with open(self.file_path_min, "w") as fd:
|
with open(self.file_path_min, "w") as fd:
|
||||||
fd.write(f"""{Question.txt_header}
|
fd.write(f"""{Question.txt_header}
|
||||||
@ -259,7 +298,7 @@ This is a question.
|
|||||||
message = Message.from_file(self.file_path)
|
message = Message.from_file(self.file_path)
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertEqual(message.answer, 'This is an answer.')
|
self.assertEqual(message.answer, 'This is an answer.')
|
||||||
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
||||||
@ -274,7 +313,7 @@ This is a question.
|
|||||||
message = Message.from_file(self.file_path_min)
|
message = Message.from_file(self.file_path_min)
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertEqual(message.file_path, self.file_path_min)
|
self.assertEqual(message.file_path, self.file_path_min)
|
||||||
self.assertIsNone(message.answer)
|
self.assertIsNone(message.answer)
|
||||||
@ -284,7 +323,7 @@ This is a question.
|
|||||||
MessageFilter(tags_or={Tag('tag1')}))
|
MessageFilter(tags_or={Tag('tag1')}))
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertEqual(message.answer, 'This is an answer.')
|
self.assertEqual(message.answer, 'This is an answer.')
|
||||||
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
||||||
@ -311,13 +350,13 @@ This is a question.
|
|||||||
MessageFilter(tags_not={Tag('tag1')}))
|
MessageFilter(tags_not={Tag('tag1')}))
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertSetEqual(cast(set[Tag], message.tags), set())
|
self.assertSetEqual(cast(set[Tag], message.tags), set())
|
||||||
self.assertEqual(message.file_path, self.file_path_min)
|
self.assertEqual(message.file_path, self.file_path_min)
|
||||||
|
|
||||||
def test_from_file_not_exists(self) -> None:
|
def test_from_file_not_exists(self) -> None:
|
||||||
file_not_exists = pathlib.Path("example.txt")
|
file_not_exists = pathlib.Path(f"example{msg_suffix}")
|
||||||
with self.assertRaises(MessageError) as cm:
|
with self.assertRaises(MessageError) as cm:
|
||||||
Message.from_file(file_not_exists)
|
Message.from_file(file_not_exists)
|
||||||
self.assertEqual(str(cm.exception), f"Message file '{file_not_exists}' does not exist")
|
self.assertEqual(str(cm.exception), f"Message file '{file_not_exists}' does not exist")
|
||||||
@ -396,7 +435,7 @@ This is a question.
|
|||||||
|
|
||||||
class MessageFromFileYamlTestCase(unittest.TestCase):
|
class MessageFromFileYamlTestCase(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.file = tempfile.NamedTemporaryFile(delete=False, suffix='.yaml')
|
self.file = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path = pathlib.Path(self.file.name)
|
self.file_path = pathlib.Path(self.file.name)
|
||||||
with open(self.file_path, "w") as fd:
|
with open(self.file_path, "w") as fd:
|
||||||
fd.write(f"""
|
fd.write(f"""
|
||||||
@ -410,7 +449,7 @@ class MessageFromFileYamlTestCase(unittest.TestCase):
|
|||||||
- tag1
|
- tag1
|
||||||
- tag2
|
- tag2
|
||||||
""")
|
""")
|
||||||
self.file_min = tempfile.NamedTemporaryFile(delete=False, suffix='.yaml')
|
self.file_min = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path_min = pathlib.Path(self.file_min.name)
|
self.file_path_min = pathlib.Path(self.file_min.name)
|
||||||
with open(self.file_path_min, "w") as fd:
|
with open(self.file_path_min, "w") as fd:
|
||||||
fd.write(f"""
|
fd.write(f"""
|
||||||
@ -431,7 +470,7 @@ class MessageFromFileYamlTestCase(unittest.TestCase):
|
|||||||
message = Message.from_file(self.file_path)
|
message = Message.from_file(self.file_path)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertEqual(message.answer, 'This is an answer.')
|
self.assertEqual(message.answer, 'This is an answer.')
|
||||||
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
||||||
@ -446,14 +485,14 @@ class MessageFromFileYamlTestCase(unittest.TestCase):
|
|||||||
message = Message.from_file(self.file_path_min)
|
message = Message.from_file(self.file_path_min)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertSetEqual(cast(set[Tag], message.tags), set())
|
self.assertSetEqual(cast(set[Tag], message.tags), set())
|
||||||
self.assertEqual(message.file_path, self.file_path_min)
|
self.assertEqual(message.file_path, self.file_path_min)
|
||||||
self.assertIsNone(message.answer)
|
self.assertIsNone(message.answer)
|
||||||
|
|
||||||
def test_from_file_not_exists(self) -> None:
|
def test_from_file_not_exists(self) -> None:
|
||||||
file_not_exists = pathlib.Path("example.yaml")
|
file_not_exists = pathlib.Path(f"example{msg_suffix}")
|
||||||
with self.assertRaises(MessageError) as cm:
|
with self.assertRaises(MessageError) as cm:
|
||||||
Message.from_file(file_not_exists)
|
Message.from_file(file_not_exists)
|
||||||
self.assertEqual(str(cm.exception), f"Message file '{file_not_exists}' does not exist")
|
self.assertEqual(str(cm.exception), f"Message file '{file_not_exists}' does not exist")
|
||||||
@ -463,7 +502,7 @@ class MessageFromFileYamlTestCase(unittest.TestCase):
|
|||||||
MessageFilter(tags_or={Tag('tag1')}))
|
MessageFilter(tags_or={Tag('tag1')}))
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertEqual(message.answer, 'This is an answer.')
|
self.assertEqual(message.answer, 'This is an answer.')
|
||||||
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
self.assertSetEqual(cast(set[Tag], message.tags), {Tag('tag1'), Tag('tag2')})
|
||||||
@ -484,7 +523,7 @@ class MessageFromFileYamlTestCase(unittest.TestCase):
|
|||||||
MessageFilter(tags_not={Tag('tag1')}))
|
MessageFilter(tags_not={Tag('tag1')}))
|
||||||
self.assertIsNotNone(message)
|
self.assertIsNotNone(message)
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
if message: # mypy bug
|
assert message
|
||||||
self.assertEqual(message.question, 'This is a question.')
|
self.assertEqual(message.question, 'This is a question.')
|
||||||
self.assertSetEqual(cast(set[Tag], message.tags), set())
|
self.assertSetEqual(cast(set[Tag], message.tags), set())
|
||||||
self.assertEqual(message.file_path, self.file_path_min)
|
self.assertEqual(message.file_path, self.file_path_min)
|
||||||
@ -563,7 +602,7 @@ class MessageFromFileYamlTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
class TagsFromFileTestCase(unittest.TestCase):
|
class TagsFromFileTestCase(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.file_txt = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
self.file_txt = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path_txt = pathlib.Path(self.file_txt.name)
|
self.file_path_txt = pathlib.Path(self.file_txt.name)
|
||||||
with open(self.file_path_txt, "w") as fd:
|
with open(self.file_path_txt, "w") as fd:
|
||||||
fd.write(f"""{TagLine.prefix} tag1 tag2 ptag3
|
fd.write(f"""{TagLine.prefix} tag1 tag2 ptag3
|
||||||
@ -572,7 +611,7 @@ This is a question.
|
|||||||
{Answer.txt_header}
|
{Answer.txt_header}
|
||||||
This is an answer.
|
This is an answer.
|
||||||
""")
|
""")
|
||||||
self.file_txt_no_tags = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
self.file_txt_no_tags = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path_txt_no_tags = pathlib.Path(self.file_txt_no_tags.name)
|
self.file_path_txt_no_tags = pathlib.Path(self.file_txt_no_tags.name)
|
||||||
with open(self.file_path_txt_no_tags, "w") as fd:
|
with open(self.file_path_txt_no_tags, "w") as fd:
|
||||||
fd.write(f"""{Question.txt_header}
|
fd.write(f"""{Question.txt_header}
|
||||||
@ -580,7 +619,7 @@ 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_txt_tags_empty = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path_txt_tags_empty = pathlib.Path(self.file_txt_tags_empty.name)
|
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:
|
with open(self.file_path_txt_tags_empty, "w") as fd:
|
||||||
fd.write(f"""TAGS:
|
fd.write(f"""TAGS:
|
||||||
@ -589,7 +628,7 @@ This is a question.
|
|||||||
{Answer.txt_header}
|
{Answer.txt_header}
|
||||||
This is an answer.
|
This is an answer.
|
||||||
""")
|
""")
|
||||||
self.file_yaml = tempfile.NamedTemporaryFile(delete=False, suffix='.yaml')
|
self.file_yaml = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path_yaml = pathlib.Path(self.file_yaml.name)
|
self.file_path_yaml = pathlib.Path(self.file_yaml.name)
|
||||||
with open(self.file_path_yaml, "w") as fd:
|
with open(self.file_path_yaml, "w") as fd:
|
||||||
fd.write(f"""
|
fd.write(f"""
|
||||||
@ -602,7 +641,7 @@ This is an answer.
|
|||||||
- tag2
|
- tag2
|
||||||
- ptag3
|
- ptag3
|
||||||
""")
|
""")
|
||||||
self.file_yaml_no_tags = tempfile.NamedTemporaryFile(delete=False, suffix='.yaml')
|
self.file_yaml_no_tags = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path_yaml_no_tags = pathlib.Path(self.file_yaml_no_tags.name)
|
self.file_path_yaml_no_tags = pathlib.Path(self.file_yaml_no_tags.name)
|
||||||
with open(self.file_path_yaml_no_tags, "w") as fd:
|
with open(self.file_path_yaml_no_tags, "w") as fd:
|
||||||
fd.write(f"""
|
fd.write(f"""
|
||||||
@ -679,24 +718,25 @@ class TagsFromDirTestCase(unittest.TestCase):
|
|||||||
{Tag('ctag5'), Tag('ctag6')}
|
{Tag('ctag5'), Tag('ctag6')}
|
||||||
]
|
]
|
||||||
self.files = [
|
self.files = [
|
||||||
pathlib.Path(self.temp_dir.name, 'file1.txt'),
|
pathlib.Path(self.temp_dir.name, f'file1{msg_suffix}'),
|
||||||
pathlib.Path(self.temp_dir.name, 'file2.yaml'),
|
pathlib.Path(self.temp_dir.name, f'file2{msg_suffix}'),
|
||||||
pathlib.Path(self.temp_dir.name, 'file3.txt')
|
pathlib.Path(self.temp_dir.name, f'file3{msg_suffix}')
|
||||||
]
|
]
|
||||||
self.files_no_tags = [
|
self.files_no_tags = [
|
||||||
pathlib.Path(self.temp_dir_no_tags.name, 'file4.txt'),
|
pathlib.Path(self.temp_dir_no_tags.name, f'file4{msg_suffix}'),
|
||||||
pathlib.Path(self.temp_dir_no_tags.name, 'file5.yaml'),
|
pathlib.Path(self.temp_dir_no_tags.name, f'file5{msg_suffix}'),
|
||||||
pathlib.Path(self.temp_dir_no_tags.name, 'file6.txt')
|
pathlib.Path(self.temp_dir_no_tags.name, f'file6{msg_suffix}')
|
||||||
]
|
]
|
||||||
|
mformats = itertools.cycle(message_valid_formats)
|
||||||
for file, tags in zip(self.files, self.tag_sets):
|
for file, tags in zip(self.files, self.tag_sets):
|
||||||
message = Message(Question('This is a question.'),
|
message = Message(Question('This is a question.'),
|
||||||
Answer('This is an answer.'),
|
Answer('This is an answer.'),
|
||||||
tags)
|
tags)
|
||||||
message.to_file(file)
|
message.to_file(file, next(mformats))
|
||||||
for file in self.files_no_tags:
|
for file in self.files_no_tags:
|
||||||
message = Message(Question('This is a question.'),
|
message = Message(Question('This is a question.'),
|
||||||
Answer('This is an answer.'))
|
Answer('This is an answer.'))
|
||||||
message.to_file(file)
|
message.to_file(file, next(mformats))
|
||||||
|
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
self.temp_dir.cleanup()
|
self.temp_dir.cleanup()
|
||||||
@ -719,7 +759,7 @@ class TagsFromDirTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
class MessageIDTestCase(unittest.TestCase):
|
class MessageIDTestCase(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.file = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
self.file = tempfile.NamedTemporaryFile(delete=False, suffix=msg_suffix)
|
||||||
self.file_path = pathlib.Path(self.file.name)
|
self.file_path = pathlib.Path(self.file.name)
|
||||||
self.message = Message(Question('This is a question.'),
|
self.message = Message(Question('This is a question.'),
|
||||||
file_path=self.file_path)
|
file_path=self.file_path)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user