Skip to content

Commit 47bad0e

Browse files
committed
Check type of test-utils in CI
1 parent f64b8b8 commit 47bad0e

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

.github/workflows/ci-unit-tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ jobs:
8989
- name: "Type check (knowledge-store)"
9090
run: tox -e type -c libs/knowledge-store && rm -rf libs/knowledge-store/.tox
9191

92+
- name: "Type check (test-utils)"
93+
run: tox -e type -c libs/tests-utils && rm -rf libs/tests-utils/.tox
94+
9295
unit-tests:
9396
name: Unit Tests (Python ${{ matrix.python-version }})
9497
needs: ["preconditions"]

libs/tests-utils/pyproject.toml

+18-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ testcontainers = "^3.7.1"
1616
requests = "^2.32.2"
1717
pytest = "^7.3.0"
1818

19-
2019
[tool.poetry.group.dev.dependencies]
21-
setuptools = "^70.0.0"
20+
mypy = "^1.10.0"
21+
22+
[tool.mypy]
23+
disallow_any_generics = true
24+
disallow_incomplete_defs = true
25+
disallow_untyped_calls = true
26+
disallow_untyped_decorators = true
27+
disallow_untyped_defs = true
28+
follow_imports = "normal"
29+
ignore_missing_imports = true
30+
no_implicit_reexport = true
31+
show_error_codes = true
32+
show_error_context = true
33+
strict_equality = true
34+
strict_optional = true
35+
warn_redundant_casts = true
36+
warn_return_any = true
37+
warn_unused_ignores = true
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
from typing import Any
2+
13
from testcontainers.core.container import DockerContainer
24
from testcontainers.core.waiting_utils import wait_for_logs
5+
from typing_extensions import Self
36

47

58
class CassandraContainer(DockerContainer):
69
def __init__(
710
self,
811
image: str = "docker.io/stargateio/dse-next:4.0.11-b259738f492f",
912
port: int = 9042,
10-
**kwargs,
13+
**kwargs: Any,
1114
) -> None:
1215
super().__init__(image=image, **kwargs)
1316
self.port = port
@@ -22,13 +25,10 @@ def __init__(
2225
self.with_env("CASSANDRA_DC", "datacenter1")
2326
self.with_exposed_ports(self.port)
2427

25-
def _configure(self):
26-
pass
27-
28-
def start(self):
29-
start_res = super().start()
28+
def start(self) -> Self:
29+
super().start()
3030
wait_for_logs(self, "Startup complete")
31-
return start_res
31+
return self
3232

33-
def get_mapped_port(self):
34-
return self.get_exposed_port(self.port)
33+
def get_mapped_port(self) -> int:
34+
return int(self.get_exposed_port(self.port))

libs/tests-utils/ragstack_tests_utils/test_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _get_csv_embedding(csv_file_name: str) -> Embedding:
2323
return [[float(value) for value in row] for row in reader]
2424

2525
@staticmethod
26-
def save_csv_embedding(csv_file_name: str, embedding: Embedding):
26+
def save_csv_embedding(csv_file_name: str, embedding: Embedding) -> None:
2727
with open(TestData._get_test_data_path(csv_file_name), "w", newline="") as f:
2828
writer = csv.writer(f)
2929
writer.writerows(embedding)

libs/tests-utils/ragstack_tests_utils/test_store.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
from abc import ABC, abstractmethod
4+
from typing import Optional
45

56
import cassio
67
from cassandra.cluster import Cluster, PlainTextAuthProvider, Session
@@ -17,7 +18,7 @@ def create_cassandra_session(self) -> Session:
1718

1819

1920
class LocalCassandraTestStore(TestStore):
20-
def __init__(self):
21+
def __init__(self) -> None:
2122
super().__init__()
2223
start_container = os.environ.get("CASSANDRA_START_CONTAINER", "true")
2324
self.port = 9042
@@ -45,11 +46,11 @@ def create_cassandra_session(self) -> Session:
4546

4647

4748
class AstraDBTestStore(TestStore):
48-
token: str
49-
database_id: str
49+
token: Optional[str]
50+
database_id: Optional[str]
5051
env: str
5152

52-
def __init__(self):
53+
def __init__(self) -> None:
5354
super().__init__()
5455
if not os.getenv("ASTRA_DB_ID") or not os.getenv("ASTRA_DB_TOKEN"):
5556
raise ValueError(

libs/tests-utils/tox.ini

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tox]
2+
min_version = 4.0
3+
envlist = type
4+
5+
[testenv]
6+
description = install dependencies
7+
skip_install = true
8+
allowlist_externals = poetry
9+
commands_pre =
10+
poetry env use system
11+
poetry install
12+
13+
[testenv:type]
14+
description = run type checking
15+
commands =
16+
poetry run mypy {toxinidir}

0 commit comments

Comments
 (0)