Agents-Course-Assignment / test_tools.py
krzsam's picture
Add Excel and Python file loading tools with tests and dependencies
8b3139e
from my_tool_reverse_string import ReverseStringTool
from my_tool_image_load import ImageLoadTool
from my_tool_chess_board import ChessBoard
from my_tool_fen import FENTool
from my_tool_chess_analysis import ChessAnalysisTool
from my_tool_wiki_page_section import MyWikiPageSectionTool
from my_tool_wiki_filter_tables import MyWikiTableFilterTool
from my_tool_wiki_featured_articles import MyWikiFeaturedArticles
from my_base_libretexts_api import MyLibreTextsAPI
from my_tool_excel_load import ExcelLoadTool
from my_tool_python_load import PythonLoadTool
import pytest
import matplotlib as mp
#pytest --capture=no
@pytest.mark.parametrize("_task_id,_exp", [("f918266a-b3e0-4914-865d-4faa564f1aef", "")])
def test_tool_python_load(_task_id,_exp):
print(f"\nLoading Python file for task id: {_task_id}")
t = PythonLoadTool()
result = t.forward(_task_id)
print(f"Got result:\n{result}")
assert True
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_task_id,_exp", [("7bd855d8-463d-4ed5-93ca-5fe35145f733", "")])
def test_tool_excel_load(_task_id,_exp):
print(f"\nLoading Excel file for task id: {_task_id}")
t = ExcelLoadTool()
result = t.forward(_task_id)
print(f"Got result:\n{result}")
assert True
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_exp", [("Introductory")])
def test_tool_libretextx_bookshelves(_exp):
api = MyLibreTextsAPI()
bookshelves = api.get_bookshelves()
shelf_1 = bookshelves[0]
shelf_1_url = shelf_1["url"]
books = api.get_books(shelf_1_url)
book_2 = books[1]
book_2_url = book_2["url"]
sections = api.get_book_sections(book_2_url)
section_2 = sections[1]
section_2_url = section_2["url"]
paragraphs = api.get_book_section_paragraphs(section_2_url)
paragraph_8 = paragraphs[7]
paragraph_8_url = paragraph_8["url"]
contents = api.get_paragraph_contents(paragraph_8_url)
#print(f"Contents:\n{contents}")
assert "Louvrier" in contents
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_month,_year,_exp", [('November',2016, "FunkMonk")])
def test_tool_wiki_contributions(_month,_year, _exp):
tool = MyWikiFeaturedArticles()
results = tool(month=_month, year=_year)
results_str = "\n".join(results)
print(f"Results: {len(results)}\n{results_str}")
assert _exp in results_str
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_page,_section,_sub_section,_year_start,_year_end,_exp",
[("Mercedes Sosa", "Discography", "Studio albums", 2000, 2009, 3)])
def test_tool_wiki_page_section(_page, _section, _sub_section, _year_start, _year_end, _exp):
w = MyWikiPageSectionTool()
f = MyWikiTableFilterTool()
result = w(page=_page, section=_section)
filtered = f(result, _sub_section, _year_start, _year_end)
print(f"Table filtered: \n{filtered}")
assert len(filtered) == _exp
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_inp,_exp", [("abc", "cba"), ("ihg fed cba", "abc def ghi")])
def test_tool_reverse_string(_inp,_exp):
assert ReverseStringTool().forward(_inp) == _exp
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_task_id,_exp", [("cca530fc-4052-43b2-b130-b30968d8aa44", "")])
def test_tool_image_load(_task_id,_exp):
print(f"\nLoading image for task id: {_task_id}")
t = ImageLoadTool()
result = t.forward(_task_id)
print(f"Got result: {result}")
mp.use('QtAgg')
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_task_id,_exp", [("cca530fc-4052-43b2-b130-b30968d8aa44",
"1K1111111PP11111P11RBBqP1111n111Q1111111p11b11111pp111pp1k11r111")])
def test_tool_chess_board(_task_id,_exp):
print(f"\nLoading image for task id: {_task_id}")
t = ImageLoadTool()
image = t.forward(_task_id)
print(f"Got result: {image}")
chess_board_model_name = "my_chess_pieces_recognition.pth"
chess_board_model_dir = "/mnt/c/Users/krzsa/IdeaProjects/Agents-Course-Assignment/saved_models"
board_tool = ChessBoard(chess_board_model_name, chess_board_model_dir)
pieces = board_tool.forward(image)
assert pieces == _exp
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_pieces_list,_exp",
[
("1K1111111PP11111P11RBBqP1111n111Q1111111p11b11111pp111pp1k11r111",
"3r2k1/pp3pp1/4b2p/7Q/3n4/PqBBR2P/5PP1/6K1 b - - 0 1")
])
def test_tool_fen(_pieces_list,_exp):
print(f"\nConverting pieces list to FEN: {_pieces_list}")
t = FENTool()
fen = t.forward(_pieces_list)
print(f"Got result: {fen}")
assert fen == _exp
@pytest.mark.skip(reason="disabled")
@pytest.mark.parametrize("_fen,_exp",
[
("3r2k1/pp3pp1/4b2p/7Q/3n4/PqBBR2P/5PP1/6K1 b - - 0 1", "d8d5")
])
def test_tool_chess_analysis(_fen,_exp):
print(f"\nAnalysing FEN: {_fen}")
t = ChessAnalysisTool()
best_move = t.forward(_fen)
print(f"Got result: {best_move}")
assert best_move == _exp