diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index c3db9d4..68891a3 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -53,12 +53,11 @@ jobs: --verbose --verbosity=10 --capture=no --tb=native --showlocals -k "not test_compute_alignment and not test_reproducing_the_same_text_embedding and not test_response_shows_developer_names and not test_llm_will_hallucinate_given_no_data and not test_cosine_similarity_generated_responses" - - name: Type check Python code - run: uv run mypy src + - name: Type check + run: uv run mypy src tests examples/team_recommender/src - - name: Run ruff linter and formatter + - name: Linter and formatter run: | - uv run ruff check src tests examples uv run ruff format src tests examples diff --git a/examples/team_recommender/src/response_matches_json_schema.py b/examples/team_recommender/src/response_matches_json_schema.py index 8f7d2ef..0ac69c0 100644 --- a/examples/team_recommender/src/response_matches_json_schema.py +++ b/examples/team_recommender/src/response_matches_json_schema.py @@ -1,3 +1,5 @@ +from typing import Any + from jsonschema import FormatChecker, validate blank_checker = FormatChecker() @@ -5,7 +7,7 @@ def response_matches_json_schema( response: dict, - schema: any, + schema: Any, format_checker: FormatChecker = blank_checker, ) -> bool: """ diff --git a/examples/team_recommender/tests/example_1_text_response/openai_embeddings.py b/examples/team_recommender/tests/example_1_text_response/openai_embeddings.py index 19f3b78..a17ef42 100644 --- a/examples/team_recommender/tests/example_1_text_response/openai_embeddings.py +++ b/examples/team_recommender/tests/example_1_text_response/openai_embeddings.py @@ -38,7 +38,7 @@ def stabilize_embedding_object(embedding_object): def stabilize_float(x: float) -> float: - return struct.unpack("f", struct.pack("f", x))[0] + return float(struct.unpack("f", struct.pack("f", x))[0]) def create_embedding_object(text: str) -> dict: diff --git a/examples/team_recommender/tests/example_1_text_response/test_good_fit_for_project.py b/examples/team_recommender/tests/example_1_text_response/test_good_fit_for_project.py index cf34015..892ea41 100644 --- a/examples/team_recommender/tests/example_1_text_response/test_good_fit_for_project.py +++ b/examples/team_recommender/tests/example_1_text_response/test_good_fit_for_project.py @@ -132,7 +132,10 @@ def test_llm_will_hallucinate_given_no_data(snapshot): ) tolerance_margin = 0.05 - assert similarity_to_hallucination > similarity_to_no_hallucinations + tolerance_margin + likely_hallucination = ( + similarity_to_hallucination > similarity_to_no_hallucinations + tolerance_margin + ) + assert likely_hallucination def semantic_similarity_score(a: list, b: list) -> float: diff --git a/pyproject.toml b/pyproject.toml index 1d4ab31..c55d989 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,8 @@ dependencies = [ # this small library should be kept independent # consider adding dependencies to one of the dependency groups ] -license = { file = "LICENSE" } +license = "MIT" +license-files = ["LICENSE"] [dependency-groups] test = [ @@ -36,6 +37,7 @@ dev = [ "pydantic>=2.10.6,<3", "ruff>=0.9.10", "pytest-timeout>=2.3.1", + "types-jsonschema>=4.23.0.20241208", ] [tool.uv] @@ -67,6 +69,10 @@ namespace_packages = true explicit_package_bases = true mypy_path = ["src"] +[[tool.mypy.overrides]] +module = "tests.*" +disallow_untyped_defs = false + [tool.black] line-length = 120 target-version = ['py313'] diff --git a/tests/test_reporter.py b/tests/test_reporter.py index a322de3..8070a6c 100644 --- a/tests/test_reporter.py +++ b/tests/test_reporter.py @@ -2,9 +2,9 @@ import time from unittest.mock import MagicMock, mock_open, patch +from cat_ai.helpers.helpers import root_dir +from cat_ai.reporter import Reporter from cat_ai.statistical_analysis import analyse_measure_from_test_sample -from src.cat_ai.helpers.helpers import root_dir -from src.cat_ai.reporter import Reporter def test_reporter_creates_a_unique_folder_path() -> None: diff --git a/tests/test_runner.py b/tests/test_runner.py index 57d7f7b..9a4ff4b 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -1,5 +1,5 @@ -from src.cat_ai.reporter import Reporter -from src.cat_ai.runner import Runner +from cat_ai.reporter import Reporter +from cat_ai.runner import Runner # Dummy test function that will be passed to Runner diff --git a/tests/test_statistical_analysis.py b/tests/test_statistical_analysis.py index 24a9bb2..439d191 100644 --- a/tests/test_statistical_analysis.py +++ b/tests/test_statistical_analysis.py @@ -225,9 +225,9 @@ def test_failure_rate_graph(snapshot): matplotlib.rcParams["ps.fonttype"] = 42 # Generate a series of failure rates - totals = np.ones(100) * 100 - failures = np.arange(0, 100) - + totals = [100] * 100 + failures = list(range(100)) + assert len(failures) == len(totals) # Calculate results for each rate results = [ analyse_failure_rate_from_test_sample(f, t) for f, t in zip(failures, totals, strict=True) diff --git a/uv.lock b/uv.lock index f30538d..baafd81 100644 --- a/uv.lock +++ b/uv.lock @@ -178,6 +178,7 @@ dev = [ { name = "sphinx" }, { name = "sphinx-markdown-builder" }, { name = "sphinx-rtd-theme" }, + { name = "types-jsonschema" }, ] examples = [ { name = "openai" }, @@ -203,6 +204,7 @@ dev = [ { name = "sphinx", specifier = ">=8.1.3,<9" }, { name = "sphinx-markdown-builder", specifier = ">=0.6.8,<0.7" }, { name = "sphinx-rtd-theme", specifier = ">=3.0.2,<4" }, + { name = "types-jsonschema", specifier = ">=4.23.0.20241208" }, ] examples = [ { name = "openai", specifier = ">=1.63.2,<2" }, @@ -2057,6 +2059,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/00/c0/8f5d070730d7836adc9c9b6408dec68c6ced86b304a9b26a14df072a6e8c/traitlets-5.14.3-py3-none-any.whl", hash = "sha256:b74e89e397b1ed28cc831db7aea759ba6640cb3de13090ca145426688ff1ac4f", size = 85359 }, ] +[[package]] +name = "types-jsonschema" +version = "4.23.0.20241208" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "referencing" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ad/e6/9e5cd771687086844caa43dbb211ec0d1cfa899d17c110f3220efcd46e83/types_jsonschema-4.23.0.20241208.tar.gz", hash = "sha256:e8b15ad01f290ecf6aea53f93fbdf7d4730e4600313e89e8a7f95622f7e87b7c", size = 14770 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/91/64/4b2fba8b7cb0104ba013f2a1bf6f39a98e927e14befe1ef947d373b25218/types_jsonschema-4.23.0.20241208-py3-none-any.whl", hash = "sha256:87934bd9231c99d8eff94cacfc06ba668f7973577a9bd9e1f9de957c5737313e", size = 15021 }, +] + [[package]] name = "types-python-dateutil" version = "2.9.0.20241206"