author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 28 Apr 2010 12:15:52 +0200 | |
branch | oldstable |
changeset 5424 | 8ecbcbff9777 |
parent 5421 | 8167de96c523 |
child 5730 | 784025c15a3c |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3002
diff
changeset
|
19 |
"""unittests for cubicweb.uilib |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1646
diff
changeset
|
20 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1646
diff
changeset
|
21 |
""" |
0 | 22 |
|
23 |
__docformat__ = "restructuredtext en" |
|
24 |
||
25 |
from logilab.common.testlib import TestCase, unittest_main |
|
26 |
from logilab.common.tree import Node |
|
27 |
||
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3002
diff
changeset
|
28 |
from cubicweb import uilib |
0 | 29 |
|
30 |
class UILIBTC(TestCase): |
|
31 |
||
32 |
def test_remove_tags(self): |
|
33 |
"""make sure remove_tags remove all tags""" |
|
34 |
data = [ |
|
35 |
('<h1>Hello</h1>', 'Hello'), |
|
36 |
('<h1>Hello <a href="foo/bar"><b>s</b>pam</a></h1>', 'Hello spam'), |
|
37 |
('<br>Hello<img src="doh.png"/>', 'Hello'), |
|
38 |
('<p></p>', ''), |
|
39 |
] |
|
40 |
for text, expected in data: |
|
41 |
got = uilib.remove_html_tags(text) |
|
42 |
self.assertEquals(got, expected) |
|
1646 | 43 |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
44 |
def test_fallback_safe_cut(self): |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
45 |
self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 4), u'ab c...') |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
46 |
self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 5), u'ab <a href="hello">cd</a>') |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
47 |
self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a>', 4), u'ab &...') |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
48 |
self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a> ef', 5), u'ab &d...') |
362
a6a319f000c3
use mtconverter's html_unescape rather than saxutils' escape to deal with any html entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
350
diff
changeset
|
49 |
self.assertEquals(uilib.fallback_safe_cut(u'ab <a href="hello">ìd</a>', 4), u'ab ì...') |
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
50 |
self.assertEquals(uilib.fallback_safe_cut(u'& <a href="hello">&d</a> ef', 4), u'& &d...') |
1646 | 51 |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
52 |
def test_lxml_safe_cut(self): |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
53 |
self.assertEquals(uilib.safe_cut(u'aaa<div>aaad</div> ef', 4), u'<p>aaa</p><div>a...</div>') |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
54 |
self.assertEquals(uilib.safe_cut(u'aaa<div>aaad</div> ef', 7), u'<p>aaa</p><div>aaad</div>...') |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
55 |
self.assertEquals(uilib.safe_cut(u'aaa<div>aaad</div>', 7), u'<p>aaa</p><div>aaad</div>') |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
56 |
# Missing ellipsis due to space management but we don't care |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
57 |
self.assertEquals(uilib.safe_cut(u'ab <a href="hello">&d</a>', 4), u'<p>ab <a href="hello">&...</a></p>') |
0 | 58 |
|
59 |
def test_cut(self): |
|
160
cf9ab83b1cf3
adding tests for safe_cut (and text_cut_letters)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
0
diff
changeset
|
60 |
"""tests uilib.cut() behaviour""" |
0 | 61 |
data = [ |
62 |
('hello', 'hello'), |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
63 |
('hello world', 'hello wo...'), |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
64 |
("hell<b>O'</b> world", "hell<b>O..."), |
0 | 65 |
] |
66 |
for text, expected in data: |
|
67 |
got = uilib.cut(text, 8) |
|
68 |
self.assertEquals(got, expected) |
|
69 |
||
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
70 |
def test_text_cut(self): |
0 | 71 |
"""tests uilib.text_cut() behaviour with no text""" |
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
72 |
data = [('',''), |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
73 |
("""Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod |
0 | 74 |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, |
75 |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo |
|
76 |
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
77 |
cillum dolore eu fugiat nulla pariatur.""", |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
78 |
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod \ |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
79 |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, \ |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
80 |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \ |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
81 |
consequat."), |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
82 |
("""Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod |
0 | 83 |
tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, |
84 |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo |
|
85 |
consequat Duis aute irure dolor in reprehenderit in voluptate velit esse |
|
86 |
cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat cupidatat non |
|
87 |
proident, sunt in culpa qui officia deserunt mollit anim id est laborum |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
88 |
""", |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
89 |
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod \ |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
90 |
tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, \ |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
91 |
quis nostrud exercitation ullamco laboris nisi"), |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
92 |
] |
0 | 93 |
for text, expected in data: |
94 |
got = uilib.text_cut(text, 30) |
|
95 |
self.assertEquals(got, expected) |
|
96 |
||
97 |
if __name__ == '__main__': |
|
98 |
unittest_main() |
|
99 |