Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pytest settings and handle warnings #1745

Merged
merged 17 commits into from Apr 2, 2022
9 changes: 6 additions & 3 deletions .github/workflows/docs.yml
@@ -1,17 +1,20 @@
name: Generate Docs
name: Docs

on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: docs-${{ github.ref }}
cancel-in-progress: true

jobs:
generate-docs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.7', '3.9', '3.10' ]
python-version: [ '3.7', '3.10' ]
steps:
- name: Check out repository code
uses: actions/checkout@v2
Expand Down
33 changes: 17 additions & 16 deletions .github/workflows/tests.yml
Expand Up @@ -4,20 +4,26 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

jobs:
run-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: [ '3.7', '3.8', '3.9', '3.10', 'pypy-3.7']
exclude:
python-version: ['3.7', '3.10']
include:
- os: "windows-latest"
python-version: "pypy-3.7"
- os: "macos-latest"
python-version: "3.8"
- os: "macos-latest"
python-version: "3.9"
- os: "ubuntu-latest"
python-version: "pypy-3.8"
fail-fast: false
steps:
- name: Check out repository code
uses: actions/checkout@v2
Expand All @@ -31,7 +37,7 @@ jobs:
sudo apt-get install texlive-plain-generic inkscape texlive-xetex

# pandoc is not up to date in the ubuntu repos, so we install directly
wget https://github.com/jgm/pandoc/releases/download/2.14.2/pandoc-2.14.2-1-amd64.deb && sudo dpkg -i pandoc-2.14.2-1-amd64.deb
wget https://github.com/jgm/pandoc/releases/download/2.17.1.1/pandoc-2.17.1.1-1-amd64.deb && sudo dpkg -i pandoc-2.17.1.1-1-amd64.deb

- name: Install package dependencies
shell: bash
Expand All @@ -48,29 +54,24 @@ jobs:
pip freeze
pip check

- name: Check Manifest
run: check-manifest --ignore "share/**"

- name: Run tests with coverage
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(runner.os, 'Windows') }}
shell: bash
env:
PYTHONWARNINGS: default
run: |
check-manifest --ignore "share/**"
# See https://github.com/pyppeteer/pyppeteer/pull/321
pip install -U websockets --user
# cd so we test the install, not the repo
cd $HOME
pytest --cov nbconvert -v --pyargs nbconvert
python -m pytest --cov nbconvert -vv

- name: Run tests on pypy and Windows
if: ${{ startsWith(matrix.python-version, 'pypy') || startsWith(runner.os, 'Windows') }}
shell: bash
run: |

# cd so we test the install, not the repo
cd $HOME
# See https://github.com/pyppeteer/pyppeteer/pull/321
pip install -U websockets --user
pytest -v --pyargs nbconvert
python -m pytest -vv

- name: Code coverage
run: codecov
2 changes: 2 additions & 0 deletions MANIFEST.in
Expand Up @@ -5,6 +5,8 @@ include .mailmap
include MANIFEST.in
include nbconvert/templates/skeleton/Makefile
include nbconvert/tests/README.md
include pyproject.toml
include setup.py

# Documentation
graft docs
Expand Down
5 changes: 5 additions & 0 deletions nbconvert/conftest.py
@@ -0,0 +1,5 @@
import asyncio
import os

if os.name == 'nt':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
2 changes: 1 addition & 1 deletion nbconvert/filters/filter_links.py
Expand Up @@ -33,7 +33,7 @@ def resolve_one_reference(key, val, fmt, meta):
# pandoc automatically makes labels for headings.
label = m.group(1).lower()
label = re.sub(r'[^\w-]+', '', label) # Strip HTML entities
text = re.sub(r'_', '\_', text) # Escape underscores in display text
text = re.sub(r'_', r'\_', text) # Escape underscores in display text
return RawInline('tex', r'\hyperref[{label}]{{{text}}}'.format(label=label, text=text))

