ipython-contrib / jupyter_contrib_nbextensions

A collection of various notebook extensions for Jupyter
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest
Other
5.2k stars 805 forks source link

Remove dependency on nose (port to pytest) #1587

Open mcepl opened 2 years ago

mcepl commented 2 years ago

I am a maintainer of Python packages in openSUSE, and I am on my crusade of eliminating nose1 from our distribution. When I look at its repository on https://github.com/nose-devs/nose, the last release 1.3.7 was on 2 Jun 2015, and even the last commit on the master branch was on 4 Mar 2016.

This patch eliminates dependency on nose. Resulting test suite depends on pytest, which is currently perfectly developed and maintained.

Unfortunately, all is not well, three tests fail on me, and I would appreciate some hints what I do wrong:

[   31s] ____________ TestNbConvertExporters.test_html_collapsible_headings _____________
[   31s]
[   31s] self = <test_exporters.TestNbConvertExporters testMethod=test_html_collapsible_headings>
[   31s]
[   31s]     @_with_tmp_cwd
[   31s]     def test_html_collapsible_headings(self):
[   31s]         """Test exporter for inlining collapsible_headings"""
[   31s]         nb = v4.new_notebook(cells=[
[   31s]             v4.new_markdown_cell(source=('# level 1 heading')),
[   31s]             v4.new_code_cell(source='a = range(1,10)'),
[   31s]             v4.new_markdown_cell(source=('## level 2 heading')),
[   31s]             v4.new_code_cell(source='a = range(1,10)'),
[   31s]             v4.new_markdown_cell(source=('### level 3 heading')),
[   31s]             v4.new_code_cell(source='a = range(1,10)'),
[   31s]         ])
[   31s]
[   31s]         def check(byte_string, root_node):
[   31s]             assert b'collapsible_headings' in byte_string
[   31s]
[   31s] >       self.check_html(nb, 'html_ch', check_func=check)
[   31s]
[   31s] tests/test_exporters.py:90:
[   31s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   31s] tests/test_exporters.py:36: in check_html
[   31s]     self.nbconvert('--to {} "{}"'.format(exporter_name, nb_src_filename))
[   31s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   31s]
[   31s] self = <test_exporters.TestNbConvertExporters testMethod=test_html_collapsible_headings>
[   31s] parameters = ['--to', 'html_ch', 'notebook.ipynb'], ignore_return_code = False
[   31s] stdin = None
[   31s]
[   31s]     def nbconvert(self, parameters, ignore_return_code=False, stdin=None):
[   31s]         """
[   31s]         Run nbconvert as a shell command, listening for both Errors and
[   31s]         non-zero return codes. Returns the tuple (stdout, stderr) of
[   31s]         output produced during the nbconvert run.
[   31s]
[   31s]         Parameters
[   31s]         ----------
[   31s]         parameters : str, list(str)
[   31s]             List of parameters to pass to IPython.
[   31s]         ignore_return_code : optional bool (default False)
[   31s]             Throw an OSError if the return code
[   31s]         """
[   31s]         cmd = [sys.executable, '-m', 'nbconvert']
[   31s]         if sys.platform == 'win32':
[   31s]             if isinstance(parameters, (str,)):
[   31s]                 cmd = ' '.join(cmd) + ' ' + parameters
[   31s]             else:
[   31s]                 cmd = ' '.join(cmd + parameters)
[   31s]         else:
[   31s]             if isinstance(parameters, (str,)):
[   31s]                 parameters = shlex.split(parameters)
[   31s]             cmd += parameters
[   31s]         p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
[   31s]         stdout, stderr = p.communicate(input=stdin)
[   31s]         if not (p.returncode == 0 or ignore_return_code):
[   31s] >           raise OSError(stderr.decode('utf8', 'replace'))
[   31s] E           OSError: [NbConvertApp] Converting notebook notebook.ipynb to html_ch
[   31s] E           Traceback (most recent call last):
[   31s] E             File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
[   31s] E               return _run_code(code, main_globals, None,
[   31s] E             File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
[   31s] E               exec(code, run_globals)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/__main__.py", line 2, in <module>
[   31s] E               main()
[   31s] E             File "/usr/lib/python3.9/site-packages/jupyter_core/application.py", line 264, in launch_instance
[   31s] E               return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
[   31s] E             File "/usr/lib/python3.9/site-packages/traitlets/config/application.py", line 846, in launch_instance
[   31s] E               app.start()
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 360, in start
[   31s] E               self.convert_notebooks()
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 532, in convert_notebooks
[   31s] E               self.convert_single_notebook(notebook_filename)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 497, in convert_single_notebook
[   31s] E               output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 426, in export_single_notebook
[   31s] E               output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 190, in from_filename
[   31s] E               return self.from_file(f, resources=resources, **kw)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 208, in from_file
[   31s] E               return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
[   31s] E             File "/home/abuild/rpmbuild/BUILDROOT/python-jupyter-contrib-nbextensions-0.5.1-0.x86_64/usr/lib/python3.9/site-packages/jupyter_contrib_nbextensions/nbconvert_support/exporter_inliner.py", line 31, in from_notebook_node
[   31s] E               return super(ExporterInliner, self).from_notebook_node(
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/html.py", line 145, in from_notebook_node
[   31s] E               return super().from_notebook_node(nb, resources, **kw)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 392, in from_notebook_node
[   31s] E               output = self.template.render(nb=nb_copy, resources=resources)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 151, in template
[   31s] E               self._template_cached = self._load_template()
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 362, in _load_template
[   31s] E               return self.environment.get_template(template_file)
[   31s] E             File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 997, in get_template
[   31s] E               return self._load_template(name, globals)
[   31s] E             File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 958, in _load_template
[   31s] E               template = self.loader.load(self, name, self.make_globals(globals))
[   31s] E             File "/usr/lib/python3.9/site-packages/jinja2/loaders.py", line 566, in load
[   31s] E               raise TemplateNotFound(name)
[   31s] E           jinja2.exceptions.TemplateNotFound: inliner
[   31s]
[   31s] /usr/lib/python3.9/site-packages/nbconvert/tests/base.py:160: OSError
[   31s] _____________________ TestNbConvertExporters.test_htmltoc2 _____________________
[   31s]
[   31s] self = <test_exporters.TestNbConvertExporters testMethod=test_htmltoc2>
[   31s]
[   31s]     @_with_tmp_cwd
[   31s]     def test_htmltoc2(self):
[   31s]         """Test exporter for adding table of contents"""
[   31s]         nb = v4.new_notebook(cells=[
[   31s]             v4.new_code_cell(source="a = 'world'"),
[   31s]             v4.new_markdown_cell(source="# Heading"),
[   31s]         ])
[   31s]
[   31s]         def check(byte_string, root_node):
[   31s]             assert b'toc2' in byte_string
[   31s]
[   31s] >       self.check_html(nb, 'html_toc', check_func=check)
[   31s]
[   31s] tests/test_exporters.py:73:
[   31s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   31s] tests/test_exporters.py:36: in check_html
[   31s]     self.nbconvert('--to {} "{}"'.format(exporter_name, nb_src_filename))
[   31s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   31s]
[   31s] self = <test_exporters.TestNbConvertExporters testMethod=test_htmltoc2>
[   31s] parameters = ['--to', 'html_toc', 'notebook.ipynb'], ignore_return_code = False
[   31s] stdin = None
[   31s]
[   31s]     def nbconvert(self, parameters, ignore_return_code=False, stdin=None):
[   31s]         """
[   31s]         Run nbconvert as a shell command, listening for both Errors and
[   31s]         non-zero return codes. Returns the tuple (stdout, stderr) of
[   31s]         output produced during the nbconvert run.
[   31s]
[   31s]         Parameters
[   31s]         ----------
[   31s]         parameters : str, list(str)
[   31s]             List of parameters to pass to IPython.
[   31s]         ignore_return_code : optional bool (default False)
[   31s]             Throw an OSError if the return code
[   31s]         """
[   31s]         cmd = [sys.executable, '-m', 'nbconvert']
[   31s]         if sys.platform == 'win32':
[   31s]             if isinstance(parameters, (str,)):
[   31s]                 cmd = ' '.join(cmd) + ' ' + parameters
[   31s]             else:
[   31s]                 cmd = ' '.join(cmd + parameters)
[   31s]         else:
[   31s]             if isinstance(parameters, (str,)):
[   31s]                 parameters = shlex.split(parameters)
[   31s]             cmd += parameters
[   31s]         p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
[   31s]         stdout, stderr = p.communicate(input=stdin)
[   31s]         if not (p.returncode == 0 or ignore_return_code):
[   31s] >           raise OSError(stderr.decode('utf8', 'replace'))
[   31s] E           OSError: [NbConvertApp] Converting notebook notebook.ipynb to html_toc
[   31s] E           Traceback (most recent call last):
[   31s] E             File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
[   31s] E               return _run_code(code, main_globals, None,
[   31s] E             File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
[   31s] E               exec(code, run_globals)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/__main__.py", line 2, in <module>
[   31s] E               main()
[   31s] E             File "/usr/lib/python3.9/site-packages/jupyter_core/application.py", line 264, in launch_instance
[   31s] E               return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
[   31s] E             File "/usr/lib/python3.9/site-packages/traitlets/config/application.py", line 846, in launch_instance
[   31s] E               app.start()
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 360, in start
[   31s] E               self.convert_notebooks()
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 532, in convert_notebooks
[   31s] E               self.convert_single_notebook(notebook_filename)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 497, in convert_single_notebook
[   31s] E               output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 426, in export_single_notebook
[   31s] E               output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 190, in from_filename
[   31s] E               return self.from_file(f, resources=resources, **kw)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 208, in from_file
[   31s] E               return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/html.py", line 145, in from_notebook_node
[   31s] E               return super().from_notebook_node(nb, resources, **kw)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 392, in from_notebook_node
[   31s] E               output = self.template.render(nb=nb_copy, resources=resources)
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 151, in template
[   31s] E               self._template_cached = self._load_template()
[   31s] E             File "/usr/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 362, in _load_template
[   31s] E               return self.environment.get_template(template_file)
[   31s] E             File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 997, in get_template
[   31s] E               return self._load_template(name, globals)
[   31s] E             File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 958, in _load_template
[   31s] E               template = self.loader.load(self, name, self.make_globals(globals))
[   31s] E             File "/usr/lib/python3.9/site-packages/jinja2/loaders.py", line 566, in load
[   31s] E               raise TemplateNotFound(name)
[   31s] E           jinja2.exceptions.TemplateNotFound: toc2
[   31s]
[   31s] /usr/lib/python3.9/site-packages/nbconvert/tests/base.py:160: OSError
[   31s] ________________________ test_preprocessor_execute_time ________________________
[   31s]
[   31s]     def test_preprocessor_execute_time():
[   31s]         """Test ExecuteTime preprocessor."""
[   31s]         # check import shortcut
[   31s]         from jupyter_contrib_nbextensions.nbconvert_support import ExecuteTimePreprocessor  # noqa E501
[   31s]         notebook_node = nbf.new_notebook(cells=[
[   31s]             nbf.new_code_cell(source="a = 'world'"),
[   31s]             nbf.new_code_cell(source="import time\ntime.sleep(2)"),
[   31s]         ])
[   31s]         body, resources = export_through_preprocessor(
[   31s]             notebook_node, ExecuteTimePreprocessor, NotebookExporter, 'ipynb')
[   31s]         cells = json.loads(body)['cells']
[   31s]         for cell in cells:
[   31s]             if cell['cell_type'] != 'code':
[   31s]                 assert 'ExecuteTime' not in cell['metadata']
[   31s]             else:
[   31s] >               assert 'ExecuteTime' in cell['metadata']
[   31s] E               AssertionError: assert 'ExecuteTime' in {'execution': {'iopub.execute_input': '2022-01-29T21:26:06.400652Z', 'iopub.status.busy': '2022-01-29T21:26:06.399666Z', 'iopub.status.idle': '2022-01-29T21:26:06.402629Z', 'shell.execute_reply': '2022-01-29T21:26:06.403176Z'}}
[   31s]
[   31s] tests/test_preprocessors.py:210: AssertionError
[   31s] =============================== warnings summary ===============================
[   31s] tests/test_application.py::AppTest::test_03_app_install_defaults
[   31s] tests/test_application.py::AppTest::test_05_app_install_user
[   31s] tests/test_application.py::AppTest::test_07_app_install_sys_prefix
[   31s] tests/test_application.py::AppTest::test_08_app_install_system
[   31s] tests/test_application.py::AppTest::test_09_app_install_symlink
[   31s] tests/test_application.py::AppTest::test_11_app_install_nbextensions_dir
[   31s] tests/test_application.py::AppTest::test_13_app_install_prefix
[   31s] tests/test_application.py::AppTest::test_15_app_install_only_config
[   31s]   /usr/lib/python3.9/site-packages/traitlets/config/configurable.py:85: DeprecationWarning: Passing unrecognized arguments to super(EnableJupyterNbextensionsConfiguratorApp).__init__(logger=<Logger InstallContribNbextensionsApp (INFO)>).
[   31s]   object.__init__() takes exactly one argument (the instance to initialize)
[   31s]   This is deprecated in traitlets 4.2.This error will be raised in a future release of traitlets.
[   31s]     super(Configurable, self).__init__(**kwargs)
[   31s]
[   31s] -- Docs: https://docs.pytest.org/en/stable/warnings.html
[   31s] =========================== short test summary info ============================
[   31s] FAILED tests/test_exporters.py::TestNbConvertExporters::test_html_collapsible_headings
[   31s] FAILED tests/test_exporters.py::TestNbConvertExporters::test_htmltoc2 - OSErr...
[   31s] FAILED tests/test_preprocessors.py::test_preprocessor_execute_time - Assertio...
[   31s] ============= 3 failed, 20 passed, 3 skipped, 8 warnings in 22.04s =============