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