# Other elements will be returned unchanged.
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/filters/strings.py
Expand Up @@ -204,15 +204,15 @@ def ipython2python(code):
IPython code, to be transformed to pure Python
"""
try:
from IPython.core.inputsplitter import IPythonInputSplitter
from IPython.core.inputtransformer2 import TransformerManager
except ImportError:
warnings.warn(
"IPython is needed to transform IPython syntax to pure Python."
" Install ipython if you need this functionality."
)
return code
else:
isp = IPythonInputSplitter(line_input_checker=False)
isp = TransformerManager()
return isp.transform_cell(code)

def posix_path(path):
Expand Down
9 changes: 6 additions & 3 deletions nbconvert/filters/tests/test_datatypefilter.py
Expand Up @@ -2,7 +2,7 @@

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import pytest
from ...tests.base import TestsBase
from ..datatypefilter import DataTypeFilter

Expand All @@ -19,9 +19,12 @@ def test_junk_types(self):
filter = DataTypeFilter()
assert "image/png" in filter({"hair":"1", "water":2, "image/png":3, "rock":4.0})
assert "application/pdf" in filter({"application/pdf":"file_path", "hair":2, "water":"yay", "png":'not a png', "rock":'is a rock'})
self.assertEqual(filter({"hair":"this is not", "water":"going to return anything", "rock":"or is it"}), [])

with pytest.warns(UserWarning):
self.assertEqual(filter({"hair":"this is not", "water":"going to return anything", "rock":"or is it"}), [])

def test_null(self):
"""Will the DataTypeFilter fail if no types are passed in?"""
filter = DataTypeFilter()
self.assertEqual(filter({}), [])
with pytest.warns(UserWarning):
self.assertEqual(filter({}), [])
4 changes: 2 additions & 2 deletions nbconvert/filters/tests/test_strings.py
Expand Up @@ -151,8 +151,8 @@ def test_get_lines(self):
def test_ipython2python(self):
"""ipython2python test"""
#TODO: More tests
results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'")
self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')",
results = ipython2python('%%pylab\nprint("Hello-World")').replace("u'", "'")
self.fuzzy_compare(results.replace(r'\n', ''), "get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')",
ignore_spaces=True, ignore_newlines=True)

def test_posix_path(self):
Expand Down
2 changes: 2 additions & 0 deletions nbconvert/utils/tests/test_pandoc.py
Expand Up @@ -14,6 +14,7 @@

from ...tests.utils import onlyif_cmds_exist

import pytest
from nbconvert.tests.base import TestsBase
from .. import pandoc

Expand Down Expand Up @@ -59,6 +60,7 @@ def test_minimal_version(self):

pandoc._minimal_version = "120.0"
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
# call it twice to verify the cached value is used
assert not pandoc.check_pandoc_version()
assert not pandoc.check_pandoc_version()
Expand Down
25 changes: 25 additions & 0 deletions pyproject.toml
@@ -0,0 +1,25 @@
[build-system]
requires = ["setuptools>=60.0"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
markers = "network: marks tests which require network connection"
addopts = "-raXs --durations 10 --color=yes --doctest-modules --ignore=nbconvert/tests/files/override.py --ignore=nbconvert/tests/files/jupyter_nbconvert_config.py"
testpaths = [
"nbconvert/"
]
filterwarnings = [
"error",
"ignore:nbconvert.utils.lexers is deprecated as of 5.0:UserWarning",
# Pending https://github.com/jupyter/nbformat/pull/256
"ignore:Passing a schema to Validator.iter_errors is deprecated:DeprecationWarning",
# https://github.com/pyppeteer/pyppeteer/issues/342
"ignore:remove loop argument:DeprecationWarning:websockets",
# https://github.com/mhammond/pywin32/issues/1802
"ignore:getargs.*format is deprecated:DeprecationWarning",
# From jupyter_client
"ignore:unclosed <socket.socket:ResourceWarning",
"ignore:unclosed event loop:ResourceWarning",
"ignore:There is no current event loop:DeprecationWarning",

]
4 changes: 0 additions & 4 deletions setup.cfg
Expand Up @@ -9,10 +9,6 @@ ignore =
nbconvert/resources/style.min.css
.circleci/*

[tool:pytest]
markers =
network: marks tests which require network connection

[flake8]
ignore = E121, # continuation line under-indented for hanging indent
E123, # closing bracket does not match indentation of opening bracket's line
Expand Down
Expand Up @@ -65,6 +65,6 @@
((*- endif -*))
((*- set indention = " " * (execution_count | length + 7) -*))
\begin{Verbatim}[commandchars=\\\{\}]
((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
((( text | add_prompts(first='{\\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
\end{Verbatim}
((*- endmacro *))