##// END OF EJS Templates
assert_equals -> assert_equal
Jonathan Frederic -
Show More
@@ -1,91 +1,91
1 """
1 """
2 Module with tests for ansi filters
2 Module with tests for ansi filters
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 from IPython.utils.coloransi import TermColors
17 from IPython.utils.coloransi import TermColors
18
18
19 from ...tests.base import TestsBase
19 from ...tests.base import TestsBase
20 from ..ansi import strip_ansi, ansi2html, ansi2latex
20 from ..ansi import strip_ansi, ansi2html, ansi2latex
21
21
22
22
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 # Class
24 # Class
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26
26
27 class TestAnsi(TestsBase):
27 class TestAnsi(TestsBase):
28 """Contains test functions for ansi.py"""
28 """Contains test functions for ansi.py"""
29
29
30
30
31 def test_strip_ansi(self):
31 def test_strip_ansi(self):
32 """
32 """
33 strip_ansi test
33 strip_ansi test
34 """
34 """
35 correct_outputs = {
35 correct_outputs = {
36 '%s%s%s' % (TermColors.Green, TermColors.White, TermColors.Red) : '',
36 '%s%s%s' % (TermColors.Green, TermColors.White, TermColors.Red) : '',
37 'hello%s' % TermColors.Blue: 'hello',
37 'hello%s' % TermColors.Blue: 'hello',
38 'he%s%sllo' % (TermColors.Yellow, TermColors.Cyan) : 'hello',
38 'he%s%sllo' % (TermColors.Yellow, TermColors.Cyan) : 'hello',
39 '%shello' % TermColors.Blue : 'hello',
39 '%shello' % TermColors.Blue : 'hello',
40 '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.Red) : 'hello',
40 '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.Red) : 'hello',
41 'hel%slo' % TermColors.Green : 'hello',
41 'hel%slo' % TermColors.Green : 'hello',
42 'hello' : 'hello'}
42 'hello' : 'hello'}
43
43
44 for inval, outval in correct_outputs.items():
44 for inval, outval in correct_outputs.items():
45 yield self._try_strip_ansi, inval, outval
45 yield self._try_strip_ansi, inval, outval
46
46
47
47
48 def _try_strip_ansi(self, inval, outval):
48 def _try_strip_ansi(self, inval, outval):
49 self.assert_equals(outval, strip_ansi(inval))
49 self.assert_equal(outval, strip_ansi(inval))
50
50
51
51
52 def test_ansi2html(self):
52 def test_ansi2html(self):
53 """
53 """
54 ansi2html test
54 ansi2html test
55 """
55 """
56 correct_outputs = {
56 correct_outputs = {
57 '%s' % (TermColors.Red) : '<span class="ansired"></span>',
57 '%s' % (TermColors.Red) : '<span class="ansired"></span>',
58 'hello%s' % TermColors.Blue: 'hello<span class="ansiblue"></span>',
58 'hello%s' % TermColors.Blue: 'hello<span class="ansiblue"></span>',
59 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : 'he<span class="ansigreen"></span><span class="ansicyan">llo</span>',
59 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : 'he<span class="ansigreen"></span><span class="ansicyan">llo</span>',
60 '%shello' % TermColors.Yellow : '<span class="ansiyellow">hello</span>',
60 '%shello' % TermColors.Yellow : '<span class="ansiyellow">hello</span>',
61 '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : '<span class="ansigrey">h</span><span class="ansigrey">e</span><span class="ansigrey">l</span><span class="ansigrey">l</span><span class="ansigrey">o</span><span class="ansigrey"></span>',
61 '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : '<span class="ansigrey">h</span><span class="ansigrey">e</span><span class="ansigrey">l</span><span class="ansigrey">l</span><span class="ansigrey">o</span><span class="ansigrey"></span>',
62 'hel%slo' % TermColors.Green : 'hel<span class="ansigreen">lo</span>',
62 'hel%slo' % TermColors.Green : 'hel<span class="ansigreen">lo</span>',
63 'hello' : 'hello'}
63 'hello' : 'hello'}
64
64
65 for inval, outval in correct_outputs.items():
65 for inval, outval in correct_outputs.items():
66 yield self._try_ansi2html, inval, outval
66 yield self._try_ansi2html, inval, outval
67
67
68
68
69 def _try_ansi2html(self, inval, outval):
69 def _try_ansi2html(self, inval, outval):
70 self.fuzzy_compare(outval, ansi2html(inval))
70 self.fuzzy_compare(outval, ansi2html(inval))
71
71
72
72
73 def test_ansi2latex(self):
73 def test_ansi2latex(self):
74 """
74 """
75 ansi2latex test
75 ansi2latex test
76 """
76 """
77 correct_outputs = {
77 correct_outputs = {
78 '%s' % (TermColors.Red) : r'\red{}',
78 '%s' % (TermColors.Red) : r'\red{}',
79 'hello%s' % TermColors.Blue: r'hello\blue{}',
79 'hello%s' % TermColors.Blue: r'hello\blue{}',
80 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : r'he\green{}\cyan{llo}',
80 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : r'he\green{}\cyan{llo}',
81 '%shello' % TermColors.Yellow : r'\yellow{hello}',
81 '%shello' % TermColors.Yellow : r'\yellow{hello}',
82 '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : r'\white{h}\white{e}\white{l}\white{l}\white{o}\white{}',
82 '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : r'\white{h}\white{e}\white{l}\white{l}\white{o}\white{}',
83 'hel%slo' % TermColors.Green : r'hel\green{lo}',
83 'hel%slo' % TermColors.Green : r'hel\green{lo}',
84 'hello' : 'hello'}
84 'hello' : 'hello'}
85
85
86 for inval, outval in correct_outputs.items():
86 for inval, outval in correct_outputs.items():
87 yield self._try_ansi2latex, inval, outval
87 yield self._try_ansi2latex, inval, outval
88
88
89
89
90 def _try_ansi2latex(self, inval, outval):
90 def _try_ansi2latex(self, inval, outval):
91 self.fuzzy_compare(outval, ansi2latex(inval), case_sensitive=True)
91 self.fuzzy_compare(outval, ansi2latex(inval), case_sensitive=True)
@@ -1,72 +1,72
1 """
1 """
2 Module with tests for Latex
2 Module with tests for Latex
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17
17
18 from ...tests.base import TestsBase
18 from ...tests.base import TestsBase
19 from ..latex import escape_latex, strip_math_space
19 from ..latex import escape_latex, strip_math_space
20
20
21
21
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Class
23 # Class
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25
25
26 class TestLatex(TestsBase):
26 class TestLatex(TestsBase):
27
27
28
28
29 def test_escape_latex(self):
29 def test_escape_latex(self):
30 """
30 """
31 escape_latex test
31 escape_latex test
32 """
32 """
33 tests = [
33 tests = [
34 (r'How are \you doing today?', r'How are \textbackslashyou doing today?'),
34 (r'How are \you doing today?', r'How are \textbackslashyou doing today?'),
35 (r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\textbackslashescapechar=`\textbackslashA\textbackslashcatcode`\textbackslash|=0 |string|foo'),
35 (r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\textbackslashescapechar=`\textbackslashA\textbackslashcatcode`\textbackslash|=0 |string|foo'),
36 (r'# $ % & ~ _ ^ \ { }',r'\# \$ \% \& \~{} \_ \^{} \textbackslash \{ \}'),
36 (r'# $ % & ~ _ ^ \ { }',r'\# \$ \% \& \~{} \_ \^{} \textbackslash \{ \}'),
37 ('','')]
37 ('','')]
38
38
39 for test in tests:
39 for test in tests:
40 yield self._try_escape_latex, test[0], test[1]
40 yield self._try_escape_latex, test[0], test[1]
41
41
42
42
43 def _try_escape_latex(self, test, result):
43 def _try_escape_latex(self, test, result):
44 """
44 """
45 Try to remove latex from string
45 Try to remove latex from string
46 """
46 """
47 self.assert_equals(escape_latex(test), result)
47 self.assert_equal(escape_latex(test), result)
48
48
49
49
50 def test_strip_math_space(self):
50 def test_strip_math_space(self):
51 """
51 """
52 strip_math_space test
52 strip_math_space test
53 """
53 """
54 tests = [
54 tests = [
55 ('$e$','$e$'),
55 ('$e$','$e$'),
56 ('$ e $','$e$'),
56 ('$ e $','$e$'),
57 ('xxx$e^i$yyy','xxx$e^i$yyy'),
57 ('xxx$e^i$yyy','xxx$e^i$yyy'),
58 ('xxx$ e^i $yyy','xxx$e^i$yyy'),
58 ('xxx$ e^i $yyy','xxx$e^i$yyy'),
59 ('xxx$e^i $yyy','xxx$e^i$yyy'),
59 ('xxx$e^i $yyy','xxx$e^i$yyy'),
60 ('xxx$ e^i$yyy','xxx$e^i$yyy'),
60 ('xxx$ e^i$yyy','xxx$e^i$yyy'),
61 ('\$ e $ e $','\$ e $e$'),
61 ('\$ e $ e $','\$ e $e$'),
62 ('','')]
62 ('','')]
63
63
64 for test in tests:
64 for test in tests:
65 yield self._try_strip_math_space, test[0], test[1]
65 yield self._try_strip_math_space, test[0], test[1]
66
66
67
67
68 def _try_strip_math_space(self, test, result):
68 def _try_strip_math_space(self, test, result):
69 """
69 """
70 Try to remove spaces between dollar symbols and contents correctly
70 Try to remove spaces between dollar symbols and contents correctly
71 """
71 """
72 self.assert_equals(strip_math_space(test), result)
72 self.assert_equal(strip_math_space(test), result)
@@ -1,132 +1,132
1 """
1 """
2 Module with tests for Strings
2 Module with tests for Strings
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 from ...tests.base import TestsBase
17 from ...tests.base import TestsBase
18 from ..strings import (wrap_text, html2text, add_anchor, strip_dollars,
18 from ..strings import (wrap_text, html2text, add_anchor, strip_dollars,
19 strip_files_prefix, get_lines, comment_lines, ipython2python)
19 strip_files_prefix, get_lines, comment_lines, ipython2python)
20
20
21
21
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Class
23 # Class
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25
25
26 class TestStrings(TestsBase):
26 class TestStrings(TestsBase):
27
27
28 def test_wrap_text(self):
28 def test_wrap_text(self):
29 """
29 """
30 wrap_text test
30 wrap_text test
31 """
31 """
32 test_text = """
32 test_text = """
33 Tush! never tell me; I take it much unkindly
33 Tush! never tell me; I take it much unkindly
34 That thou, Iago, who hast had my purse
34 That thou, Iago, who hast had my purse
35 As if the strings were thine, shouldst know of this.
35 As if the strings were thine, shouldst know of this.
36 """
36 """
37 for length in [30,5,1]:
37 for length in [30,5,1]:
38 yield self._confirm_wrap_text, test_text, length
38 yield self._confirm_wrap_text, test_text, length
39
39
40 def _confirm_wrap_text(self, text, length):
40 def _confirm_wrap_text(self, text, length):
41 for line in wrap_text(text, length).split('\n'):
41 for line in wrap_text(text, length).split('\n'):
42 assert len(line) <= length
42 assert len(line) <= length
43
43
44 def test_html2text(self):
44 def test_html2text(self):
45 """
45 """
46 html2text test
46 html2text test
47 """
47 """
48 #TODO: More tests
48 #TODO: More tests
49 self.assert_equals(html2text('<name>joe</name>'), 'joe')
49 self.assert_equal(html2text('<name>joe</name>'), 'joe')
50
50
51
51
52 def test_add_anchor(self):
52 def test_add_anchor(self):
53 """
53 """
54 add_anchor test
54 add_anchor test
55 """
55 """
56 #TODO: More tests
56 #TODO: More tests
57 results = add_anchor('<b>Hello World!</b>')
57 results = add_anchor('<b>Hello World!</b>')
58 assert 'Hello World!' in results
58 assert 'Hello World!' in results
59 assert 'id="' in results
59 assert 'id="' in results
60 assert 'class="anchor-link"' in results
60 assert 'class="anchor-link"' in results
61 assert '<b' in results
61 assert '<b' in results
62 assert '</b>' in results
62 assert '</b>' in results
63
63
64
64
65 def test_strip_dollars(self):
65 def test_strip_dollars(self):
66 """
66 """
67 strip_dollars test
67 strip_dollars test
68 """
68 """
69 tests = [
69 tests = [
70 ('', ''),
70 ('', ''),
71 ('$$', ''),
71 ('$$', ''),
72 ('$H$', 'H'),
72 ('$H$', 'H'),
73 ('$He', 'He'),
73 ('$He', 'He'),
74 ('H$el', 'H$el'),
74 ('H$el', 'H$el'),
75 ('Hell$', 'Hell'),
75 ('Hell$', 'Hell'),
76 ('Hello', 'Hello'),
76 ('Hello', 'Hello'),
77 ('W$o$rld', 'W$o$rld')]
77 ('W$o$rld', 'W$o$rld')]
78 for test in tests:
78 for test in tests:
79 yield self._try_strip_dollars, test[0], test[1]
79 yield self._try_strip_dollars, test[0], test[1]
80
80
81
81
82 def _try_strip_dollars(self, test, result):
82 def _try_strip_dollars(self, test, result):
83 self.assert_equals(strip_dollars(test), result)
83 self.assert_equal(strip_dollars(test), result)
84
84
85
85
86 def test_strip_files_prefix(self):
86 def test_strip_files_prefix(self):
87 """
87 """
88 strip_files_prefix test
88 strip_files_prefix test
89 """
89 """
90 tests = [
90 tests = [
91 ('', ''),
91 ('', ''),
92 ('/files', '/files'),
92 ('/files', '/files'),
93 ('test="/files"', 'test="/files"'),
93 ('test="/files"', 'test="/files"'),
94 ('My files are in `files/`', 'My files are in `files/`'),
94 ('My files are in `files/`', 'My files are in `files/`'),
95 ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')]
95 ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')]
96 for test in tests:
96 for test in tests:
97 yield self._try_files_prefix, test[0], test[1]
97 yield self._try_files_prefix, test[0], test[1]
98
98
99
99
100 def _try_files_prefix(self, test, result):
100 def _try_files_prefix(self, test, result):
101 self.assert_equals(strip_files_prefix(test), result)
101 self.assert_equal(strip_files_prefix(test), result)
102
102
103
103
104 def test_comment_lines(self):
104 def test_comment_lines(self):
105 """
105 """
106 comment_lines test
106 comment_lines test
107 """
107 """
108 for line in comment_lines('hello\nworld\n!').split('\n'):
108 for line in comment_lines('hello\nworld\n!').split('\n'):
109 assert line.startswith('# ')
109 assert line.startswith('# ')
110 for line in comment_lines('hello\nworld\n!', 'beep').split('\n'):
110 for line in comment_lines('hello\nworld\n!', 'beep').split('\n'):
111 assert line.startswith('beep')
111 assert line.startswith('beep')
112
112
113
113
114 def test_get_lines(self):
114 def test_get_lines(self):
115 """
115 """
116 get_lines test
116 get_lines test
117 """
117 """
118 text = "hello\nworld\n!"
118 text = "hello\nworld\n!"
119 self.assert_equals(get_lines(text, start=1), "world\n!")
119 self.assert_equal(get_lines(text, start=1), "world\n!")
120 self.assert_equals(get_lines(text, end=2), "hello\nworld")
120 self.assert_equal(get_lines(text, end=2), "hello\nworld")
121 self.assert_equals(get_lines(text, start=2, end=5), "!")
121 self.assert_equal(get_lines(text, start=2, end=5), "!")
122 self.assert_equals(get_lines(text, start=-2), "world\n!")
122 self.assert_equal(get_lines(text, start=-2), "world\n!")
123
123
124
124
125 def test_ipython2python(self):
125 def test_ipython2python(self):
126 """
126 """
127 ipython2python test
127 ipython2python test
128 """
128 """
129 #TODO: More tests
129 #TODO: More tests
130 results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'")
130 results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'")
131 self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')",
131 self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')",
132 ignore_spaces=True, ignore_newlines=True)
132 ignore_spaces=True, ignore_newlines=True)
General Comments 0
You need to be logged in to leave comments. Login now