diff --git a/.github/workflows/hugchat_unit_test.yml b/.github/workflows/hugchat_unit_test.yml index 4ed788f..64972df 100644 --- a/.github/workflows/hugchat_unit_test.yml +++ b/.github/workflows/hugchat_unit_test.yml @@ -17,6 +17,7 @@ jobs: fail-fast: false matrix: python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + max-parallel: 1 steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 572cd84..e81010a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ dist/* .idea/ usercookies/ +fortest/ .mypy_cache build/ \ No newline at end of file diff --git a/src/hugchat/cli.py b/src/hugchat/cli.py index 8013776..c0d5a04 100644 --- a/src/hugchat/cli.py +++ b/src/hugchat/cli.py @@ -90,9 +90,12 @@ def cli(): running = True is_web_search = False web_search_hint = False + print("Login successfully🎉 You can input `/help` to open the command menu.") + while running: question = input("> ") + if question == "/new": cid = chatbot.new_conversation() print("The new conversation ID is: " + cid) diff --git a/src/hugchat/hugchat.py b/src/hugchat/hugchat.py index 9acbc63..ddbc3bf 100644 --- a/src/hugchat/hugchat.py +++ b/src/hugchat/hugchat.py @@ -311,7 +311,7 @@ def delete_all_conversations(self) -> None: self.conversation_list = [] self.current_conversation = None - def delete_conversation(self, conversation_object: conversation = None) -> bool: + def delete_conversation(self, conversation_object: conversation = None) -> None: """ Delete a HuggingChat conversation by conversation. """ diff --git a/src/unit_test.py b/src/unit_test.py index bfce2a6..9b9e86a 100644 --- a/src/unit_test.py +++ b/src/unit_test.py @@ -4,8 +4,10 @@ import os import logging -from .hugchat import hugchat +from .hugchat import hugchat, cli from .hugchat.login import Login +import sys +from unittest.mock import patch logging.basicConfig(level=logging.DEBUG) @@ -39,7 +41,7 @@ def test_create_conversation(self): assert res is not None chatbot.change_conversation(res) my_conversation = res - print("Test create conversation:",str(res)) + print("Test create conversation:", str(res)) def test_chat_without_web_search(self): """ @@ -64,9 +66,54 @@ def test_generator(self): print(i, flush=True) assert res is not None + + # def test_delete_conversation(self): + # """ + # test delete conversation module + # """ + # chatbot.delete_conversation(my_conversation) + + def test_delete_all_conversations(self): + """ + test delete all conversations module + """ + chatbot.delete_all_conversations() + + def test_cli(self): + global times_run + times_run = -1 + + # many not enabled because the CLI is currently very broken + return_strings = [ + "/help", + "Hello!", + # "/new", + # "/ids", + # "/sharewithauthor off" + "/exit" + ] + def input_callback(_): + global times_run + times_run += 1 + + return return_strings[times_run] + + sys.argv = [sys.argv[0]] + + sys.argv.append("-u") + sys.argv.append(EMAIL) + + with patch("getpass.getpass", side_effect=lambda _: PASSWORD): + with patch('builtins.input', side_effect=input_callback): + cli.cli() if __name__ == "__main__": test = TestAPI() test.test_login() test.test_create_conversation() + # test.test_delete_conversation() + test.test_chat_without_web_search() + test.test_chat_web_search() + test.test_delete_all_conversations() + test.test_cli() test.test_generator() \ No newline at end of file