Skip to content

Commit

Permalink
specify encoding to open file
Browse files Browse the repository at this point in the history
  • Loading branch information
AgnieszkaZaba committed Oct 12, 2024
1 parent dcb2c4c commit e044cfe
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

SI = pint.UnitRegistry()

COLAB_HEADER = """import sys
if 'google.colab' in sys.modules:
!pip --quiet install open-atmos-jupyter-utils
from open_atmos_jupyter_utils import pip_install_on_colab
pip_install_on_colab('PySDM-examples')"""

@pytest.fixture(
params=find_files(file_extension=".ipynb"),
Expand Down Expand Up @@ -83,13 +88,6 @@ def test_jetbrains_bug_py_66491(notebook_filename):
+ " (could be due to a bug in PyCharm,"
+ " see https://youtrack.jetbrains.com/issue/PY-66491 )"
)


COLAB_HEADER = """import sys
if 'google.colab' in sys.modules:
!pip --quiet install open-atmos-jupyter-utils
from open_atmos_jupyter_utils import pip_install_on_colab
pip_install_on_colab('PySDM-examples')"""

def _relative_path(absolute_path):
return os.path.relpath(
Expand All @@ -114,7 +112,7 @@ def _colab_badge_markdown(absolute_path):

def test_first_cell_contains_three_badges(notebook):
""" checks if all notebooks feature nbviewer, mybinder and Colab badges (in the first cell) """
with open(notebook) as fp:
with open(notebook, encoding="utf8") as fp:
nb = nbformat.read(fp, nbformat.NO_CONVERT)
assert len(nb.cells) > 0
assert nb.cells[0].cell_type == "markdown"
Expand All @@ -127,15 +125,15 @@ def test_first_cell_contains_three_badges(notebook):

def test_second_cell_is_a_markdown_cell(notebook):
""" checks if all notebooks have their second cell with some markdown (hopefully clarifying what the example is about) """
with open(notebook) as fp:
with open(notebook, encoding="utf8") as fp:
nb = nbformat.read(fp, nbformat.NO_CONVERT)
assert len(nb.cells) > 1
assert nb.cells[1].cell_type == "markdown"


def test_third_cell_contains_colab_header(notebook):
""" checks if all notebooks feature a Colab-magic cell """
with open(notebook) as fp:
with open(notebook, encoding="utf8") as fp:
nb = nbformat.read(fp, nbformat.NO_CONVERT)
assert len(nb.cells) > 2
assert nb.cells[2].cell_type == "code"
Expand Down

0 comments on commit e044cfe

Please sign in to comment.