Skip to content

Commit

Permalink
Check types, add code coverage (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 13, 2024
1 parent 7ed416e commit 86a4762
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 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 -e ".[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 @@ -28,10 +28,18 @@ Homepage = "https://github.com/davidbrochart/ypywidgets"

[project.optional-dependencies]
dev = [
"coverage >=7.0.0,<8.0.0",
"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.
4 changes: 2 additions & 2 deletions src/ypywidgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ 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):
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 86a4762

Please sign in to comment.