Skip to content

Commit

Permalink
Check types, add code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 13, 2024
1 parent 7ed416e commit c53a357
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 10 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ jobs:
run: python3 -m pip install --upgrade pip

- name: Install ypywidgets in dev mode
run: |
pip install .[dev]
run: pip install .[dev]

- name: Check types
run: mypy src

- name: Run tests
run: pytest ./tests -v --color=yes

- name: Run code coverage
if: ${{ (matrix.python-version == '3.12') && (matrix.os == 'ubuntu-latest') }}
run: |
pytest ./tests -v --color=yes
coverage run -m pytest tests
coverage report --fail-under=100
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://github.com/QuantStack/ypywidgets/workflows/test/badge.svg)](https://github.com/QuantStack/ypywidgets/actions)
[![Code Coverage](https://img.shields.io/badge/coverage-100%25-green)](https://img.shields.io/badge/coverage-100%25-green)

# ypywidgets: Y-based Jupyter widgets for Python

Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@ dependencies = [
"comm >=0.1.4,<1",
"pycrdt >=0.9.0,<0.10.0",
"reacttrs >=0.2.1,<0.3.0",
"coverage >=7.0.0,<8.0.0",
]

[project.urls]
Homepage = "https://github.com/davidbrochart/ypywidgets"

[project.optional-dependencies]
dev = [
"mypy",
"pytest",
"pytest-asyncio",
]

[tool.hatch.build.targets.wheel]
ignore-vcs = true
packages = ["src/ypywidgets"]

[tool.coverage.run]
source = ["src/ypywidgets", "tests"]

[tool.coverage.report]
show_missing = true
2 changes: 1 addition & 1 deletion src/ypywidgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

try:
__version__ = importlib.metadata.version("ypywidgets")
except importlib.metadata.PackageNotFoundError:
except importlib.metadata.PackageNotFoundError: # pragma: no cover
__version__ = "unknown"
2 changes: 1 addition & 1 deletion src/ypywidgets/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
self._comm = create_widget_comm(comm_data, comm_metadata, comm_id)
CommProvider(self.ydoc, self._comm)

def _repr_mimebundle_(self, **kwargs):
def _repr_mimebundle_(self, **kwargs): # pragma: nocover
plaintext = repr(self)
if len(plaintext) > 110:
plaintext = plaintext[:110] + '…'
Expand Down
Empty file added src/ypywidgets/py.typed
Empty file.
8 changes: 4 additions & 4 deletions src/ypywidgets/widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from pycrdt import Doc, Map, Text
from pycrdt import Doc, MapEvent, Map, Text


class Widget:
Expand All @@ -9,17 +9,17 @@ class Widget:
ydoc: Doc

def __init__(self, ydoc: Doc | None = None) -> None:
if self._initialized:
if self._initialized: # pragma: nocover
return
self._initialized = True
self.ydoc = Doc() if ydoc is None else ydoc
self.ydoc["_attrs"] = self._attrs = Map()
self.ydoc["_model_name"] = Text()
self._attrs.observe(self._set_attr)
for k, v in self._attrs.items():
for k, v in self._attrs.items(): # pragma: nocover
setattr(self, k, v)

def _set_attr(self, event):
def _set_attr(self, event: MapEvent):
for k, v in event.keys.items():
new_value = v["newValue"]
if getattr(self, k) != new_value:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ async def get_widget(self, timeout=0.1):
if self.widget:
return self.widget
await asyncio.sleep(0)
if time.monotonic() - t > timeout:
if time.monotonic() - t > timeout: # pragma: nocover
raise TimeoutError("Timeout waiting for widget")

0 comments on commit c53a357

Please sign in to comment.