Show More
@@ -14,7 +14,6 b' Module with tests for ansi filters' | |||
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | from IPython.testing import decorators as dec | |
|
18 | 17 | from IPython.utils.coloransi import TermColors |
|
19 | 18 | |
|
20 | 19 | from ...tests.base import TestsBase |
@@ -28,7 +27,6 b' from ..ansi import strip_ansi, ansi2html, ansi2latex' | |||
|
28 | 27 | class TestAnsi(TestsBase): |
|
29 | 28 | """Contains test functions for ansi.py""" |
|
30 | 29 | |
|
31 | @dec.parametric | |
|
32 | 30 | def test_strip_ansi(self): |
|
33 | 31 | """strip_ansi test""" |
|
34 | 32 | correct_outputs = { |
@@ -41,14 +39,13 b' class TestAnsi(TestsBase):' | |||
|
41 | 39 | 'hello' : 'hello'} |
|
42 | 40 | |
|
43 | 41 | for inval, outval in correct_outputs.items(): |
|
44 |
yield self._try_strip_ansi |
|
|
42 | yield self._try_strip_ansi(inval, outval) | |
|
45 | 43 | |
|
46 | 44 | |
|
47 | 45 | def _try_strip_ansi(self, inval, outval): |
|
48 |
self.assert |
|
|
46 | self.assertEqual(outval, strip_ansi(inval)) | |
|
49 | 47 | |
|
50 | 48 | |
|
51 | @dec.parametric | |
|
52 | 49 | def test_ansi2html(self): |
|
53 | 50 | """ansi2html test""" |
|
54 | 51 | correct_outputs = { |
@@ -61,14 +58,13 b' class TestAnsi(TestsBase):' | |||
|
61 | 58 | 'hello' : 'hello'} |
|
62 | 59 | |
|
63 | 60 | for inval, outval in correct_outputs.items(): |
|
64 |
yield self._try_ansi2html |
|
|
61 | yield self._try_ansi2html(inval, outval) | |
|
65 | 62 | |
|
66 | 63 | |
|
67 | 64 | def _try_ansi2html(self, inval, outval): |
|
68 | 65 | self.fuzzy_compare(outval, ansi2html(inval)) |
|
69 | 66 | |
|
70 | 67 | |
|
71 | @dec.parametric | |
|
72 | 68 | def test_ansi2latex(self): |
|
73 | 69 | """ansi2latex test""" |
|
74 | 70 | correct_outputs = { |
@@ -81,7 +77,7 b' class TestAnsi(TestsBase):' | |||
|
81 | 77 | 'hello' : 'hello'} |
|
82 | 78 | |
|
83 | 79 | for inval, outval in correct_outputs.items(): |
|
84 |
yield self._try_ansi2latex |
|
|
80 | yield self._try_ansi2latex(inval, outval) | |
|
85 | 81 | |
|
86 | 82 | |
|
87 | 83 | def _try_ansi2latex(self, inval, outval): |
@@ -37,10 +37,10 b' class TestDataTypeFilter(TestsBase):' | |||
|
37 | 37 | filter = DataTypeFilter() |
|
38 | 38 | assert "png" in filter(["hair", "water", "png", "rock"]) |
|
39 | 39 | assert "pdf" in filter(["pdf", "hair", "water", "png", "rock"]) |
|
40 |
self.assert |
|
|
40 | self.assertEqual(filter(["hair", "water", "rock"]), []) | |
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | def test_null(self): |
|
44 | 44 | """Will the DataTypeFilter fail if no types are passed in?""" |
|
45 | 45 | filter = DataTypeFilter() |
|
46 |
self.assert |
|
|
46 | self.assertEqual(filter([]), []) |
@@ -14,8 +14,6 b' Module with tests for Highlight' | |||
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | from IPython.testing import decorators as dec | |
|
18 | ||
|
19 | 17 | from ...tests.base import TestsBase |
|
20 | 18 | from ..highlight import highlight2html, highlight2latex |
|
21 | 19 | |
@@ -48,18 +46,16 b' class TestHighlight(TestsBase):' | |||
|
48 | 46 | ['pylab', 'plot']] |
|
49 | 47 | |
|
50 | 48 | |
|
51 | @dec.parametric | |
|
52 | 49 | def test_highlight2html(self): |
|
53 | 50 | """highlight2html test""" |
|
54 | 51 | for index, test in enumerate(self.tests): |
|
55 |
yield self._try_highlight |
|
|
52 | yield self._try_highlight(highlight2html, test, self.tokens[index]) | |
|
56 | 53 | |
|
57 | 54 | |
|
58 | @dec.parametric | |
|
59 | 55 | def test_highlight2latex(self): |
|
60 | 56 | """highlight2latex test""" |
|
61 | 57 | for index, test in enumerate(self.tests): |
|
62 |
yield self._try_highlight |
|
|
58 | yield self._try_highlight(highlight2latex, test, self.tokens[index]) | |
|
63 | 59 | |
|
64 | 60 | |
|
65 | 61 | def _try_highlight(self, method, test, tokens): |
@@ -14,8 +14,6 b' Module with tests for Latex' | |||
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | from IPython.testing import decorators as dec | |
|
18 | ||
|
19 | 17 | from ...tests.base import TestsBase |
|
20 | 18 | from ..latex import escape_latex, strip_math_space |
|
21 | 19 | |
@@ -27,7 +25,6 b' from ..latex import escape_latex, strip_math_space' | |||
|
27 | 25 | class TestLatex(TestsBase): |
|
28 | 26 | |
|
29 | 27 | |
|
30 | @dec.parametric | |
|
31 | 28 | def test_escape_latex(self): |
|
32 | 29 | """escape_latex test""" |
|
33 | 30 | tests = [ |
@@ -37,15 +34,14 b' class TestLatex(TestsBase):' | |||
|
37 | 34 | ('','')] |
|
38 | 35 | |
|
39 | 36 | for test in tests: |
|
40 |
yield self._try_escape_latex |
|
|
37 | yield self._try_escape_latex(test[0], test[1]) | |
|
41 | 38 | |
|
42 | 39 | |
|
43 | 40 | def _try_escape_latex(self, test, result): |
|
44 | 41 | """Try to remove latex from string""" |
|
45 |
self.assert |
|
|
42 | self.assertEqual(escape_latex(test), result) | |
|
46 | 43 | |
|
47 | 44 | |
|
48 | @dec.parametric | |
|
49 | 45 | def test_strip_math_space(self): |
|
50 | 46 | """strip_math_space test""" |
|
51 | 47 | tests = [ |
@@ -59,11 +55,11 b' class TestLatex(TestsBase):' | |||
|
59 | 55 | ('','')] |
|
60 | 56 | |
|
61 | 57 | for test in tests: |
|
62 |
yield self._try_strip_math_space |
|
|
58 | yield self._try_strip_math_space(test[0], test[1]) | |
|
63 | 59 | |
|
64 | 60 | |
|
65 | 61 | def _try_strip_math_space(self, test, result): |
|
66 | 62 | """ |
|
67 | 63 | Try to remove spaces between dollar symbols and contents correctly |
|
68 | 64 | """ |
|
69 |
self.assert |
|
|
65 | self.assertEqual(strip_math_space(test), result) |
@@ -58,23 +58,20 b' class TestMarkdown(TestsBase):' | |||
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | @dec.onlyif_cmds_exist('pandoc') |
|
61 | @dec.parametric | |
|
62 | 61 | def test_markdown2latex(self): |
|
63 | 62 | """markdown2latex test""" |
|
64 | 63 | for index, test in enumerate(self.tests): |
|
65 |
yield self._try_markdown |
|
|
64 | yield self._try_markdown(markdown2latex, test, self.tokens[index]) | |
|
66 | 65 | |
|
67 | 66 | |
|
68 | 67 | @dec.onlyif_cmds_exist('pandoc') |
|
69 | @dec.parametric | |
|
70 | 68 | def test_markdown2html(self): |
|
71 | 69 | """markdown2html test""" |
|
72 | 70 | for index, test in enumerate(self.tests): |
|
73 |
yield self._try_markdown |
|
|
71 | yield self._try_markdown(markdown2html, test, self.tokens[index]) | |
|
74 | 72 | |
|
75 | 73 | |
|
76 | 74 | @dec.onlyif_cmds_exist('pandoc') |
|
77 | @dec.parametric | |
|
78 | 75 | def test_markdown2rst(self): |
|
79 | 76 | """markdown2rst test""" |
|
80 | 77 | |
@@ -84,7 +81,7 b' class TestMarkdown(TestsBase):' | |||
|
84 | 81 | tokens[1] = r'\*\*test' |
|
85 | 82 | |
|
86 | 83 | for index, test in enumerate(self.tests): |
|
87 |
yield self._try_markdown |
|
|
84 | yield self._try_markdown(markdown2rst, test, tokens[index]) | |
|
88 | 85 | |
|
89 | 86 | |
|
90 | 87 | def _try_markdown(self, method, test, tokens): |
@@ -26,7 +26,6 b' from ..strings import (wrap_text, html2text, add_anchor, strip_dollars,' | |||
|
26 | 26 | |
|
27 | 27 | class TestStrings(TestsBase): |
|
28 | 28 | |
|
29 | @dec.parametric | |
|
30 | 29 | def test_wrap_text(self): |
|
31 | 30 | """wrap_text test""" |
|
32 | 31 | test_text = """ |
@@ -35,7 +34,7 b' class TestStrings(TestsBase):' | |||
|
35 | 34 | As if the strings were thine, shouldst know of this. |
|
36 | 35 | """ |
|
37 | 36 | for length in [30,5,1]: |
|
38 |
yield self._confirm_wrap_text |
|
|
37 | yield self._confirm_wrap_text(test_text, length) | |
|
39 | 38 | |
|
40 | 39 | |
|
41 | 40 | def _confirm_wrap_text(self, text, length): |
@@ -46,7 +45,7 b' class TestStrings(TestsBase):' | |||
|
46 | 45 | def test_html2text(self): |
|
47 | 46 | """html2text test""" |
|
48 | 47 | #TODO: More tests |
|
49 |
self.assert |
|
|
48 | self.assertEqual(html2text('<name>joe</name>'), 'joe') | |
|
50 | 49 | |
|
51 | 50 | |
|
52 | 51 | def test_add_anchor(self): |
@@ -60,7 +59,6 b' class TestStrings(TestsBase):' | |||
|
60 | 59 | assert '</b>' in results |
|
61 | 60 | |
|
62 | 61 | |
|
63 | @dec.parametric | |
|
64 | 62 | def test_strip_dollars(self): |
|
65 | 63 | """strip_dollars test""" |
|
66 | 64 | tests = [ |
@@ -73,14 +71,13 b' class TestStrings(TestsBase):' | |||
|
73 | 71 | ('Hello', 'Hello'), |
|
74 | 72 | ('W$o$rld', 'W$o$rld')] |
|
75 | 73 | for test in tests: |
|
76 |
yield self._try_strip_dollars |
|
|
74 | yield self._try_strip_dollars(test[0], test[1]) | |
|
77 | 75 | |
|
78 | 76 | |
|
79 | 77 | def _try_strip_dollars(self, test, result): |
|
80 |
self.assert |
|
|
78 | self.assertEqual(strip_dollars(test), result) | |
|
81 | 79 | |
|
82 | 80 | |
|
83 | @dec.parametric | |
|
84 | 81 | def test_strip_files_prefix(self): |
|
85 | 82 | """strip_files_prefix test""" |
|
86 | 83 | tests = [ |
@@ -90,11 +87,11 b' class TestStrings(TestsBase):' | |||
|
90 | 87 | ('My files are in `files/`', 'My files are in `files/`'), |
|
91 | 88 | ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')] |
|
92 | 89 | for test in tests: |
|
93 |
yield self._try_files_prefix |
|
|
90 | yield self._try_files_prefix(test[0], test[1]) | |
|
94 | 91 | |
|
95 | 92 | |
|
96 | 93 | def _try_files_prefix(self, test, result): |
|
97 |
self.assert |
|
|
94 | self.assertEqual(strip_files_prefix(test), result) | |
|
98 | 95 | |
|
99 | 96 | |
|
100 | 97 | def test_comment_lines(self): |
@@ -108,10 +105,10 b' class TestStrings(TestsBase):' | |||
|
108 | 105 | def test_get_lines(self): |
|
109 | 106 | """get_lines test""" |
|
110 | 107 | text = "hello\nworld\n!" |
|
111 |
self.assert |
|
|
112 |
self.assert |
|
|
113 |
self.assert |
|
|
114 |
self.assert |
|
|
108 | self.assertEqual(get_lines(text, start=1), "world\n!") | |
|
109 | self.assertEqual(get_lines(text, end=2), "hello\nworld") | |
|
110 | self.assertEqual(get_lines(text, start=2, end=5), "!") | |
|
111 | self.assertEqual(get_lines(text, start=-2), "world\n!") | |
|
115 | 112 | |
|
116 | 113 | |
|
117 | 114 | def test_ipython2python(self): |
@@ -17,11 +17,11 b' import os' | |||
|
17 | 17 | import glob |
|
18 | 18 | import shutil |
|
19 | 19 | |
|
20 | from nose.tools import assert_equal | |
|
21 | 20 | import IPython |
|
22 | 21 | from IPython.utils.tempdir import TemporaryWorkingDirectory |
|
23 | 22 | from IPython.utils.process import get_output_error_code |
|
24 | 23 | from IPython.testing.tools import get_ipython_cmd |
|
24 | from IPython.testing.ipunittest import ParametricTestCase | |
|
25 | 25 | |
|
26 | 26 | # a trailing space allows for simpler concatenation with the other arguments |
|
27 | 27 | ipy_cmd = get_ipython_cmd(as_string=True) + " " |
@@ -31,19 +31,11 b' ipy_cmd = get_ipython_cmd(as_string=True) + " "' | |||
|
31 | 31 | #----------------------------------------------------------------------------- |
|
32 | 32 | |
|
33 | 33 | |
|
34 |
class TestsBase( |
|
|
34 | class TestsBase(ParametricTestCase): | |
|
35 | 35 | """Base tests class. Contains useful fuzzy comparison and nbconvert |
|
36 | 36 | functions.""" |
|
37 | 37 | |
|
38 | 38 | |
|
39 | def __init__(self): | |
|
40 | ||
|
41 | # We need to manually add assert_equal to the class instead of inheriting | |
|
42 | # from unittest.TestCase because if we inherit from unittest.TestCase | |
|
43 | # support for test generators is lost (a known 'feature' of nose). | |
|
44 | self.assert_equal = assert_equal | |
|
45 | ||
|
46 | ||
|
47 | 39 | def fuzzy_compare(self, a, b, newlines_are_spaces=True, tabs_are_spaces=True, |
|
48 | 40 | fuzzy_spacing=True, ignore_spaces=False, |
|
49 | 41 | ignore_newlines=False, case_sensitive=False, leave_padding=False): |
@@ -82,7 +74,7 b' class TestsBase(object):' | |||
|
82 | 74 | a = a.lower() |
|
83 | 75 | b = b.lower() |
|
84 | 76 | |
|
85 |
self.assert |
|
|
77 | self.assertEqual(a, b) | |
|
86 | 78 | |
|
87 | 79 | |
|
88 | 80 | def recursive_replace(self, text, search, replacement): |
General Comments 0
You need to be logged in to leave comments.
Login now