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