Compare commits
1 Commits
44a88a7c00
...
1876a2f505
| Author | SHA1 | Date | |
|---|---|---|---|
| 1876a2f505 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -130,5 +130,4 @@ dmypy.json
|
||||
|
||||
.config.yaml
|
||||
db
|
||||
noweb
|
||||
Session.vim
|
||||
noweb
|
||||
@ -84,12 +84,11 @@ 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), \
|
||||
mock.patch('builtins.open',
|
||||
mock.mock_open(
|
||||
read_data="TAGS: tag1 tag2\n=== QUESTION ===\nThis is a question\n=== ANSWER ===\nThis is an answer")):
|
||||
with mock.patch('chatmastermind.message.pathlib.Path.exists', return_value=True):
|
||||
message = Message.from_file(file_path)
|
||||
|
||||
self.assertIsInstance(message, Message)
|
||||
@ -102,18 +101,20 @@ 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)
|
||||
mock_fd().assert_called_once_with(file_path, 'w')
|
||||
mock_fd().write.assert_called_once_with(expected_content)
|
||||
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)
|
||||
|
||||
def test_to_file_yaml(self) -> None:
|
||||
# TODO: Create a test yaml file
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user