Compare commits
2 Commits
1876a2f505
...
44a88a7c00
| Author | SHA1 | Date | |
|---|---|---|---|
| 44a88a7c00 | |||
| 55f89adb03 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -130,4 +130,5 @@ dmypy.json
|
||||
|
||||
.config.yaml
|
||||
db
|
||||
noweb
|
||||
noweb
|
||||
Session.vim
|
||||
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
|
||||
def test_to_file_yaml(self) -> None:
|
||||
# TODO: Create a test yaml file
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user