From a111b9ca62f3f88719204d8a32fbf261a4ce6960 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 1 Apr 2022 23:49:29 -0500 Subject: [PATCH] Add pytest settings and handle warnings (#1745) --- .github/workflows/docs.yml | 9 +++-- .github/workflows/tests.yml | 33 ++++++++++--------- MANIFEST.in | 2 ++ nbconvert/conftest.py | 5 +++ nbconvert/filters/filter_links.py | 2 +- nbconvert/filters/strings.py | 4 +-- .../filters/tests/test_datatypefilter.py | 9 +++-- nbconvert/filters/tests/test_strings.py | 4 +-- nbconvert/utils/tests/test_pandoc.py | 2 ++ pyproject.toml | 25 ++++++++++++++ setup.cfg | 4 --- .../templates/latex/style_ipython.tex.j2 | 2 +- 12 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 nbconvert/conftest.py create mode 100644 pyproject.toml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 139c02c3d..a3ac9dd32 100644 --- a/.github/workflows/docs.yml +++ b/.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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 648b5e447..4e195fc4f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,10 @@ on: push: branches: [main] pull_request: - branches: [main] + +concurrency: + group: tests-${{ github.ref }} + cancel-in-progress: true jobs: run-tests: @@ -12,12 +15,15 @@ jobs: 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 @@ -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 @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in index de4112031..54a92652d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/nbconvert/conftest.py b/nbconvert/conftest.py new file mode 100644 index 000000000..ffc7eb257 --- /dev/null +++ b/nbconvert/conftest.py @@ -0,0 +1,5 @@ +import asyncio +import os + +if os.name == 'nt': + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) diff --git a/nbconvert/filters/filter_links.py b/nbconvert/filters/filter_links.py index 3b64fd1a4..9557749c3 100644 --- a/nbconvert/filters/filter_links.py +++ b/nbconvert/filters/filter_links.py @@ -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. diff --git a/nbconvert/filters/strings.py b/nbconvert/filters/strings.py index 38e2f4ba9..4633bab81 100755 --- a/nbconvert/filters/strings.py +++ b/nbconvert/filters/strings.py @@ -204,7 +204,7 @@ 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." @@ -212,7 +212,7 @@ def ipython2python(code): ) return code else: - isp = IPythonInputSplitter(line_input_checker=False) + isp = TransformerManager() return isp.transform_cell(code) def posix_path(path): diff --git a/nbconvert/filters/tests/test_datatypefilter.py b/nbconvert/filters/tests/test_datatypefilter.py index 1ef3a1f19..50f6fdfc0 100644 --- a/nbconvert/filters/tests/test_datatypefilter.py +++ b/nbconvert/filters/tests/test_datatypefilter.py @@ -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 @@ -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({}), []) diff --git a/nbconvert/filters/tests/test_strings.py b/nbconvert/filters/tests/test_strings.py index c54aaf485..e94b1a502 100644 --- a/nbconvert/filters/tests/test_strings.py +++ b/nbconvert/filters/tests/test_strings.py @@ -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): diff --git a/nbconvert/utils/tests/test_pandoc.py b/nbconvert/utils/tests/test_pandoc.py index 162847989..656b46797 100644 --- a/nbconvert/utils/tests/test_pandoc.py +++ b/nbconvert/utils/tests/test_pandoc.py @@ -14,6 +14,7 @@ from ...tests.utils import onlyif_cmds_exist +import pytest from nbconvert.tests.base import TestsBase from .. import pandoc @@ -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() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..3df9ceba2 --- /dev/null +++ b/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