From 485cf497d0451520cf16b2799d8225637d94a24a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramiro=20G=C3=B3mez?= Date: Mon, 22 Jul 2024 23:35:24 +0200 Subject: [PATCH] Fix linting issues. Add tests. --- charla/chat.py | 8 ++++---- tests/test_chat.py | 12 ++++++++---- todo.md | 3 --- 3 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 todo.md diff --git a/charla/chat.py b/charla/chat.py index 766ce84..0082f13 100644 --- a/charla/chat.py +++ b/charla/chat.py @@ -18,6 +18,7 @@ from charla import config # UI text + t_open = 'OPEN: ' t_open_toolbar = 'Add to prompt: ' t_prompt = 'PROMPT: ' @@ -68,10 +69,9 @@ def get_content(source: str) -> str: if source.startswith(('http://', 'https://')): try: resp = httpx.get(source, follow_redirects=True) - if 'text/html' == resp.headers['content-type']: - content = html2text(resp.text, baseurl=source) - else: - content = resp.text + content = html2text( + resp.text, baseurl=source + ) if resp.headers['content-type'] == 'text/html' else resp.text except httpx.ConnectError as err: print(f'Enter an existing URL.\n{err}\n') else: diff --git a/tests/test_chat.py b/tests/test_chat.py index afb6a6c..8069d1e 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -9,10 +9,14 @@ def mock_args(): return p.parse_args([]) -# def test_available_models(): -# models = chat.available_models() -# assert len(models) -# assert 'name' in models[0] +def test_get_content_error(): + assert '' == chat.get_content('https://does-not-exist') + assert '' == chat.get_content('does-not-exist.file') + + +def test_get_content_file(): + content = chat.get_content('./tests/test_chat.py') + assert len(content) def test_prompt_session(): diff --git a/todo.md b/todo.md deleted file mode 100644 index 5c06f6f..0000000 --- a/todo.md +++ /dev/null @@ -1,3 +0,0 @@ -# TODO - -* Load content from remote files. Should this be a core feature or a plugin?