started to implement sub-commands
This commit is contained in:
+14
-14
@@ -3,9 +3,9 @@ import io
|
||||
import pathlib
|
||||
import argparse
|
||||
from chatmastermind.utils import terminal_width
|
||||
from chatmastermind.main import create_parser, handle_question
|
||||
from chatmastermind.main import create_parser, ask_cmd
|
||||
from chatmastermind.api_client import ai
|
||||
from chatmastermind.storage import create_chat, save_answers, dump_data
|
||||
from chatmastermind.storage import create_chat_hist, save_answers, dump_data
|
||||
from unittest import mock
|
||||
from unittest.mock import patch, MagicMock, Mock
|
||||
|
||||
@@ -30,7 +30,7 @@ class TestCreateChat(unittest.TestCase):
|
||||
{'question': 'test_content', 'answer': 'some answer',
|
||||
'tags': ['test_tag']}))
|
||||
|
||||
test_chat = create_chat(self.question, self.tags, None, self.config)
|
||||
test_chat = create_chat_hist(self.question, self.tags, None, self.config)
|
||||
|
||||
self.assertEqual(len(test_chat), 4)
|
||||
self.assertEqual(test_chat[0],
|
||||
@@ -52,7 +52,7 @@ class TestCreateChat(unittest.TestCase):
|
||||
{'question': 'test_content', 'answer': 'some answer',
|
||||
'tags': ['other_tag']}))
|
||||
|
||||
test_chat = create_chat(self.question, self.tags, None, self.config)
|
||||
test_chat = create_chat_hist(self.question, self.tags, None, self.config)
|
||||
|
||||
self.assertEqual(len(test_chat), 2)
|
||||
self.assertEqual(test_chat[0],
|
||||
@@ -75,7 +75,7 @@ class TestCreateChat(unittest.TestCase):
|
||||
'tags': ['test_tag2']})),
|
||||
)
|
||||
|
||||
test_chat = create_chat(self.question, [], None, self.config)
|
||||
test_chat = create_chat_hist(self.question, [], None, self.config)
|
||||
|
||||
self.assertEqual(len(test_chat), 6)
|
||||
self.assertEqual(test_chat[0],
|
||||
@@ -112,24 +112,24 @@ class TestHandleQuestion(unittest.TestCase):
|
||||
'setting2': 'value2'
|
||||
}
|
||||
|
||||
@patch("chatmastermind.main.create_chat", return_value="test_chat")
|
||||
@patch("chatmastermind.main.create_chat_hist", return_value="test_chat")
|
||||
@patch("chatmastermind.main.process_tags")
|
||||
@patch("chatmastermind.main.ai", return_value=(["answer1", "answer2", "answer3"], "test_usage"))
|
||||
@patch("chatmastermind.utils.pp")
|
||||
@patch("builtins.print")
|
||||
def test_handle_question(self, mock_print, mock_pp, mock_ai,
|
||||
mock_process_tags, mock_create_chat):
|
||||
def test_ask_cmd(self, mock_print, mock_pp, mock_ai,
|
||||
mock_process_tags, mock_create_chat_hist):
|
||||
open_mock = MagicMock()
|
||||
with patch("chatmastermind.storage.open", open_mock):
|
||||
handle_question(self.args, self.config, True)
|
||||
ask_cmd(self.args, self.config, True)
|
||||
mock_process_tags.assert_called_once_with(self.args.tags,
|
||||
self.args.extags,
|
||||
[])
|
||||
mock_create_chat.assert_called_once_with(self.question,
|
||||
self.args.tags,
|
||||
self.args.extags,
|
||||
self.config,
|
||||
False, False, False)
|
||||
mock_create_chat_hist.assert_called_once_with(self.question,
|
||||
self.args.tags,
|
||||
self.args.extags,
|
||||
self.config,
|
||||
False, False, False)
|
||||
mock_pp.assert_called_once_with("test_chat")
|
||||
mock_ai.assert_called_with("test_chat",
|
||||
self.config,
|
||||
|
||||
Reference in New Issue
Block a user