python package restructuring

This commit is contained in:
2025-01-14 20:29:29 +01:00
parent 0c022d4731
commit 7224111a0b
27 changed files with 97 additions and 74 deletions

View File

@@ -1 +0,0 @@
# empty

View File

@@ -1,32 +1,20 @@
import pytest
import tests.helper as helper
from tests import helper
inference = None
InferenceClass = None
Tensor = None
def prepare():
if InferenceClass == None:
test_import_inference_module_librarys()
if inference == None:
test_instantiate_inference_instance()
def test_import_inference_module_librarys():
import inference
import torch
global InferenceClass
global Tensor
InferenceClass = inference.Inference
Tensor = torch.Tensor
def test_instantiate_inference_instance():
if InferenceClass == None:
test_import_inference_module_librarys()
global inference
inference = InferenceClass()
global Tensor
if inference == None:
from torch import Tensor as _Tensor
from chatbug.inference import Inference
from chatbug.model_selection import get_model
inference = Inference(get_model())
Tensor = _Tensor
def test_tool_header_generation():

View File

@@ -1,6 +1,6 @@
import pytest
import tool_helper
import tests.helper as helper
import chatbug.tool_helper as tool_helper
from tests import helper

View File

@@ -1,6 +1,6 @@
import pytest
import tool_functions
import chatbug.tool_functions as tool_functions
from tests import helper
def test_math_evaluate_1():
@@ -28,6 +28,13 @@ def test_math_evaluate_5():
result = tool_functions.math_evaluate("sin(pi/2) + cos(0)")
assert result == "sin(pi/2) + cos(0) = 2"
def test_math_evaluate_solve_a():
result = tool_functions.math_evaluate("solve 240=x*r+x*r^2+x*r^3+s and r=1.618 and s=5 for x, r, s")
assert result == "Solved equation system 240 = r**3*x + r**2*x + r*x + s, r = 1.61800000000000 and s = 5 for x=27.7393327937747=~27.739, r=1.61800000000000=~1.618 and s=5.00000000000000=~5.000."
def test_math_evaluate_solve_b():
result = tool_functions.math_evaluate("solve 250=x+x*r+s and r=1.618 and s=0 for x, r, s")
assert result == "Solved equation system 250 = r*x + s + x, r = 1.61800000000000 and s = 0 for x=95.4927425515661=~95.493, r=1.61800000000000=~1.618 and s=0."
@@ -54,4 +61,3 @@ def test_math_solver_3b():
def test_math_solver_4():
result = tool_functions.math_evaluate("solve 2*x**3 + 3*y = 7 and x - y = 1 for x, y")
assert result == "Solved equation system 2*x**3 + 3*y = 7 and x - y = 1 for x=~1.421 and y=~0.421."

View File

@@ -1,7 +1,8 @@
import pytest
import tool_helper
from chatbug import tool_helper
from unittest import mock
import tests.helper as helper
from tests import helper
import re
@@ -40,34 +41,34 @@ def test_match_and_extract_matching3_with_newline():
def test_string_malformed_faulty():
with mock.patch("utils.print_error") as print_error_mock:
with mock.patch("chatbug.utils.print_error") as print_error_mock:
result = tool_helper._execute_tool_call_str("{json_content}", [])
assert result == None
print_error_mock.assert_called_once() # this will check if the mocked function on the context was called.
def test_tool_call_json_1():
with mock.patch("utils.print_error") as print_error_mock:
with mock.patch("chatbug.utils.print_error") as print_error_mock:
result = tool_helper._execute_tool_call_json({"name": "tool_dummy", "arguments": {"a": 1, "b": "zwei"}}, [helper.tool_dummy, helper.tool_dummy2])
assert result == "result_1_zwei"
assert print_error_mock.call_count == 0
def test_tool_call_json_2():
with mock.patch("utils.print_error") as print_error_mock:
with mock.patch("chatbug.utils.print_error") as print_error_mock:
result = tool_helper._execute_tool_call_json({"name": "tool_dummy2", "arguments": {"text": "some_text"}}, [helper.tool_dummy, helper.tool_dummy2])
assert result == "SOME_TEXT"
assert print_error_mock.call_count == 0
def test_tool_call_json_non_existing_call_check():
with mock.patch("utils.print_error") as print_error_mock:
with mock.patch("chatbug.utils.print_error") as print_error_mock:
result = tool_helper._execute_tool_call_json({"name": "tool_dummy_which_is_not_existing", "arguments": {"text": "some_text"}}, [helper.tool_dummy, helper.tool_dummy2])
assert result == None
assert print_error_mock.call_count == 1 # this will check if the mocked function on the context was called.
def test_tool_call_json_wrong_arguments_check():
with mock.patch("utils.print_error") as print_error_mock:
with mock.patch("chatbug.utils.print_error") as print_error_mock:
result = tool_helper._execute_tool_call_json({"name": "tool_dummy", "arguments": {"a": "must_be_an_int_but_is_string", "b": "zwei"}}, [helper.tool_dummy, helper.tool_dummy2])
assert result == None
assert print_error_mock.call_count == 1 # this will check if the mocked function on the context was called.
@@ -75,7 +76,6 @@ def test_tool_call_json_wrong_arguments_check():
def test_regex_multiline():
import re
pattern = r"<start>(.*)</end>"
# The text to search (spanning multiple lines)