Skip to content

Commit 86a4762

Browse files
Check types, add code coverage (#34)
1 parent 7ed416e commit 86a4762

File tree

8 files changed

+24
-8
lines changed

8 files changed

+24
-8
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ jobs:
3434
run: python3 -m pip install --upgrade pip
3535

3636
- name: Install ypywidgets in dev mode
37-
run: |
38-
pip install .[dev]
37+
run: pip install -e ".[dev]"
38+
39+
- name: Check types
40+
run: mypy src
3941

4042
- name: Run tests
43+
run: pytest ./tests -v --color=yes
44+
45+
- name: Run code coverage
46+
if: ${{ (matrix.python-version == '3.12') && (matrix.os == 'ubuntu-latest') }}
4147
run: |
42-
pytest ./tests -v --color=yes
48+
coverage run -m pytest tests
49+
coverage report --fail-under=100

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Build Status](https://github.com/QuantStack/ypywidgets/workflows/test/badge.svg)](https://github.com/QuantStack/ypywidgets/actions)
2+
[![Code Coverage](https://img.shields.io/badge/coverage-100%25-green)](https://img.shields.io/badge/coverage-100%25-green)
23

34
# ypywidgets: Y-based Jupyter widgets for Python
45

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ Homepage = "https://github.com/davidbrochart/ypywidgets"
2828

2929
[project.optional-dependencies]
3030
dev = [
31+
"coverage >=7.0.0,<8.0.0",
32+
"mypy",
3133
"pytest",
3234
"pytest-asyncio",
3335
]
3436

3537
[tool.hatch.build.targets.wheel]
3638
ignore-vcs = true
3739
packages = ["src/ypywidgets"]
40+
41+
[tool.coverage.run]
42+
source = ["src/ypywidgets", "tests"]
43+
44+
[tool.coverage.report]
45+
show_missing = true

src/ypywidgets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
try:
88
__version__ = importlib.metadata.version("ypywidgets")
9-
except importlib.metadata.PackageNotFoundError:
9+
except importlib.metadata.PackageNotFoundError: # pragma: no cover
1010
__version__ = "unknown"

src/ypywidgets/comm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(
7676
self._comm = create_widget_comm(comm_data, comm_metadata, comm_id)
7777
CommProvider(self.ydoc, self._comm)
7878

79-
def _repr_mimebundle_(self, **kwargs):
79+
def _repr_mimebundle_(self, **kwargs): # pragma: nocover
8080
plaintext = repr(self)
8181
if len(plaintext) > 110:
8282
plaintext = plaintext[:110] + '…'

src/ypywidgets/py.typed

Whitespace-only changes.

src/ypywidgets/widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ class Widget:
99
ydoc: Doc
1010

1111
def __init__(self, ydoc: Doc | None = None) -> None:
12-
if self._initialized:
12+
if self._initialized: # pragma: nocover
1313
return
1414
self._initialized = True
1515
self.ydoc = Doc() if ydoc is None else ydoc
1616
self.ydoc["_attrs"] = self._attrs = Map()
1717
self.ydoc["_model_name"] = Text()
1818
self._attrs.observe(self._set_attr)
19-
for k, v in self._attrs.items():
19+
for k, v in self._attrs.items(): # pragma: nocover
2020
setattr(self, k, v)
2121

2222
def _set_attr(self, event):

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ async def get_widget(self, timeout=0.1):
9696
if self.widget:
9797
return self.widget
9898
await asyncio.sleep(0)
99-
if time.monotonic() - t > timeout:
99+
if time.monotonic() - t > timeout: # pragma: nocover
100100
raise TimeoutError("Timeout waiting for widget")

0 commit comments

Comments
 (0)