From 9b5a6a063d4fcab84ebd29be2b78bdad6e734ff7 2013-08-01 23:56:42 From: Jonathan Frederic Date: 2013-08-01 23:56:42 Subject: [PATCH] Use IPython parameterized testing --- diff --git a/IPython/nbconvert/filters/tests/test_ansi.py b/IPython/nbconvert/filters/tests/test_ansi.py index 29446d7..c6d9d17 100644 --- a/IPython/nbconvert/filters/tests/test_ansi.py +++ b/IPython/nbconvert/filters/tests/test_ansi.py @@ -14,7 +14,6 @@ Module with tests for ansi filters # Imports #----------------------------------------------------------------------------- -from IPython.testing import decorators as dec from IPython.utils.coloransi import TermColors from ...tests.base import TestsBase @@ -28,7 +27,6 @@ from ..ansi import strip_ansi, ansi2html, ansi2latex class TestAnsi(TestsBase): """Contains test functions for ansi.py""" - @dec.parametric def test_strip_ansi(self): """strip_ansi test""" correct_outputs = { @@ -41,14 +39,13 @@ class TestAnsi(TestsBase): 'hello' : 'hello'} for inval, outval in correct_outputs.items(): - yield self._try_strip_ansi, inval, outval + yield self._try_strip_ansi(inval, outval) def _try_strip_ansi(self, inval, outval): - self.assert_equal(outval, strip_ansi(inval)) + self.assertEqual(outval, strip_ansi(inval)) - @dec.parametric def test_ansi2html(self): """ansi2html test""" correct_outputs = { @@ -61,14 +58,13 @@ class TestAnsi(TestsBase): 'hello' : 'hello'} for inval, outval in correct_outputs.items(): - yield self._try_ansi2html, inval, outval + yield self._try_ansi2html(inval, outval) def _try_ansi2html(self, inval, outval): self.fuzzy_compare(outval, ansi2html(inval)) - @dec.parametric def test_ansi2latex(self): """ansi2latex test""" correct_outputs = { @@ -81,7 +77,7 @@ class TestAnsi(TestsBase): 'hello' : 'hello'} for inval, outval in correct_outputs.items(): - yield self._try_ansi2latex, inval, outval + yield self._try_ansi2latex(inval, outval) def _try_ansi2latex(self, inval, outval): diff --git a/IPython/nbconvert/filters/tests/test_datatypefilter.py b/IPython/nbconvert/filters/tests/test_datatypefilter.py index d40904b..0187c1f 100644 --- a/IPython/nbconvert/filters/tests/test_datatypefilter.py +++ b/IPython/nbconvert/filters/tests/test_datatypefilter.py @@ -37,10 +37,10 @@ class TestDataTypeFilter(TestsBase): filter = DataTypeFilter() assert "png" in filter(["hair", "water", "png", "rock"]) assert "pdf" in filter(["pdf", "hair", "water", "png", "rock"]) - self.assert_equals(filter(["hair", "water", "rock"]), []) + self.assertEqual(filter(["hair", "water", "rock"]), []) def test_null(self): """Will the DataTypeFilter fail if no types are passed in?""" filter = DataTypeFilter() - self.assert_equals(filter([]), []) + self.assertEqual(filter([]), []) diff --git a/IPython/nbconvert/filters/tests/test_highlight.py b/IPython/nbconvert/filters/tests/test_highlight.py index 6f9b601..04f9107 100644 --- a/IPython/nbconvert/filters/tests/test_highlight.py +++ b/IPython/nbconvert/filters/tests/test_highlight.py @@ -14,8 +14,6 @@ Module with tests for Highlight # Imports #----------------------------------------------------------------------------- -from IPython.testing import decorators as dec - from ...tests.base import TestsBase from ..highlight import highlight2html, highlight2latex @@ -48,18 +46,16 @@ class TestHighlight(TestsBase): ['pylab', 'plot']] - @dec.parametric def test_highlight2html(self): """highlight2html test""" for index, test in enumerate(self.tests): - yield self._try_highlight, highlight2html, test, self.tokens[index] + yield self._try_highlight(highlight2html, test, self.tokens[index]) - @dec.parametric def test_highlight2latex(self): """highlight2latex test""" for index, test in enumerate(self.tests): - yield self._try_highlight, highlight2latex, test, self.tokens[index] + yield self._try_highlight(highlight2latex, test, self.tokens[index]) def _try_highlight(self, method, test, tokens): diff --git a/IPython/nbconvert/filters/tests/test_latex.py b/IPython/nbconvert/filters/tests/test_latex.py index 4cc5921..14909c6 100644 --- a/IPython/nbconvert/filters/tests/test_latex.py +++ b/IPython/nbconvert/filters/tests/test_latex.py @@ -14,8 +14,6 @@ Module with tests for Latex # Imports #----------------------------------------------------------------------------- -from IPython.testing import decorators as dec - from ...tests.base import TestsBase from ..latex import escape_latex, strip_math_space @@ -27,7 +25,6 @@ from ..latex import escape_latex, strip_math_space class TestLatex(TestsBase): - @dec.parametric def test_escape_latex(self): """escape_latex test""" tests = [ @@ -37,15 +34,14 @@ class TestLatex(TestsBase): ('','')] for test in tests: - yield self._try_escape_latex, test[0], test[1] + yield self._try_escape_latex(test[0], test[1]) def _try_escape_latex(self, test, result): """Try to remove latex from string""" - self.assert_equal(escape_latex(test), result) + self.assertEqual(escape_latex(test), result) - @dec.parametric def test_strip_math_space(self): """strip_math_space test""" tests = [ @@ -59,11 +55,11 @@ class TestLatex(TestsBase): ('','')] for test in tests: - yield self._try_strip_math_space, test[0], test[1] + yield self._try_strip_math_space(test[0], test[1]) def _try_strip_math_space(self, test, result): """ Try to remove spaces between dollar symbols and contents correctly """ - self.assert_equal(strip_math_space(test), result) + self.assertEqual(strip_math_space(test), result) diff --git a/IPython/nbconvert/filters/tests/test_markdown.py b/IPython/nbconvert/filters/tests/test_markdown.py index 235c2f0..d0b5b3c 100644 --- a/IPython/nbconvert/filters/tests/test_markdown.py +++ b/IPython/nbconvert/filters/tests/test_markdown.py @@ -58,23 +58,20 @@ class TestMarkdown(TestsBase): @dec.onlyif_cmds_exist('pandoc') - @dec.parametric def test_markdown2latex(self): """markdown2latex test""" for index, test in enumerate(self.tests): - yield self._try_markdown, markdown2latex, test, self.tokens[index] + yield self._try_markdown(markdown2latex, test, self.tokens[index]) @dec.onlyif_cmds_exist('pandoc') - @dec.parametric def test_markdown2html(self): """markdown2html test""" for index, test in enumerate(self.tests): - yield self._try_markdown, markdown2html, test, self.tokens[index] + yield self._try_markdown(markdown2html, test, self.tokens[index]) @dec.onlyif_cmds_exist('pandoc') - @dec.parametric def test_markdown2rst(self): """markdown2rst test""" @@ -84,7 +81,7 @@ class TestMarkdown(TestsBase): tokens[1] = r'\*\*test' for index, test in enumerate(self.tests): - yield self._try_markdown, markdown2rst, test, tokens[index] + yield self._try_markdown(markdown2rst, test, tokens[index]) def _try_markdown(self, method, test, tokens): diff --git a/IPython/nbconvert/filters/tests/test_strings.py b/IPython/nbconvert/filters/tests/test_strings.py index 1dda79e..c7bdd96 100644 --- a/IPython/nbconvert/filters/tests/test_strings.py +++ b/IPython/nbconvert/filters/tests/test_strings.py @@ -26,7 +26,6 @@ from ..strings import (wrap_text, html2text, add_anchor, strip_dollars, class TestStrings(TestsBase): - @dec.parametric def test_wrap_text(self): """wrap_text test""" test_text = """ @@ -35,7 +34,7 @@ class TestStrings(TestsBase): As if the strings were thine, shouldst know of this. """ for length in [30,5,1]: - yield self._confirm_wrap_text, test_text, length + yield self._confirm_wrap_text(test_text, length) def _confirm_wrap_text(self, text, length): @@ -46,7 +45,7 @@ class TestStrings(TestsBase): def test_html2text(self): """html2text test""" #TODO: More tests - self.assert_equal(html2text('joe'), 'joe') + self.assertEqual(html2text('joe'), 'joe') def test_add_anchor(self): @@ -60,7 +59,6 @@ class TestStrings(TestsBase): assert '' in results - @dec.parametric def test_strip_dollars(self): """strip_dollars test""" tests = [ @@ -73,14 +71,13 @@ class TestStrings(TestsBase): ('Hello', 'Hello'), ('W$o$rld', 'W$o$rld')] for test in tests: - yield self._try_strip_dollars, test[0], test[1] + yield self._try_strip_dollars(test[0], test[1]) def _try_strip_dollars(self, test, result): - self.assert_equal(strip_dollars(test), result) + self.assertEqual(strip_dollars(test), result) - @dec.parametric def test_strip_files_prefix(self): """strip_files_prefix test""" tests = [ @@ -90,11 +87,11 @@ class TestStrings(TestsBase): ('My files are in `files/`', 'My files are in `files/`'), ('files/test.html', 'files/test.html')] for test in tests: - yield self._try_files_prefix, test[0], test[1] + yield self._try_files_prefix(test[0], test[1]) def _try_files_prefix(self, test, result): - self.assert_equal(strip_files_prefix(test), result) + self.assertEqual(strip_files_prefix(test), result) def test_comment_lines(self): @@ -108,10 +105,10 @@ class TestStrings(TestsBase): def test_get_lines(self): """get_lines test""" text = "hello\nworld\n!" - self.assert_equal(get_lines(text, start=1), "world\n!") - self.assert_equal(get_lines(text, end=2), "hello\nworld") - self.assert_equal(get_lines(text, start=2, end=5), "!") - self.assert_equal(get_lines(text, start=-2), "world\n!") + self.assertEqual(get_lines(text, start=1), "world\n!") + self.assertEqual(get_lines(text, end=2), "hello\nworld") + self.assertEqual(get_lines(text, start=2, end=5), "!") + self.assertEqual(get_lines(text, start=-2), "world\n!") def test_ipython2python(self): diff --git a/IPython/nbconvert/tests/base.py b/IPython/nbconvert/tests/base.py index 68cc510..bd8b1e4 100644 --- a/IPython/nbconvert/tests/base.py +++ b/IPython/nbconvert/tests/base.py @@ -17,11 +17,11 @@ import os import glob import shutil -from nose.tools import assert_equal import IPython from IPython.utils.tempdir import TemporaryWorkingDirectory from IPython.utils.process import get_output_error_code from IPython.testing.tools import get_ipython_cmd +from IPython.testing.ipunittest import ParametricTestCase # a trailing space allows for simpler concatenation with the other arguments ipy_cmd = get_ipython_cmd(as_string=True) + " " @@ -31,19 +31,11 @@ ipy_cmd = get_ipython_cmd(as_string=True) + " " #----------------------------------------------------------------------------- -class TestsBase(object): +class TestsBase(ParametricTestCase): """Base tests class. Contains useful fuzzy comparison and nbconvert functions.""" - def __init__(self): - - # We need to manually add assert_equal to the class instead of inheriting - # from unittest.TestCase because if we inherit from unittest.TestCase - # support for test generators is lost (a known 'feature' of nose). - self.assert_equal = assert_equal - - def fuzzy_compare(self, a, b, newlines_are_spaces=True, tabs_are_spaces=True, fuzzy_spacing=True, ignore_spaces=False, ignore_newlines=False, case_sensitive=False, leave_padding=False): @@ -82,7 +74,7 @@ class TestsBase(object): a = a.lower() b = b.lower() - self.assert_equal(a, b) + self.assertEqual(a, b) def recursive_replace(self, text, search, replacement):