From 6f2089f622ead6d79eb2a67c9b9be7cafce57bda Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Thu, 6 Sep 2018 18:42:27 -0500 Subject: [PATCH 01/10] Add option to overwrite the highlight_code filter --- nbconvert/exporters/html.py | 7 +++++-- nbconvert/exporters/latex.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index 9210e19fd..291d2ee08 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -90,8 +90,11 @@ def process_attachments(self, nb, output): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - self.register_filter('highlight_code', - Highlight2HTML(pygments_lexer=lexer, parent=self)) + highlight_code = Highlight2HTML(pygments_lexer=lexer, parent=self) + if "highlight_code" in self.filters: + highlight_code = self.filters["highlight_code"] + self.register_filter('highlight_code', highlight_code) + output, resources = super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) att_output = self.process_attachments(nb, output) return att_output, resources diff --git a/nbconvert/exporters/latex.py b/nbconvert/exporters/latex.py index 1a57405f8..fc48c4168 100644 --- a/nbconvert/exporters/latex.py +++ b/nbconvert/exporters/latex.py @@ -78,8 +78,11 @@ def default_config(self): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - self.register_filter('highlight_code', - Highlight2Latex(pygments_lexer=lexer, parent=self)) + highlight_code = Highlight2Latex(pygments_lexer=lexer, parent=self) + if "highlight_code" in self.filters: + highlight_code = self.filters["highlight_code"] + self.register_filter('highlight_code', highlight_code) + return super(LatexExporter, self).from_notebook_node(nb, resources, **kw) def _create_environment(self): From 69cdaccb3ffc4320355df04b93c12ee571a128a7 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 30 Oct 2018 12:04:33 -0500 Subject: [PATCH 02/10] Consolidate using filters.get() --- nbconvert/exporters/html.py | 4 +--- nbconvert/exporters/latex.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index 291d2ee08..e90bf927c 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -90,9 +90,7 @@ def process_attachments(self, nb, output): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - highlight_code = Highlight2HTML(pygments_lexer=lexer, parent=self) - if "highlight_code" in self.filters: - highlight_code = self.filters["highlight_code"] + highlight_code = self.filters.get('highlight_code', Highlight2HTML(pygments_lexer=lexer, parent=self)) self.register_filter('highlight_code', highlight_code) output, resources = super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) diff --git a/nbconvert/exporters/latex.py b/nbconvert/exporters/latex.py index fc48c4168..46a6188ae 100644 --- a/nbconvert/exporters/latex.py +++ b/nbconvert/exporters/latex.py @@ -78,9 +78,7 @@ def default_config(self): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - highlight_code = Highlight2Latex(pygments_lexer=lexer, parent=self) - if "highlight_code" in self.filters: - highlight_code = self.filters["highlight_code"] + highlight_code = self.filters.get('highlight_code', Highlight2Latex(pygments_lexer=lexer, parent=self)) self.register_filter('highlight_code', highlight_code) return super(LatexExporter, self).from_notebook_node(nb, resources, **kw) From 5538c09fab05836bf8df37f3fc88d1de717e1f88 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 30 Oct 2018 12:04:54 -0500 Subject: [PATCH 03/10] Add tests for custom filter highlighter --- nbconvert/exporters/tests/test_html.py | 15 +++++++++++++++ nbconvert/exporters/tests/test_latex.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/nbconvert/exporters/tests/test_html.py b/nbconvert/exporters/tests/test_html.py index cb8c88144..8183b4194 100644 --- a/nbconvert/exporters/tests/test_html.py +++ b/nbconvert/exporters/tests/test_html.py @@ -119,3 +119,18 @@ def test_attachments(self): result = check_for_png.search(output) self.assertTrue(result.group(0).strip().startswith(' Date: Thu, 6 Sep 2018 18:42:27 -0500 Subject: [PATCH 04/10] Add option to overwrite the highlight_code filter --- nbconvert/exporters/html.py | 7 +++++-- nbconvert/exporters/latex.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index 9210e19fd..291d2ee08 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -90,8 +90,11 @@ def process_attachments(self, nb, output): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - self.register_filter('highlight_code', - Highlight2HTML(pygments_lexer=lexer, parent=self)) + highlight_code = Highlight2HTML(pygments_lexer=lexer, parent=self) + if "highlight_code" in self.filters: + highlight_code = self.filters["highlight_code"] + self.register_filter('highlight_code', highlight_code) + output, resources = super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) att_output = self.process_attachments(nb, output) return att_output, resources diff --git a/nbconvert/exporters/latex.py b/nbconvert/exporters/latex.py index 1a57405f8..fc48c4168 100644 --- a/nbconvert/exporters/latex.py +++ b/nbconvert/exporters/latex.py @@ -78,8 +78,11 @@ def default_config(self): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - self.register_filter('highlight_code', - Highlight2Latex(pygments_lexer=lexer, parent=self)) + highlight_code = Highlight2Latex(pygments_lexer=lexer, parent=self) + if "highlight_code" in self.filters: + highlight_code = self.filters["highlight_code"] + self.register_filter('highlight_code', highlight_code) + return super(LatexExporter, self).from_notebook_node(nb, resources, **kw) def _create_environment(self): From a25fbbd91caa4a525bab8f494e08230eb7f770e8 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 30 Oct 2018 12:04:33 -0500 Subject: [PATCH 05/10] Consolidate using filters.get() --- nbconvert/exporters/html.py | 4 +--- nbconvert/exporters/latex.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index 291d2ee08..e90bf927c 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -90,9 +90,7 @@ def process_attachments(self, nb, output): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - highlight_code = Highlight2HTML(pygments_lexer=lexer, parent=self) - if "highlight_code" in self.filters: - highlight_code = self.filters["highlight_code"] + highlight_code = self.filters.get('highlight_code', Highlight2HTML(pygments_lexer=lexer, parent=self)) self.register_filter('highlight_code', highlight_code) output, resources = super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) diff --git a/nbconvert/exporters/latex.py b/nbconvert/exporters/latex.py index fc48c4168..46a6188ae 100644 --- a/nbconvert/exporters/latex.py +++ b/nbconvert/exporters/latex.py @@ -78,9 +78,7 @@ def default_config(self): def from_notebook_node(self, nb, resources=None, **kw): langinfo = nb.metadata.get('language_info', {}) lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) - highlight_code = Highlight2Latex(pygments_lexer=lexer, parent=self) - if "highlight_code" in self.filters: - highlight_code = self.filters["highlight_code"] + highlight_code = self.filters.get('highlight_code', Highlight2Latex(pygments_lexer=lexer, parent=self)) self.register_filter('highlight_code', highlight_code) return super(LatexExporter, self).from_notebook_node(nb, resources, **kw) From cb77d2a54f490c726a63b0ea4bd61e3e8ea317ba Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 30 Oct 2018 12:04:54 -0500 Subject: [PATCH 06/10] Add tests for custom filter highlighter --- nbconvert/exporters/tests/test_html.py | 15 +++++++++++++++ nbconvert/exporters/tests/test_latex.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/nbconvert/exporters/tests/test_html.py b/nbconvert/exporters/tests/test_html.py index cb8c88144..8183b4194 100644 --- a/nbconvert/exporters/tests/test_html.py +++ b/nbconvert/exporters/tests/test_html.py @@ -119,3 +119,18 @@ def test_attachments(self): result = check_for_png.search(output) self.assertTrue(result.group(0).strip().startswith(' Date: Tue, 30 Oct 2018 16:32:49 -0500 Subject: [PATCH 07/10] Fix tests for multiple ipython versions --- .../{Interrupt.ipynb => Interrupt-IPY6.ipynb} | 0 .../tests/files/Interrupt-IPY7.ipynb | 63 +++++++++++++++++++ nbconvert/preprocessors/tests/test_execute.py | 11 +++- 3 files changed, 73 insertions(+), 1 deletion(-) rename nbconvert/preprocessors/tests/files/{Interrupt.ipynb => Interrupt-IPY6.ipynb} (100%) create mode 100644 nbconvert/preprocessors/tests/files/Interrupt-IPY7.ipynb diff --git a/nbconvert/preprocessors/tests/files/Interrupt.ipynb b/nbconvert/preprocessors/tests/files/Interrupt-IPY6.ipynb similarity index 100% rename from nbconvert/preprocessors/tests/files/Interrupt.ipynb rename to nbconvert/preprocessors/tests/files/Interrupt-IPY6.ipynb diff --git a/nbconvert/preprocessors/tests/files/Interrupt-IPY7.ipynb b/nbconvert/preprocessors/tests/files/Interrupt-IPY7.ipynb new file mode 100644 index 000000000..333dcf7e1 --- /dev/null +++ b/nbconvert/preprocessors/tests/files/Interrupt-IPY7.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mcontinue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "while True: continue" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "done\n" + ] + } + ], + "source": [ + "print(\"done\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/nbconvert/preprocessors/tests/test_execute.py b/nbconvert/preprocessors/tests/test_execute.py index 52af82508..98252d873 100644 --- a/nbconvert/preprocessors/tests/test_execute.py +++ b/nbconvert/preprocessors/tests/test_execute.py @@ -21,6 +21,7 @@ from .base import PreprocessorTestsBase from ..execute import ExecutePreprocessor, CellExecutionError, executenb +import IPython from nbconvert.filters import strip_ansi from testpath import modified_env from ipython_genutils.py3compat import string_types @@ -126,7 +127,15 @@ def test_run_notebooks(self): for filename in input_files: if os.path.basename(filename) == "Disable Stdin.ipynb": continue - elif os.path.basename(filename) == "Interrupt.ipynb": + elif os.path.basename(filename) == "Interrupt-IPY6.ipynb": + IPY_MAJOR = IPython.version_info[0] + if IPY_MAJOR > 7: + continue + opts = dict(timeout=1, interrupt_on_timeout=True, allow_errors=True) + elif os.path.basename(filename) == "Interrupt-IPY7.ipynb": + IPY_MAJOR = IPython.version_info[0] + if IPY_MAJOR < 7: + continue opts = dict(timeout=1, interrupt_on_timeout=True, allow_errors=True) elif os.path.basename(filename) == "Skip Exceptions.ipynb": opts = dict(allow_errors=True) From 0834fe8a36f287b980aea153f5ebad4e36f3e16c Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 30 Oct 2018 17:21:57 -0500 Subject: [PATCH 08/10] Fix tests for multiple ipython versions --- .../tests/files/{Interrupt-IPY7.ipynb => Interrupt.ipynb} | 0 nbconvert/preprocessors/tests/test_execute.py | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) rename nbconvert/preprocessors/tests/files/{Interrupt-IPY7.ipynb => Interrupt.ipynb} (100%) diff --git a/nbconvert/preprocessors/tests/files/Interrupt-IPY7.ipynb b/nbconvert/preprocessors/tests/files/Interrupt.ipynb similarity index 100% rename from nbconvert/preprocessors/tests/files/Interrupt-IPY7.ipynb rename to nbconvert/preprocessors/tests/files/Interrupt.ipynb diff --git a/nbconvert/preprocessors/tests/test_execute.py b/nbconvert/preprocessors/tests/test_execute.py index 98252d873..68a8d22d3 100644 --- a/nbconvert/preprocessors/tests/test_execute.py +++ b/nbconvert/preprocessors/tests/test_execute.py @@ -127,14 +127,14 @@ def test_run_notebooks(self): for filename in input_files: if os.path.basename(filename) == "Disable Stdin.ipynb": continue - elif os.path.basename(filename) == "Interrupt-IPY6.ipynb": + elif os.path.basename(filename) == "Interrupt.ipynb": IPY_MAJOR = IPython.version_info[0] - if IPY_MAJOR > 7: + if IPY_MAJOR < 7: continue opts = dict(timeout=1, interrupt_on_timeout=True, allow_errors=True) - elif os.path.basename(filename) == "Interrupt-IPY7.ipynb": + elif os.path.basename(filename) == "Interrupt-IPY6.ipynb": IPY_MAJOR = IPython.version_info[0] - if IPY_MAJOR < 7: + if IPY_MAJOR > 7: continue opts = dict(timeout=1, interrupt_on_timeout=True, allow_errors=True) elif os.path.basename(filename) == "Skip Exceptions.ipynb": From 2e5c3f94071d20dcfb8256bbdeb565906a38ccbf Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 30 Oct 2018 17:41:28 -0500 Subject: [PATCH 09/10] Fix tests for multiple ipython versions --- .../Skip Exceptions with Cell Tags-IPY6.ipynb | 50 +++++++++++++++++++ .../Skip Exceptions with Cell Tags.ipynb | 2 +- .../tests/files/Skip Exceptions-IPY6.ipynb | 50 +++++++++++++++++++ .../tests/files/Skip Exceptions.ipynb | 2 +- nbconvert/preprocessors/tests/test_execute.py | 23 +++++---- 5 files changed, 115 insertions(+), 12 deletions(-) create mode 100644 nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags-IPY6.ipynb create mode 100644 nbconvert/preprocessors/tests/files/Skip Exceptions-IPY6.ipynb diff --git a/nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags-IPY6.ipynb b/nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags-IPY6.ipynb new file mode 100644 index 000000000..aeba4a2c6 --- /dev/null +++ b/nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags-IPY6.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "tags": [ + "raises-exception" + ] + }, + "outputs": [ + { + "ename": "Exception", + "evalue": "message", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# üñîçø∂é\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"message\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mException\u001b[0m: message" + ] + } + ], + "source": [ + "# üñîçø∂é\n", + "raise Exception(\"message\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "source": [ + "print('ok')" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags.ipynb b/nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags.ipynb index aeba4a2c6..9896d16b1 100644 --- a/nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags.ipynb +++ b/nbconvert/preprocessors/tests/files/Skip Exceptions with Cell Tags.ipynb @@ -16,7 +16,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# üñîçø∂é\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"message\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# üñîçø∂é\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"message\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mException\u001b[0m: message" ] } diff --git a/nbconvert/preprocessors/tests/files/Skip Exceptions-IPY6.ipynb b/nbconvert/preprocessors/tests/files/Skip Exceptions-IPY6.ipynb new file mode 100644 index 000000000..f9063e563 --- /dev/null +++ b/nbconvert/preprocessors/tests/files/Skip Exceptions-IPY6.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "Exception", + "evalue": "message", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mException\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# üñîçø∂é\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"message\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mException\u001b[0m: message" + ] + } + ], + "source": [ + "# üñîçø∂é\n", + "raise Exception(\"message\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "source": [ + "print('ok')" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/nbconvert/preprocessors/tests/files/Skip Exceptions.ipynb b/nbconvert/preprocessors/tests/files/Skip Exceptions.ipynb index f9063e563..2a0fc0abb 100644 --- a/nbconvert/preprocessors/tests/files/Skip Exceptions.ipynb +++ b/nbconvert/preprocessors/tests/files/Skip Exceptions.ipynb @@ -14,7 +14,7 @@ "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mException\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# üñîçø∂é\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"message\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# üñîçø∂é\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"message\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mException\u001b[0m: message" ] } diff --git a/nbconvert/preprocessors/tests/test_execute.py b/nbconvert/preprocessors/tests/test_execute.py index 68a8d22d3..ce40849fb 100644 --- a/nbconvert/preprocessors/tests/test_execute.py +++ b/nbconvert/preprocessors/tests/test_execute.py @@ -125,19 +125,22 @@ def test_run_notebooks(self): input_files = glob.glob(os.path.join(current_dir, 'files', '*.ipynb')) shared_opts = dict(kernel_name="python") for filename in input_files: - if os.path.basename(filename) == "Disable Stdin.ipynb": - continue - elif os.path.basename(filename) == "Interrupt.ipynb": - IPY_MAJOR = IPython.version_info[0] - if IPY_MAJOR < 7: + # There is some slight differences between the output in IPython 6 and IPython 7. + IPY_MAJOR = IPython.version_info[0] + if os.path.basename(filename).endswith("-IPY6.ipynb"): + print(filename, IPY_MAJOR) + if IPY_MAJOR >= 7: continue - opts = dict(timeout=1, interrupt_on_timeout=True, allow_errors=True) - elif os.path.basename(filename) == "Interrupt-IPY6.ipynb": - IPY_MAJOR = IPython.version_info[0] - if IPY_MAJOR > 7: + elif os.path.basename(filename) in ("Interrupt.ipynb", "Skip Exceptions with Cell Tags.ipynb", "Skip Exceptions.ipynb"): + if IPY_MAJOR < 7: continue + + # Special arguments for the notebooks + if os.path.basename(filename) == "Disable Stdin.ipynb": + continue + elif os.path.basename(filename) in ("Interrupt.ipynb", "Interrupt-IPY6.ipynb"): opts = dict(timeout=1, interrupt_on_timeout=True, allow_errors=True) - elif os.path.basename(filename) == "Skip Exceptions.ipynb": + elif os.path.basename(filename) in ("Skip Exceptions.ipynb", "Skip Exceptions-IPY6.ipynb"): opts = dict(allow_errors=True) else: opts = dict() From b61090c50ec5b0a3da9c4297c657ae831d882426 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 30 Oct 2018 17:51:28 -0500 Subject: [PATCH 10/10] Fix tests for multiple ipython versions --- .../preprocessors/tests/files/Interrupt.ipynb | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/nbconvert/preprocessors/tests/files/Interrupt.ipynb b/nbconvert/preprocessors/tests/files/Interrupt.ipynb index 333dcf7e1..9c22011b0 100644 --- a/nbconvert/preprocessors/tests/files/Interrupt.ipynb +++ b/nbconvert/preprocessors/tests/files/Interrupt.ipynb @@ -3,7 +3,9 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "ename": "KeyboardInterrupt", @@ -24,7 +26,9 @@ { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -39,25 +43,7 @@ ] } ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.5" - } - }, + "metadata": {}, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 0 }