Compare commits

..

2 Commits

2 changed files with 12 additions and 12 deletions

1
.gitignore vendored
View File

@ -131,3 +131,4 @@ dmypy.json
.config.yaml
db
noweb
Session.vim

View File

@ -84,11 +84,12 @@ class AnswerTestCase(CmmTestCase):
class TestMessage(CmmTestCase):
@mock.patch('builtins.open',
mock.mock_open(read_data="TAGS: tag1 tag2\n=== QUESTION ===\nThis is a question\n=== ANSWER ===\nThis is an answer"))
def test_from_file_txt(self) -> None:
file_path = pathlib.Path('message.txt')
with mock.patch('chatmastermind.message.pathlib.Path.exists', return_value=True):
with mock.patch('chatmastermind.message.pathlib.Path.exists', return_value=True), \
mock.patch('builtins.open',
mock.mock_open(
read_data="TAGS: tag1 tag2\n=== QUESTION ===\nThis is a question\n=== ANSWER ===\nThis is an answer")):
message = Message.from_file(file_path)
self.assertIsInstance(message, Message)
@ -101,20 +102,18 @@ class TestMessage(CmmTestCase):
# TODO: Create a test yaml file
pass
@mock.patch('builtins.open', mock.mock_open())
def test_to_file_txt(self) -> None:
file_path = pathlib.Path('message.txt')
message = Message(Question('This is a question'),
Answer('This is an answer'),
{Tag('tag1'), Tag('tag2')},
file_path)
expected_content = "TAGS: tag1 tag2\n=== QUESTION ===\nThis is a question\n=== ANSWER ===\nThis is an answer\n"
# fake write
with mock.patch("builtins.open", mock.mock_open) as mock_fd:
message.to_file(None)
with open(file_path, "r") as fd:
file_contents = fd.read()
expected_contents = "TAGS: tag1 tag2\n=== QUESTION ===\nThis is a question\n=== ANSWER ===\nThis is an answer\n"
self.assertEqual(file_contents, expected_contents)
mock_fd().assert_called_once_with(file_path, 'w')
mock_fd().write.assert_called_once_with(expected_content)
def test_to_file_yaml(self) -> None:
# TODO: Create a test yaml file