From 1bd95c99883f87a6a4fac42969013bd60943bb2c Mon Sep 17 00:00:00 2001 From: Kai Mei Date: Thu, 11 Jul 2024 20:50:52 -0700 Subject: [PATCH] test: rewrite test for refactored code (#85) * test: rewrite test for refactored code * chore: add pre-commit check as necessary --- .github/PULL_REQUEST_TEMPLATE.md | 10 ++++++++-- .../currency_converter.py | 0 pyopenagi/tools/imdb/top_movie.py | 2 +- pyopenagi/tools/imdb/top_series.py | 2 +- requirements-dev.txt | 3 +++ requirements.txt | 2 -- tests/test_agent_creation.py | 6 +++--- tests/test_tools/test_currency_converter.py | 6 +++--- tests/test_tools/test_top_series.py | 16 ++++++++-------- tests/test_tools/test_wolfram_alpha.py | 2 +- tests/test_tools/test_words_api.py | 2 +- 11 files changed, 29 insertions(+), 22 deletions(-) rename pyopenagi/tools/{currency_convert => currency_converter}/currency_converter.py (100%) create mode 100644 requirements-dev.txt diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3e14f2a..fd6f8c1 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,11 @@ -Thank you for your contribution to OpenAGI! Before submitting the pull request, please ensure the PR meets the following criteria. This helps improve the efficiency of the review process. +Thank you for your contribution to OpenAGI! +Before submitting the pull request, please ensure **the PR meets the following criteria**! This helps improve the efficiency of the review process. + +### Code Quality +Before submitting your PR, you need to follow the steps below to maintain code quality. +- Use `pip install -r requirements-dev.txt` to install the extra dependencies in requirements-dev.txt for the following checks. +- Use `pre-commit install` to install pre-commit locally before you commit messages. The pre-commit can help correct the style that are added or modified. +- Use `pytest -v tests/` to run the test code and make sure it passes all the checks. ### PR title and classification Only specific types of PRs will be reviewed. The PR title is prefixed appropriately (i.e., "prefix: description") to indicate the type of change. Please use one of the prefixs as below: @@ -17,7 +24,6 @@ Only specific types of PRs will be reviewed. The PR title is prefixed appropriat - **Issue:** the issue # it fixes, if applicable - **Dependencies:** any dependencies required for this change - ### For the Reviews - After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability. - If no one reviews your PR within a few days, please @-mention one of [dongyuanjushi](https://github.com/dongyuanjushi/), [evison](https://github.com/evison), [Wenyueh](https://github.com/Wenyueh), [BRama10](https://github.com/BRama10). diff --git a/pyopenagi/tools/currency_convert/currency_converter.py b/pyopenagi/tools/currency_converter/currency_converter.py similarity index 100% rename from pyopenagi/tools/currency_convert/currency_converter.py rename to pyopenagi/tools/currency_converter/currency_converter.py diff --git a/pyopenagi/tools/imdb/top_movie.py b/pyopenagi/tools/imdb/top_movie.py index 94a426b..9f82451 100644 --- a/pyopenagi/tools/imdb/top_movie.py +++ b/pyopenagi/tools/imdb/top_movie.py @@ -1,4 +1,4 @@ -from ...base import BaseRapidAPITool +from ..base import BaseRapidAPITool from typing import Any, Dict, List, Optional diff --git a/pyopenagi/tools/imdb/top_series.py b/pyopenagi/tools/imdb/top_series.py index 1639f24..bb01380 100644 --- a/pyopenagi/tools/imdb/top_series.py +++ b/pyopenagi/tools/imdb/top_series.py @@ -1,4 +1,4 @@ -from ...base import BaseRapidAPITool +from ..base import BaseRapidAPITool from typing import Any, Dict, List, Optional diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..b18a75e --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +-r requirements.txt +pre-commit +pytest diff --git a/requirements.txt b/requirements.txt index e031d15..577a2f3 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,3 @@ -pre-commit -pytest python-dotenv Requests Pympler==1.0.1 diff --git a/tests/test_agent_creation.py b/tests/test_agent_creation.py index bac91c8..c886693 100644 --- a/tests/test_agent_creation.py +++ b/tests/test_agent_creation.py @@ -4,13 +4,13 @@ def test_agent_creation(): agent_process = AgentProcess( - agent_name="Narrative Agent", + agent_name="example/academic_agent", query=Query( messages = [ - {"role": "user", "content": "Craft a tale about a valiant warrior on a quest to uncover priceless treasures hidden within a mystical island."} + {"role": "user", "content": "Summarize researches of quantum computing in recent five years."} ] ) ) # Use plain assert statements for testing conditions - assert agent_process.agent_name == "Narrative Agent", "Agent name does not match" + assert agent_process.agent_name == "example/academic_agent", "Agent name does not match" # Add more assertions here as necessary to validate the properties of the agent_process object diff --git a/tests/test_tools/test_currency_converter.py b/tests/test_tools/test_currency_converter.py index e26f7f5..6d92d7f 100644 --- a/tests/test_tools/test_currency_converter.py +++ b/tests/test_tools/test_currency_converter.py @@ -1,7 +1,7 @@ import os import pytest -from pyopenagi.tools.online.currency_converter import CurrencyConverterAPI +from pyopenagi.tools.currency_converter.currency_converter import CurrencyConverter from dotenv import load_dotenv, find_dotenv @pytest.fixture(scope="module") @@ -9,7 +9,7 @@ def test_rapid_api_key(): load_dotenv(find_dotenv()) if "RAPID_API_KEY" not in os.environ or not os.environ["RAPID_API_KEY"]: with pytest.raises(ValueError): - currency_converter_api = CurrencyConverterAPI() + currency_converter = CurrencyConverter() pytest.skip("Rapid api key is not set.") else: return True @@ -17,7 +17,7 @@ def test_rapid_api_key(): @pytest.mark.usefixtures("test_rapid_api_key") def test_currency_converter_api(): load_dotenv(find_dotenv()) - currency_converter_api = CurrencyConverterAPI() + currency_converter_api = CurrencyConverter() params = { "from": "USD", "to": "EUR", diff --git a/tests/test_tools/test_top_series.py b/tests/test_tools/test_top_series.py index 1984184..5d6e22b 100644 --- a/tests/test_tools/test_top_series.py +++ b/tests/test_tools/test_top_series.py @@ -4,7 +4,7 @@ from requests.models import Response import json -from pyopenagi.tools.online.imdb.top_series import ImdbTopSeriesAPI +from pyopenagi.tools.imdb.top_series import TopSeriesAPI from dotenv import load_dotenv, find_dotenv @pytest.fixture(scope="module") @@ -12,7 +12,7 @@ def test_rapid_api_key(): load_dotenv(find_dotenv()) if "RAPID_API_KEY" not in os.environ or not os.environ["RAPID_API_KEY"]: with pytest.raises(ValueError): - ImdbTopSeriesAPI() + TopSeriesAPI() pytest.skip("RAPID api key is not set.") else: return True @@ -76,7 +76,7 @@ def test_top_series_api_valid_input_outputs_valid_delimiter_count( valid_start, valid_end ): load_dotenv(find_dotenv()) - top_series_api = ImdbTopSeriesAPI() + top_series_api = TopSeriesAPI() params = {"start": valid_start, "end": valid_end} result = top_series_api.run(params=params) assert isinstance(result, str) @@ -85,7 +85,7 @@ def test_top_series_api_valid_input_outputs_valid_delimiter_count( @pytest.mark.usefixtures("test_rapid_api_key") def test_top_series_api_reverse_range_returns_blank(): load_dotenv(find_dotenv()) - top_series_api = ImdbTopSeriesAPI() + top_series_api = TopSeriesAPI() params = {"start": 100, "end": 0} result = top_series_api.run(params=params) assert result == "Top 100-0 series ranked by IMDB are: " @@ -103,7 +103,7 @@ def test_top_series_api_reverse_range_returns_blank(): @pytest.mark.usefixtures("test_rapid_api_key") def test_top_series_api_invalid_start_type_raises_typeerror(invalid_start, valid_end): load_dotenv(find_dotenv()) - top_series_api = ImdbTopSeriesAPI() + top_series_api = TopSeriesAPI() params = {"start": invalid_start, "end": valid_end} with pytest.raises(TypeError): top_series_api.run(params=params) @@ -121,7 +121,7 @@ def test_top_series_api_invalid_start_type_raises_typeerror(invalid_start, valid @pytest.mark.usefixtures("test_rapid_api_key") def test_top_series_api_invalid_end_type_raises_typeerror(invalid_start, valid_end): load_dotenv(find_dotenv()) - top_series_api = ImdbTopSeriesAPI() + top_series_api = TopSeriesAPI() params = {"start": invalid_start, "end": valid_end} with pytest.raises(TypeError): top_series_api.run(params=params) @@ -129,7 +129,7 @@ def test_top_series_api_invalid_end_type_raises_typeerror(invalid_start, valid_e @pytest.mark.usefixtures("test_rapid_api_key") def test_top_series_api_invalid_start_count_raises_indexerror(): load_dotenv(find_dotenv()) - top_series_api = ImdbTopSeriesAPI() + top_series_api = TopSeriesAPI() invalid_start = {"start": 101, "end": 102} with pytest.raises(IndexError): top_series_api.run(params=invalid_start) @@ -137,7 +137,7 @@ def test_top_series_api_invalid_start_count_raises_indexerror(): @pytest.mark.usefixtures("test_rapid_api_key") def test_top_series_api_invalid_end_count_raises_indexerror(): load_dotenv(find_dotenv()) - top_series_api = ImdbTopSeriesAPI() + top_series_api = TopSeriesAPI() invalid_end = {"start": 1, "end": 101} with pytest.raises(IndexError): top_series_api.run(params=invalid_end) diff --git a/tests/test_tools/test_wolfram_alpha.py b/tests/test_tools/test_wolfram_alpha.py index e5ae73f..2bc7642 100644 --- a/tests/test_tools/test_wolfram_alpha.py +++ b/tests/test_tools/test_wolfram_alpha.py @@ -4,7 +4,7 @@ from requests.models import Response import json -from pyopenagi.tools.online.wolfram_alpha import WolframAlpha +from pyopenagi.tools.wolfram.wolfram_alpha import WolframAlpha from dotenv import load_dotenv, find_dotenv @pytest.fixture(scope="module") diff --git a/tests/test_tools/test_words_api.py b/tests/test_tools/test_words_api.py index ed26420..d39c148 100644 --- a/tests/test_tools/test_words_api.py +++ b/tests/test_tools/test_words_api.py @@ -1,7 +1,7 @@ import os import pytest -from pyopenagi.tools.online.words_api import WordsAPI +from pyopenagi.tools.words_api.words_api import WordsAPI from dotenv import load_dotenv, find_dotenv @pytest.fixture(scope="module")