Skip to content

Commit c69ab45

Browse files
authored
Reenable and fix tests with Jupyter. (#535)
1 parent 8b53c44 commit c69ab45

File tree

11 files changed

+33
-34
lines changed

11 files changed

+33
-34
lines changed

.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
- name: Run unit tests and doctests.
5252
shell: bash -l {0}
53-
run: tox -e pytest -- -m "unit or (not integration and not end_to_end)" --cov=src --cov=tests --cov-report=xml -n auto
53+
run: tox -e test -- -m "unit or (not integration and not end_to_end)" --cov=src --cov=tests --cov-report=xml -n auto
5454

5555
- name: Upload unit test coverage reports to Codecov with GitHub Action
5656
uses: codecov/codecov-action@v3
@@ -59,7 +59,7 @@ jobs:
5959

6060
- name: Run integration tests.
6161
shell: bash -l {0}
62-
run: tox -e pytest -- -m integration --cov=src --cov=tests --cov-report=xml -n auto
62+
run: tox -e test -- -m integration --cov=src --cov=tests --cov-report=xml -n auto
6363

6464
- name: Upload integration test coverage reports to Codecov with GitHub Action
6565
uses: codecov/codecov-action@v3
@@ -68,7 +68,7 @@ jobs:
6868

6969
- name: Run end-to-end tests.
7070
shell: bash -l {0}
71-
run: tox -e pytest -- -m end_to_end --cov=src --cov=tests --cov-report=xml -n auto
71+
run: tox -e test -- -m end_to_end --cov=src --cov=tests --cov-report=xml -n auto
7272

7373
- name: Upload end_to_end test coverage reports to Codecov with GitHub Action
7474
uses: codecov/codecov-action@v3

docs/source/changes.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
2121
- {pull}`524` improves some linting and formatting rules.
2222
- {pull}`525` enables pytask to work with remote files using universal_pathlib.
2323
- {pull}`528` improves the codecov setup and coverage.
24+
- {pull}`535` reenables and fixes tests with Jupyter.
2425

2526
## 0.4.4 - 2023-12-04
2627

@@ -68,7 +69,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
6869
- {pull}`465` adds test to ensure internal tracebacks are removed by reports.
6970
- {pull}`466` implements hashing for files instead of modification timestamps.
7071
- {pull}`470` moves `.pytask.sqlite3` to `.pytask`.
71-
- {pull}`472` adds `is_product` to {meth}`PNode.load`.
72+
- {pull}`472` adds `is_product` to {meth}`~pytask.PNode.load`.
7273
- {pull}`473` adds signatures to nodes which decouples an identifier from a name.
7374
- {pull}`477` updates the PyPI action.
7475
- {pull}`478` replaces black with ruff-format.
@@ -94,9 +95,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
9495
is not present.
9596
- {pull}`387` replaces pony with sqlalchemy.
9697
- {pull}`391` removes `@pytask.mark.parametrize`.
97-
- {pull}`394` allows to add products with {obj}`typing.Annotation` and
98+
- {pull}`394` allows to add products with {obj}`typing.Annotated` and
9899
{obj}`~pytask.Product`.
99-
- {pull}`395` refactors all occurrences of pybaum to {mod}`_pytask.tree_util`.
100+
- {pull}`395` refactors all occurrences of pybaum to `_pytask.tree_util`.
100101
- {pull}`396` replaces pybaum with optree and adds paths to the name of
101102
{class}`pytask.PythonNode`'s allowing for better hashing.
102103
- {pull}`397` adds support for {class}`typing.NamedTuple` and attrs classes in
@@ -123,7 +124,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
123124
- {pull}`421` removes the deprecation warning when `produces` is used as an magic
124125
function keyword to define products.
125126
- {pull}`423` adds a notebook to explain the functional interface.
126-
- {pull}`424` fixes problems with {func}`~_pytask.path.import_path`.
127+
- {pull}`424` fixes problems with `~_pytask.path.import_path`.
127128
- {pull}`426` publishes the {mod}`pytask.tree_util` module.
128129
- {pull}`427` fixes type annotations for {attr}`pytask.PTask.depends_on` and
129130
{attr}`pytask.PTask.produces`.

docs/source/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"IPython.sphinxext.ipython_console_highlighting",
4242
"IPython.sphinxext.ipython_directive",
4343
"sphinx.ext.autodoc",
44+
"sphinx.ext.doctest",
4445
"sphinx.ext.extlinks",
4546
"sphinx.ext.intersphinx",
4647
"sphinx.ext.linkcode",

docs/source/reference_guides/api.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,11 @@ To mark any callable as a task use
285285
.. autofunction:: pytask.task
286286
```
287287

288-
Task are currently represented by the following class:
288+
Task are currently represented by the following classes:
289289

290290
```{eval-rst}
291291
.. autoclass:: pytask.Task
292+
.. autoclass:: pytask.TaskWithoutPath
292293
```
293294

294295
Currently, there are no different types of tasks since changing the `.function`
@@ -369,12 +370,8 @@ resolution and execution.
369370
## Tree utilities
370371

371372
```{eval-rst}
372-
.. autofunction:: pytask.tree_util.PyTree
373-
.. autofunction:: pytask.tree_util.tree_flatten_with_path
374-
.. autofunction:: pytask.tree_util.tree_leaves
375-
.. autofunction:: pytask.tree_util.tree_map
376-
.. autofunction:: pytask.tree_util.tree_map_with_path
377-
.. autofunction:: pytask.tree_util.tree_structure
373+
.. automodule:: pytask.tree_util
374+
:members:
378375
```
379376

380377
## Typing

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies:
2828
- ipywidgets
2929
- jupyterlab
3030
- matplotlib
31-
- nbval
31+
- nbmake
3232
- pre-commit
3333
- pygraphviz
3434
- pytest

pyproject.toml

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
[build-system]
22
build-backend = "setuptools.build_meta"
3-
requires = [
4-
"setuptools>=45",
5-
"setuptools_scm[toml]>=6",
6-
"wheel",
7-
]
3+
requires = ["setuptools>=64", "setuptools_scm>=8"]
84

95
[tool.setuptools_scm]
10-
write_to = "src/_pytask/_version.py"
6+
version_file = "src/_pytask/_version.py"
117

128
[project]
139
name = "pytask"
@@ -72,6 +68,7 @@ docs = [
7268
]
7369
test = [
7470
"deepdiff",
71+
"nbmake",
7572
"pexpect",
7673
"pytest",
7774
"pytest-cov",
@@ -149,15 +146,13 @@ ignore = [
149146
convention = "numpy"
150147

151148
[tool.pytest.ini_options]
152-
addopts = ["--doctest-modules"]
153-
testpaths = ["src", "tests"]
149+
testpaths = ["tests"]
154150
markers = [
155151
"wip: Tests that are work-in-progress.",
156152
"unit: Flag for unit tests which target mainly a single function.",
157153
"integration: Flag for integration tests which may comprise of multiple unit tests.",
158154
"end_to_end: Flag for tests that cover the whole program.",
159155
]
160-
norecursedirs = [".idea", ".tox"]
161156
filterwarnings = [
162157
"ignore:'@pytask.mark.*. is deprecated:FutureWarning",
163158
"ignore:The --rsyncdir command line argument:DeprecationWarning",

src/_pytask/console.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_file( # noqa: PLR0911
222222
return get_file(function.__wrapped__)
223223
source_file = inspect.getsourcefile(function)
224224
if source_file: # pragma: no cover
225-
if "<stdin>" in source_file:
225+
if "<stdin>" in source_file or "ipykernel" in source_file:
226226
return None
227227
if "<string>" in source_file:
228228
try:

src/_pytask/node_protocols.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from abc import abstractmethod
43
from typing import Any
54
from typing import Callable
65
from typing import Protocol
@@ -27,7 +26,6 @@ class PNode(Protocol):
2726
def signature(self) -> str:
2827
"""Return the signature of the node."""
2928

30-
@abstractmethod
3129
def state(self) -> str | None:
3230
"""Return the state of the node.
3331
@@ -80,7 +78,6 @@ class PTask(Protocol):
8078
def signature(self) -> str:
8179
"""Return the signature of the node."""
8280

83-
@abstractmethod
8481
def state(self) -> str | None:
8582
"""Return the state of the node.
8683

tests/test_jupyter/test_functional_interface.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"name": "python",
6565
"nbconvert_exporter": "python",
6666
"pygments_lexer": "ipython3",
67-
"version": "3.11.5"
67+
"version": "3.11.6"
6868
}
6969
},
7070
"nbformat": 4,

tests/test_jupyter/test_functional_interface_w_relative_path.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"name": "python",
6565
"nbconvert_exporter": "python",
6666
"pygments_lexer": "ipython3",
67-
"version": "3.11.5"
67+
"version": "3.11.6"
6868
}
6969
},
7070
"nbformat": 4,

tox.ini

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
[tox]
2-
envlist = pytest
2+
requires = tox>=4
3+
envlist = docs, test
34

45
[testenv]
56
passenv = CI
6-
usedevelop = true
7+
package = wheel
78

8-
[testenv:pytest]
9+
[testenv:test]
910
extras = all, test
1011
deps =
1112
pygraphviz;platform_system != "Windows"
1213

1314
commands =
14-
pytest {posargs}
15+
pytest --nbmake {posargs}
16+
17+
18+
[testenv:docs]
19+
extras = docs, test
20+
commands =
21+
- sphinx-build -n -T -b html -d {envtmpdir}/doctrees docs/source docs/build/html
22+
- sphinx-build -n -T -b doctest -d {envtmpdir}/doctrees docs/source docs/build/html

0 commit comments

Comments
 (0)