Show More
@@ -1,127 +1,127 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Module with tests for Strings |
|
3 | 3 | """ |
|
4 | 4 | |
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | 6 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | 7 | # |
|
8 | 8 | # Distributed under the terms of the Modified BSD License. |
|
9 | 9 | # |
|
10 | 10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | from ...tests.base import TestsBase |
|
19 | 19 | from ..strings import * |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | #----------------------------------------------------------------------------- |
|
23 | 23 | # Class |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | class TestStrings(TestsBase): |
|
27 | 27 | |
|
28 | 28 | def test_wrap_text(self): |
|
29 | 29 | """ |
|
30 | 30 | wrap_text test |
|
31 | 31 | """ |
|
32 | 32 | test_text = """ |
|
33 | 33 | Tush! never tell me; I take it much unkindly |
|
34 | 34 | That thou, Iago, who hast had my purse |
|
35 | 35 | As if the strings were thine, shouldst know of this. |
|
36 | 36 | """ |
|
37 | 37 | for length in [30,5,1]: |
|
38 | 38 | yield self._confirm_wrap_text, test_text, length |
|
39 | 39 | |
|
40 | 40 | def _confirm_wrap_text(self, text, length): |
|
41 | 41 | for line in wrap_text(text, length).split('\n'): |
|
42 | 42 | assert len(line) <= length |
|
43 | 43 | |
|
44 | 44 | def test_html2text(self): |
|
45 | 45 | """ |
|
46 | 46 | html2text test |
|
47 | 47 | """ |
|
48 | 48 | #TODO: More tests |
|
49 | 49 | assert html2text('<name>joe</name>') == 'joe' |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | def test_add_anchor(self): |
|
53 | 53 | """ |
|
54 | 54 | add_anchor test |
|
55 | 55 | """ |
|
56 | 56 | #TODO: More tests |
|
57 |
|
|
|
57 | self.fuzzy_compare(add_anchor('<b>Hello World!</b>'), '<b id="Hello-World!">Hello World!<a class="anchor-link" href="#Hello-World!">¶</a></b>') | |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | def test_strip_dollars(self): |
|
61 | 61 | """ |
|
62 | 62 | strip_dollars test |
|
63 | 63 | """ |
|
64 | 64 | tests = [ |
|
65 | 65 | ('', ''), |
|
66 | 66 | ('$$', ''), |
|
67 | 67 | ('$H$', 'H'), |
|
68 | 68 | ('$He', 'He'), |
|
69 | 69 | ('H$el', 'H$el'), |
|
70 | 70 | ('Hell$', 'Hell'), |
|
71 | 71 | ('Hello', 'Hello'), |
|
72 | 72 | ('W$o$rld', 'W$o$rld')] |
|
73 | 73 | for test in tests: |
|
74 | 74 | yield self._try_strip_dollars, test[0], test[1] |
|
75 | 75 | |
|
76 | 76 | |
|
77 | 77 | def _try_strip_dollars(self, test, result): |
|
78 | 78 | assert strip_dollars(test) == result |
|
79 | 79 | |
|
80 | 80 | |
|
81 | 81 | def test_strip_files_prefix(self): |
|
82 | 82 | """ |
|
83 | 83 | strip_files_prefix test |
|
84 | 84 | """ |
|
85 | 85 | tests = [ |
|
86 | 86 | ('', ''), |
|
87 | 87 | ('/files', '/files'), |
|
88 | 88 | ('test="/files"', 'test="/files"'), |
|
89 | 89 | ('My files are in `files/`', 'My files are in `files/`'), |
|
90 | 90 | ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')] |
|
91 | 91 | for test in tests: |
|
92 | 92 | yield self._try_files_prefix, test[0], test[1] |
|
93 | 93 | |
|
94 | 94 | |
|
95 | 95 | def _try_files_prefix(self, test, result): |
|
96 | 96 | assert strip_files_prefix(test) == result |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | def test_comment_lines(self): |
|
100 | 100 | """ |
|
101 | 101 | comment_lines test |
|
102 | 102 | """ |
|
103 | 103 | for line in comment_lines('hello\nworld\n!').split('\n'): |
|
104 | 104 | assert line.startswith('# ') |
|
105 | 105 | for line in comment_lines('hello\nworld\n!', 'beep').split('\n'): |
|
106 | 106 | assert line.startswith('beep') |
|
107 | 107 | |
|
108 | 108 | |
|
109 | 109 | def test_get_lines(self): |
|
110 | 110 | """ |
|
111 | 111 | get_lines test |
|
112 | 112 | """ |
|
113 | 113 | text = "hello\nworld\n!" |
|
114 | 114 | assert get_lines(text, start=1) == "world\n!" |
|
115 | 115 | assert get_lines(text, end=2) == "hello\nworld" |
|
116 | 116 | assert get_lines(text, start=2, end=5) == "!" |
|
117 | 117 | assert get_lines(text, start=-2) == "world\n!" |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | def test_ipython2python(self): |
|
121 | 121 | """ |
|
122 | 122 | ipython2python test |
|
123 | 123 | """ |
|
124 | 124 | #TODO: More tests |
|
125 | 125 | results = ipython2python(u'%%pylab\nprint("Hello-World")') |
|
126 | 126 | self.fuzzy_compare(results, u"get_ipython().run_cell_magic(u'pylab', u'', u'print(\"Hello-World\")')", |
|
127 | 127 | ignore_spaces=True, ignore_newlines=True) |
General Comments 0
You need to be logged in to leave comments.
Login now