Skip to content

Commit 04ab8b0

Browse files
committed
work around warnings caused by testing
add cell ids don't nbnormalize (no point doing this until we know we have to)
1 parent c74fae1 commit 04ab8b0

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

pkg/tests/test_nb_fns.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11

22
import os
33
import pytest
4-
from nbconvert.preprocessors.execute import CellExecutionError
4+
import warnings
5+
6+
# importing nbconvert components such as nbconvert.preprocessors.execute
7+
# while in pytest causes the following warning:
8+
#
9+
# jupyter_client/connect.py:27: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
10+
# given by the platformdirs library. To remove this warning and
11+
# see the appropriate new directories, set the environment variable
12+
# `JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.
13+
# The use of platformdirs will be the default in `jupyter_core` v6
14+
# from jupyter_core.paths import jupyter_data_dir
15+
# -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
16+
#
17+
# likely this is from some environment isolation set up by pytest
18+
# the same code does not warn when executing directly
19+
#
20+
# so we are going to trigger the warning on first import, so it is caught
21+
# and does not reoccur when we import wvpy.jtools components
22+
with warnings.catch_warnings():
23+
warnings.simplefilter("ignore")
24+
from nbconvert.preprocessors.execute import CellExecutionError # even importing this causes warning
525

626
from wvpy.jtools import render_as_html, convert_py_code_to_notebook, convert_notebook_code_to_py
727

828

9-
# Was seeing:
10-
# nbconvert/filters/ansi.py:60: DeprecationWarning: 'jinja2.escape' is deprecated and will be removed in Jinja 3.1. Import 'markupsafe.escape' instead.
11-
# @pytest.mark.filterwarnings("ignore:")
29+
# confirm we have not killed all warnings
30+
def test_still_warns_even_after_monkeying():
31+
with pytest.warns(DeprecationWarning):
32+
warnings.warn(DeprecationWarning("test warning"))
33+
34+
1235
def test_jupyter_notebook_good():
1336
source_dir = os.path.dirname(os.path.realpath(__file__))
1437
orig_wd = os.getcwd()
@@ -54,7 +77,7 @@ def test_jupyter_notebook_bad():
5477
+ 4)
5578
"""
5679

57-
# @pytest.mark.filterwarnings("ignore:")
80+
5881
def test_jupyter_notebook_parameterized_good():
5982
source_dir = os.path.dirname(os.path.realpath(__file__))
6083
orig_wd = os.getcwd()

pkg/wvpy/jtools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525

2626
nbf_v = nbformat.v4
2727

28-
def _normalize(nb):
29-
return nbformat.validator.normalize(nb, version=4, version_minor=5)[1]
28+
#def _normalize(nb):
29+
# # try and work around version mismatches
30+
# return nbformat.validator.normalize(nb, version=4, version_minor=5)[1]
3031

3132

3233
# noinspection PyBroadException
@@ -117,7 +118,7 @@ def convert_py_code_to_notebook(
117118
for i in range(len(cells)):
118119
cells[i]["id"] = f"cell{i}"
119120
nb = nbf_v.new_notebook(cells=cells)
120-
nb = _normalize(nb)
121+
# nb = _normalize(nb)
121122
return nb
122123

123124

@@ -144,7 +145,7 @@ def prepend_code_cell_to_notebook(
144145
nb_out = nbf_v.new_notebook(
145146
cells=cells
146147
)
147-
nb_out = _normalize(nb_out)
148+
# nb_out = _normalize(nb_out)
148149
return nb_out
149150

150151

0 commit comments

Comments
 (0)