Skip to content

Commit

Permalink
Merge pull request #125 from Whitelisted1/master
Browse files Browse the repository at this point in the history
Add CLI to unit testing
  • Loading branch information
Soulter authored Oct 20, 2023
2 parents 4fe6ff9 + 8ace1bd commit 36bfe85
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
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

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()

0 comments on commit 36bfe85

Please sign in to comment.