Compare commits
1 Commits
44a88a7c00
...
1876a2f505
| Author | SHA1 | Date | |
|---|---|---|---|
| 1876a2f505 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -131,4 +131,3 @@ dmypy.json
|
|||||||
.config.yaml
|
.config.yaml
|
||||||
db
|
db
|
||||||
noweb
|
noweb
|
||||||
Session.vim
|
|
||||||
|
|||||||
@ -84,12 +84,11 @@ 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)
|
||||||
@ -102,18 +101,20 @@ 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)
|
||||||
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)
|
message.to_file(None)
|
||||||
mock_fd().assert_called_once_with(file_path, 'w')
|
|
||||||
mock_fd().write.assert_called_once_with(expected_content)
|
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:
|
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