37 ('<br>Hello<img src="doh.png"/>', 'Hello'), |
37 ('<br>Hello<img src="doh.png"/>', 'Hello'), |
38 ('<p></p>', ''), |
38 ('<p></p>', ''), |
39 ] |
39 ] |
40 for text, expected in data: |
40 for text, expected in data: |
41 got = uilib.remove_html_tags(text) |
41 got = uilib.remove_html_tags(text) |
42 self.assertEquals(got, expected) |
42 self.assertEqual(got, expected) |
43 |
43 |
44 def test_fallback_safe_cut(self): |
44 def test_fallback_safe_cut(self): |
45 self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 4), u'ab c...') |
45 self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 4), u'ab c...') |
46 self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 5), u'ab <a href="hello">cd</a>') |
46 self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 5), u'ab <a href="hello">cd</a>') |
47 self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a>', 4), u'ab &...') |
47 self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a>', 4), u'ab &...') |
48 self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a> ef', 5), u'ab &d...') |
48 self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a> ef', 5), u'ab &d...') |
49 self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">ìd</a>', 4), u'ab ì...') |
49 self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">ìd</a>', 4), u'ab ì...') |
50 self.assertEquals(uilib.fallback_safe_cut(u'& <a href="hello">&d</a> ef', 4), u'& &d...') |
50 self.assertEqual(uilib.fallback_safe_cut(u'& <a href="hello">&d</a> ef', 4), u'& &d...') |
51 |
51 |
52 def test_lxml_safe_cut(self): |
52 def test_lxml_safe_cut(self): |
53 self.assertEquals(uilib.safe_cut(u'aaa<div>aaad</div> ef', 4), u'<p>aaa</p><div>a...</div>') |
53 self.assertEqual(uilib.safe_cut(u'aaa<div>aaad</div> ef', 4), u'<p>aaa</p><div>a...</div>') |
54 self.assertEquals(uilib.safe_cut(u'aaa<div>aaad</div> ef', 7), u'<p>aaa</p><div>aaad</div>...') |
54 self.assertEqual(uilib.safe_cut(u'aaa<div>aaad</div> ef', 7), u'<p>aaa</p><div>aaad</div>...') |
55 self.assertEquals(uilib.safe_cut(u'aaa<div>aaad</div>', 7), u'<p>aaa</p><div>aaad</div>') |
55 self.assertEqual(uilib.safe_cut(u'aaa<div>aaad</div>', 7), u'<p>aaa</p><div>aaad</div>') |
56 # Missing ellipsis due to space management but we don't care |
56 # Missing ellipsis due to space management but we don't care |
57 self.assertEquals(uilib.safe_cut(u'ab <a href="hello">&d</a>', 4), u'<p>ab <a href="hello">&...</a></p>') |
57 self.assertEqual(uilib.safe_cut(u'ab <a href="hello">&d</a>', 4), u'<p>ab <a href="hello">&...</a></p>') |
58 |
58 |
59 def test_cut(self): |
59 def test_cut(self): |
60 """tests uilib.cut() behaviour""" |
60 """tests uilib.cut() behaviour""" |
61 data = [ |
61 data = [ |
62 ('hello', 'hello'), |
62 ('hello', 'hello'), |
63 ('hello world', 'hello wo...'), |
63 ('hello world', 'hello wo...'), |
64 ("hell<b>O'</b> world", "hell<b>O..."), |
64 ("hell<b>O'</b> world", "hell<b>O..."), |
65 ] |
65 ] |
66 for text, expected in data: |
66 for text, expected in data: |
67 got = uilib.cut(text, 8) |
67 got = uilib.cut(text, 8) |
68 self.assertEquals(got, expected) |
68 self.assertEqual(got, expected) |
69 |
69 |
70 def test_text_cut(self): |
70 def test_text_cut(self): |
71 """tests uilib.text_cut() behaviour with no text""" |
71 """tests uilib.text_cut() behaviour with no text""" |
72 data = [('',''), |
72 data = [('',''), |
73 ("""Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod |
73 ("""Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod |
90 tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, \ |
90 tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, \ |
91 quis nostrud exercitation ullamco laboris nisi"), |
91 quis nostrud exercitation ullamco laboris nisi"), |
92 ] |
92 ] |
93 for text, expected in data: |
93 for text, expected in data: |
94 got = uilib.text_cut(text, 30) |
94 got = uilib.text_cut(text, 30) |
95 self.assertEquals(got, expected) |
95 self.assertEqual(got, expected) |
96 |
96 |
97 def test_soup2xhtml_1_1(self): |
97 def test_soup2xhtml_1_1(self): |
98 self.assertEquals(uilib.soup2xhtml('hop <div>', 'ascii'), |
98 self.assertEqual(uilib.soup2xhtml('hop <div>', 'ascii'), |
99 'hop <div/>') |
99 'hop <div/>') |
100 self.assertEquals(uilib.soup2xhtml('<div> hop', 'ascii'), |
100 self.assertEqual(uilib.soup2xhtml('<div> hop', 'ascii'), |
101 '<div> hop</div>') |
101 '<div> hop</div>') |
102 self.assertEquals(uilib.soup2xhtml('hop <div> hop', 'ascii'), |
102 self.assertEqual(uilib.soup2xhtml('hop <div> hop', 'ascii'), |
103 'hop <div> hop</div>') |
103 'hop <div> hop</div>') |
104 |
104 |
105 def test_soup2xhtml_1_2(self): |
105 def test_soup2xhtml_1_2(self): |
106 self.assertEquals(uilib.soup2xhtml('hop </div>', 'ascii'), |
106 self.assertEqual(uilib.soup2xhtml('hop </div>', 'ascii'), |
107 'hop ') |
107 'hop ') |
108 self.assertEquals(uilib.soup2xhtml('</div> hop', 'ascii'), |
108 self.assertEqual(uilib.soup2xhtml('</div> hop', 'ascii'), |
109 '<div/> hop') |
109 '<div/> hop') |
110 self.assertEquals(uilib.soup2xhtml('hop </div> hop', 'ascii'), |
110 self.assertEqual(uilib.soup2xhtml('hop </div> hop', 'ascii'), |
111 '<div>hop </div> hop') |
111 '<div>hop </div> hop') |
112 |
112 |
113 def test_soup2xhtml_2_1(self): |
113 def test_soup2xhtml_2_1(self): |
114 self.assertEquals(uilib.soup2xhtml('hop <body>', 'ascii'), |
114 self.assertEqual(uilib.soup2xhtml('hop <body>', 'ascii'), |
115 'hop ') |
115 'hop ') |
116 self.assertEquals(uilib.soup2xhtml('<body> hop', 'ascii'), |
116 self.assertEqual(uilib.soup2xhtml('<body> hop', 'ascii'), |
117 ' hop') |
117 ' hop') |
118 self.assertEquals(uilib.soup2xhtml('hop <body> hop', 'ascii'), |
118 self.assertEqual(uilib.soup2xhtml('hop <body> hop', 'ascii'), |
119 'hop hop') |
119 'hop hop') |
120 |
120 |
121 def test_soup2xhtml_2_2(self): |
121 def test_soup2xhtml_2_2(self): |
122 self.assertEquals(uilib.soup2xhtml('hop </body>', 'ascii'), |
122 self.assertEqual(uilib.soup2xhtml('hop </body>', 'ascii'), |
123 'hop ') |
123 'hop ') |
124 self.assertEquals(uilib.soup2xhtml('</body> hop', 'ascii'), |
124 self.assertEqual(uilib.soup2xhtml('</body> hop', 'ascii'), |
125 ' hop') |
125 ' hop') |
126 self.assertEquals(uilib.soup2xhtml('hop </body> hop', 'ascii'), |
126 self.assertEqual(uilib.soup2xhtml('hop </body> hop', 'ascii'), |
127 'hop hop') |
127 'hop hop') |
128 |
128 |
129 def test_soup2xhtml_3_1(self): |
129 def test_soup2xhtml_3_1(self): |
130 self.assertEquals(uilib.soup2xhtml('hop <html>', 'ascii'), |
130 self.assertEqual(uilib.soup2xhtml('hop <html>', 'ascii'), |
131 'hop ') |
131 'hop ') |
132 self.assertEquals(uilib.soup2xhtml('<html> hop', 'ascii'), |
132 self.assertEqual(uilib.soup2xhtml('<html> hop', 'ascii'), |
133 ' hop') |
133 ' hop') |
134 self.assertEquals(uilib.soup2xhtml('hop <html> hop', 'ascii'), |
134 self.assertEqual(uilib.soup2xhtml('hop <html> hop', 'ascii'), |
135 'hop hop') |
135 'hop hop') |
136 |
136 |
137 def test_soup2xhtml_3_2(self): |
137 def test_soup2xhtml_3_2(self): |
138 self.assertEquals(uilib.soup2xhtml('hop </html>', 'ascii'), |
138 self.assertEqual(uilib.soup2xhtml('hop </html>', 'ascii'), |
139 'hop ') |
139 'hop ') |
140 self.assertEquals(uilib.soup2xhtml('</html> hop', 'ascii'), |
140 self.assertEqual(uilib.soup2xhtml('</html> hop', 'ascii'), |
141 ' hop') |
141 ' hop') |
142 self.assertEquals(uilib.soup2xhtml('hop </html> hop', 'ascii'), |
142 self.assertEqual(uilib.soup2xhtml('hop </html> hop', 'ascii'), |
143 'hop hop') |
143 'hop hop') |
144 |
144 |
145 def test_js(self): |
145 def test_js(self): |
146 self.assertEquals(str(uilib.js.pouet(1, "2")), |
146 self.assertEqual(str(uilib.js.pouet(1, "2")), |
147 'pouet(1,"2")') |
147 'pouet(1,"2")') |
148 self.assertEquals(str(uilib.js.cw.pouet(1, "2")), |
148 self.assertEqual(str(uilib.js.cw.pouet(1, "2")), |
149 'cw.pouet(1,"2")') |
149 'cw.pouet(1,"2")') |
150 self.assertEquals(str(uilib.js.cw.pouet(1, "2").pouet(None)), |
150 self.assertEqual(str(uilib.js.cw.pouet(1, "2").pouet(None)), |
151 'cw.pouet(1,"2").pouet(null)') |
151 'cw.pouet(1,"2").pouet(null)') |
152 |
152 |
153 if __name__ == '__main__': |
153 if __name__ == '__main__': |
154 unittest_main() |
154 unittest_main() |
155 |
155 |