Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI to unit testing #125

Merged
merged 8 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/hugchat_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
max-parallel: 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ dist/*

.idea/
usercookies/
fortest/
.mypy_cache
build/
3 changes: 3 additions & 0 deletions src/hugchat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/hugchat/hugchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
51 changes: 49 additions & 2 deletions src/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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()
Loading