Skip to content

Commit

Permalink
Add code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 13, 2024
1 parent 07e7c10 commit f5c1130
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +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
run: mypy src

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

- name: Run code coverage
if: ${{ (matrix.python-version == '3.12') && (matrix.os == 'ubuntu-latest') }}
run: |
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
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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]
Expand All @@ -36,3 +37,9 @@ dev = [
[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
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 f5c1130

Please sign in to comment.