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
|
.config.yaml
|
||||||
db
|
db
|
||||||
noweb
|
noweb
|
||||||
|
Session.vim
|
||||||
|
|||||||
@ -84,11 +84,12 @@ class AnswerTestCase(CmmTestCase):
|
|||||||
|
|
||||||
class TestMessage(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:
|
def test_from_file_txt(self) -> None:
|
||||||
file_path = pathlib.Path('message.txt')
|
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)
|
message = Message.from_file(file_path)
|
||||||
|
|
||||||
self.assertIsInstance(message, Message)
|
self.assertIsInstance(message, Message)
|
||||||
@ -101,20 +102,18 @@ class TestMessage(CmmTestCase):
|
|||||||
# TODO: Create a test yaml file
|
# TODO: Create a test yaml file
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@mock.patch('builtins.open', mock.mock_open())
|
|
||||||
def test_to_file_txt(self) -> None:
|
def test_to_file_txt(self) -> None:
|
||||||
file_path = pathlib.Path('message.txt')
|
file_path = pathlib.Path('message.txt')
|
||||||
message = Message(Question('This is a question'),
|
message = Message(Question('This is a question'),
|
||||||
Answer('This is an answer'),
|
Answer('This is an answer'),
|
||||||
{Tag('tag1'), Tag('tag2')},
|
{Tag('tag1'), Tag('tag2')},
|
||||||
file_path)
|
file_path)
|
||||||
message.to_file(None)
|
expected_content = "TAGS: tag1 tag2\n=== QUESTION ===\nThis is a question\n=== ANSWER ===\nThis is an answer\n"
|
||||||
|
# fake write
|
||||||
with open(file_path, "r") as fd:
|
with mock.patch("builtins.open", mock.mock_open) as mock_fd:
|
||||||
file_contents = fd.read()
|
message.to_file(None)
|
||||||
|
mock_fd().assert_called_once_with(file_path, 'w')
|
||||||
expected_contents = "TAGS: tag1 tag2\n=== QUESTION ===\nThis is a question\n=== ANSWER ===\nThis is an answer\n"
|
mock_fd().write.assert_called_once_with(expected_content)
|
||||||
self.assertEqual(file_contents, expected_contents)
|
|
||||||
|
|
||||||
def test_to_file_yaml(self) -> None:
|
def test_to_file_yaml(self) -> None:
|
||||||
# TODO: Create a test yaml file
|
# TODO: Create a test yaml file
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user