Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Dec 12, 2024
1 parent 30bf9ec commit e2a944c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: pip install -e ".[test]"

- name: Check types
run: mypy python
run: mypy --check-untyped-defs python

- name: Run tests
if: ${{ !((matrix.python-version == '3.13') && (matrix.os == 'ubuntu')) }}
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies = [
[project.optional-dependencies]
test = [
"pytest >=7.4.2,<8",
"pytest-mypy-testing",
"anyio",
"trio >=0.25.1,<0.27",
"pydantic >=2.5.2,<3",
Expand All @@ -59,11 +60,13 @@ python-source = "python"
module-name = "pycrdt._pycrdt"

[tool.ruff]
exclude = ["tests/test_types.py"]
line-length = 100
lint.select = ["F", "E", "W", "I001"]

[tool.coverage.run]
source = ["python", "tests"]
omit = ["tests/test_types.py"]

[tool.coverage.report]
show_missing = true
Expand Down
1 change: 1 addition & 0 deletions python/pycrdt/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def __init__(self, event: Any, doc: Doc):

def __str__(self):
str_list = []
slot: Any
for slot in self.__slots__:
val = str(getattr(self, slot))
str_list.append(f"{slot}: {val}")
Expand Down
20 changes: 20 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
from pycrdt import Array, Doc, Map


@pytest.mark.mypy_testing
def mypy_test_array():
doc = Doc()
array0: Array[int] = doc.get("array0", type=Array)
array0.append(0)
array0.append("foo") # E: Argument 1 to "append" of "Array" has incompatible type "str"; expected "int" [arg-type]


@pytest.mark.mypy_testing
def mypy_test_map():
doc = Doc()
map0: Map[bool] = doc.get("map0", type=Map)
map0["foo"] = True
map0["foo"] = "bar" # E: Incompatible types in assignment (expression has type "str", target has type "bool")
v0: str = map0.pop("foo") # E: Incompatible types in assignment (expression has type "bool", variable has type "str")
v1: bool = map0.pop("foo")

0 comments on commit e2a944c

Please sign in to comment.