Skip to content

Commit

Permalink
test: rewrite test for refactored code (#85)
Browse files Browse the repository at this point in the history
* test: rewrite test for refactored code

* chore: add pre-commit check as necessary
  • Loading branch information
dongyuanjushi committed Jul 12, 2024
1 parent d7f0e6d commit 1bd95c9
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 22 deletions.
10 changes: 8 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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).
2 changes: 1 addition & 1 deletion pyopenagi/tools/imdb/top_movie.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ...base import BaseRapidAPITool
from ..base import BaseRapidAPITool

from typing import Any, Dict, List, Optional

Expand Down
2 changes: 1 addition & 1 deletion pyopenagi/tools/imdb/top_series.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ...base import BaseRapidAPITool
from ..base import BaseRapidAPITool

from typing import Any, Dict, List, Optional

Expand Down
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r requirements.txt
pre-commit
pytest
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pre-commit
pytest
python-dotenv
Requests
Pympler==1.0.1
Expand Down
6 changes: 3 additions & 3 deletions tests/test_agent_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests/test_tools/test_currency_converter.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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")
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

@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",
Expand Down
16 changes: 8 additions & 8 deletions tests/test_tools/test_top_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
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")
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
Expand Down Expand Up @@ -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)
Expand All @@ -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: "
Expand All @@ -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)
Expand All @@ -121,23 +121,23 @@ 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)

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

@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)
2 changes: 1 addition & 1 deletion tests/test_tools/test_wolfram_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tools/test_words_api.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit 1bd95c9

Please sign in to comment.