##// END OF EJS Templates
Fuzzy compare add_anchor
Jonathan Frederic -
Show More
@@ -1,127 +1,127 b''
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
17
18 from ...tests.base import TestsBase
18 from ...tests.base import TestsBase
19 from ..strings import *
19 from ..strings import *
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 assert html2text('<name>joe</name>') == 'joe'
49 assert 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 assert add_anchor('<b>Hello World!</b>') == '<b id="Hello-World!">Hello World!<a class="anchor-link" href="#Hello-World!">&#182;</a></b>'
57 self.fuzzy_compare(add_anchor('<b>Hello World!</b>'), '<b id="Hello-World!">Hello World!<a class="anchor-link" href="#Hello-World!">&#182;</a></b>')
58
58
59
59
60 def test_strip_dollars(self):
60 def test_strip_dollars(self):
61 """
61 """
62 strip_dollars test
62 strip_dollars test
63 """
63 """
64 tests = [
64 tests = [
65 ('', ''),
65 ('', ''),
66 ('$$', ''),
66 ('$$', ''),
67 ('$H$', 'H'),
67 ('$H$', 'H'),
68 ('$He', 'He'),
68 ('$He', 'He'),
69 ('H$el', 'H$el'),
69 ('H$el', 'H$el'),
70 ('Hell$', 'Hell'),
70 ('Hell$', 'Hell'),
71 ('Hello', 'Hello'),
71 ('Hello', 'Hello'),
72 ('W$o$rld', 'W$o$rld')]
72 ('W$o$rld', 'W$o$rld')]
73 for test in tests:
73 for test in tests:
74 yield self._try_strip_dollars, test[0], test[1]
74 yield self._try_strip_dollars, test[0], test[1]
75
75
76
76
77 def _try_strip_dollars(self, test, result):
77 def _try_strip_dollars(self, test, result):
78 assert strip_dollars(test) == result
78 assert strip_dollars(test) == result
79
79
80
80
81 def test_strip_files_prefix(self):
81 def test_strip_files_prefix(self):
82 """
82 """
83 strip_files_prefix test
83 strip_files_prefix test
84 """
84 """
85 tests = [
85 tests = [
86 ('', ''),
86 ('', ''),
87 ('/files', '/files'),
87 ('/files', '/files'),
88 ('test="/files"', 'test="/files"'),
88 ('test="/files"', 'test="/files"'),
89 ('My files are in `files/`', 'My files are in `files/`'),
89 ('My files are in `files/`', 'My files are in `files/`'),
90 ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')]
90 ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')]
91 for test in tests:
91 for test in tests:
92 yield self._try_files_prefix, test[0], test[1]
92 yield self._try_files_prefix, test[0], test[1]
93
93
94
94
95 def _try_files_prefix(self, test, result):
95 def _try_files_prefix(self, test, result):
96 assert strip_files_prefix(test) == result
96 assert strip_files_prefix(test) == result
97
97
98
98
99 def test_comment_lines(self):
99 def test_comment_lines(self):
100 """
100 """
101 comment_lines test
101 comment_lines test
102 """
102 """
103 for line in comment_lines('hello\nworld\n!').split('\n'):
103 for line in comment_lines('hello\nworld\n!').split('\n'):
104 assert line.startswith('# ')
104 assert line.startswith('# ')
105 for line in comment_lines('hello\nworld\n!', 'beep').split('\n'):
105 for line in comment_lines('hello\nworld\n!', 'beep').split('\n'):
106 assert line.startswith('beep')
106 assert line.startswith('beep')
107
107
108
108
109 def test_get_lines(self):
109 def test_get_lines(self):
110 """
110 """
111 get_lines test
111 get_lines test
112 """
112 """
113 text = "hello\nworld\n!"
113 text = "hello\nworld\n!"
114 assert get_lines(text, start=1) == "world\n!"
114 assert get_lines(text, start=1) == "world\n!"
115 assert get_lines(text, end=2) == "hello\nworld"
115 assert get_lines(text, end=2) == "hello\nworld"
116 assert get_lines(text, start=2, end=5) == "!"
116 assert get_lines(text, start=2, end=5) == "!"
117 assert get_lines(text, start=-2) == "world\n!"
117 assert get_lines(text, start=-2) == "world\n!"
118
118
119
119
120 def test_ipython2python(self):
120 def test_ipython2python(self):
121 """
121 """
122 ipython2python test
122 ipython2python test
123 """
123 """
124 #TODO: More tests
124 #TODO: More tests
125 results = ipython2python(u'%%pylab\nprint("Hello-World")')
125 results = ipython2python(u'%%pylab\nprint("Hello-World")')
126 self.fuzzy_compare(results, u"get_ipython().run_cell_magic(u'pylab', u'', u'print(\"Hello-World\")')",
126 self.fuzzy_compare(results, u"get_ipython().run_cell_magic(u'pylab', u'', u'print(\"Hello-World\")')",
127 ignore_spaces=True, ignore_newlines=True)
127 ignore_spaces=True, ignore_newlines=True)
General Comments 0
You need to be logged in to leave comments. Login now