fixed almost all tests
This commit is contained in:
parent
93a8b0081a
commit
056bf4c6b5
@ -7,7 +7,7 @@ from chatmastermind.main import create_parser, ask_cmd
|
||||
from chatmastermind.api_client import ai
|
||||
from chatmastermind.storage import create_chat_hist, save_answers, dump_data
|
||||
from unittest import mock
|
||||
from unittest.mock import patch, MagicMock, Mock
|
||||
from unittest.mock import patch, MagicMock, Mock, ANY
|
||||
|
||||
|
||||
class TestCreateChat(unittest.TestCase):
|
||||
@ -113,16 +113,18 @@ class TestHandleQuestion(unittest.TestCase):
|
||||
}
|
||||
|
||||
@patch("chatmastermind.main.create_chat_hist", return_value="test_chat")
|
||||
@patch("chatmastermind.main.process_tags")
|
||||
@patch("chatmastermind.main.print_tag_args")
|
||||
@patch("chatmastermind.utils.print_chat_hist")
|
||||
@patch("chatmastermind.main.ai", return_value=(["answer1", "answer2", "answer3"], "test_usage"))
|
||||
@patch("chatmastermind.utils.pp")
|
||||
@patch("builtins.print")
|
||||
def test_ask_cmd(self, mock_print, mock_pp, mock_ai,
|
||||
mock_process_tags, mock_create_chat_hist):
|
||||
mock_print_tag_args, mock_create_chat_hist,
|
||||
mock_print_chat_hist):
|
||||
open_mock = MagicMock()
|
||||
with patch("chatmastermind.storage.open", open_mock):
|
||||
ask_cmd(self.args, self.config, True)
|
||||
mock_process_tags.assert_called_once_with(self.args.tags,
|
||||
ask_cmd(self.args, self.config)
|
||||
mock_print_tag_args.assert_called_once_with(self.args.tags,
|
||||
self.args.extags,
|
||||
[])
|
||||
mock_create_chat_hist.assert_called_once_with(self.question,
|
||||
@ -130,6 +132,9 @@ class TestHandleQuestion(unittest.TestCase):
|
||||
self.args.extags,
|
||||
self.config,
|
||||
False, False, False)
|
||||
mock_print_chat_hist.assert_called_once_with('test_chat',
|
||||
False,
|
||||
self.args.only_source_code)
|
||||
mock_pp.assert_called_once_with("test_chat")
|
||||
mock_ai.assert_called_with("test_chat",
|
||||
self.config,
|
||||
@ -205,15 +210,15 @@ class TestAI(unittest.TestCase):
|
||||
|
||||
class TestCreateParser(unittest.TestCase):
|
||||
def test_create_parser(self):
|
||||
with patch('argparse.ArgumentParser.add_mutually_exclusive_group') as mock_add_mutually_exclusive_group:
|
||||
mock_group = Mock()
|
||||
mock_add_mutually_exclusive_group.return_value = mock_group
|
||||
with patch('argparse.ArgumentParser.add_subparsers') as mock_add_subparsers:
|
||||
mock_cmdparser = Mock()
|
||||
mock_add_subparsers.return_value = mock_cmdparser
|
||||
parser = create_parser()
|
||||
self.assertIsInstance(parser, argparse.ArgumentParser)
|
||||
mock_add_mutually_exclusive_group.assert_called_once_with(required=True)
|
||||
mock_group.add_argument.assert_any_call('-p', '--print', help='File to print')
|
||||
mock_group.add_argument.assert_any_call('-q', '--question', nargs='*', help='Question to ask')
|
||||
mock_group.add_argument.assert_any_call('-D', '--chat-dump', help="Print chat history as Python structure", action='store_true')
|
||||
mock_group.add_argument.assert_any_call('-d', '--chat', help="Print chat history as readable text", action='store_true')
|
||||
mock_add_subparsers.assert_called_once_with(dest='command', title='commands', description='supported commands', required=True)
|
||||
mock_cmdparser.add_parser.assert_any_call('ask', parents=ANY, help=ANY)
|
||||
mock_cmdparser.add_parser.assert_any_call('hist', parents=ANY, help=ANY)
|
||||
mock_cmdparser.add_parser.assert_any_call('tag', help=ANY)
|
||||
mock_cmdparser.add_parser.assert_any_call('model', help=ANY)
|
||||
mock_cmdparser.add_parser.assert_any_call('print', help=ANY)
|
||||
self.assertTrue('.config.yaml' in parser.get_default('config'))
|
||||
self.assertEqual(parser.get_default('number'), 1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user