author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 14 Nov 2013 17:17:02 +0100 | |
changeset 9361 | 0542a85fe667 |
parent 8909 | f46b017db2d9 |
child 10116 | 4e9738f5c798 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
8909
f46b017db2d9
[test] fix skipIf import, currently failing if unittest2 is not there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7568
diff
changeset
|
2 |
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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/>. |
6153
ade53a90ddf1
remove useless import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
19 |
"""unittests for cubicweb.uilib""" |
0 | 20 |
|
21 |
__docformat__ = "restructuredtext en" |
|
22 |
||
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
23 |
|
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
24 |
import pkg_resources |
7568
c5ee33fb6a3b
[test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
25 |
|
8909
f46b017db2d9
[test] fix skipIf import, currently failing if unittest2 is not there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7568
diff
changeset
|
26 |
try: |
f46b017db2d9
[test] fix skipIf import, currently failing if unittest2 is not there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7568
diff
changeset
|
27 |
from unittest import skipIf |
f46b017db2d9
[test] fix skipIf import, currently failing if unittest2 is not there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7568
diff
changeset
|
28 |
except ImportError: |
f46b017db2d9
[test] fix skipIf import, currently failing if unittest2 is not there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7568
diff
changeset
|
29 |
from unittest2 import skipIf |
0 | 30 |
|
7568
c5ee33fb6a3b
[test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
31 |
from logilab.common.testlib import DocTest, TestCase, unittest_main |
c5ee33fb6a3b
[test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
32 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3002
diff
changeset
|
33 |
from cubicweb import uilib |
0 | 34 |
|
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
35 |
lxml_version = pkg_resources.get_distribution('lxml').version.split('.') |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
36 |
|
0 | 37 |
class UILIBTC(TestCase): |
38 |
||
39 |
def test_remove_tags(self): |
|
40 |
"""make sure remove_tags remove all tags""" |
|
41 |
data = [ |
|
42 |
('<h1>Hello</h1>', 'Hello'), |
|
43 |
('<h1>Hello <a href="foo/bar"><b>s</b>pam</a></h1>', 'Hello spam'), |
|
44 |
('<br>Hello<img src="doh.png"/>', 'Hello'), |
|
45 |
('<p></p>', ''), |
|
46 |
] |
|
47 |
for text, expected in data: |
|
48 |
got = uilib.remove_html_tags(text) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
49 |
self.assertEqual(got, expected) |
1646 | 50 |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
51 |
def test_fallback_safe_cut(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
52 |
self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 4), u'ab c...') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
53 |
self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">cd</a>', 5), u'ab <a href="hello">cd</a>') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
54 |
self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a>', 4), u'ab &...') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
55 |
self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">&d</a> ef', 5), u'ab &d...') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
56 |
self.assertEqual(uilib.fallback_safe_cut(u'ab <a href="hello">ìd</a>', 4), u'ab ì...') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
57 |
self.assertEqual(uilib.fallback_safe_cut(u'& <a href="hello">&d</a> ef', 4), u'& &d...') |
1646 | 58 |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
59 |
def test_lxml_safe_cut(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
60 |
self.assertEqual(uilib.safe_cut(u'aaa<div>aaad</div> ef', 4), u'<p>aaa</p><div>a...</div>') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
61 |
self.assertEqual(uilib.safe_cut(u'aaa<div>aaad</div> ef', 7), u'<p>aaa</p><div>aaad</div>...') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
62 |
self.assertEqual(uilib.safe_cut(u'aaa<div>aaad</div>', 7), u'<p>aaa</p><div>aaad</div>') |
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
63 |
# Missing ellipsis due to space management but we don't care |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
64 |
self.assertEqual(uilib.safe_cut(u'ab <a href="hello">&d</a>', 4), u'<p>ab <a href="hello">&...</a></p>') |
0 | 65 |
|
66 |
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
|
67 |
"""tests uilib.cut() behaviour""" |
0 | 68 |
data = [ |
69 |
('hello', 'hello'), |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
70 |
('hello world', 'hello wo...'), |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
71 |
("hell<b>O'</b> world", "hell<b>O..."), |
0 | 72 |
] |
73 |
for text, expected in data: |
|
74 |
got = uilib.cut(text, 8) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
75 |
self.assertEqual(got, expected) |
0 | 76 |
|
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
77 |
def test_text_cut(self): |
0 | 78 |
"""tests uilib.text_cut() behaviour with no text""" |
350
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
79 |
data = [('',''), |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
80 |
("""Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod |
0 | 81 |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, |
82 |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo |
|
83 |
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
|
84 |
cillum dolore eu fugiat nulla pariatur.""", |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
85 |
"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
|
86 |
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
|
87 |
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
|
88 |
consequat."), |
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 |
0 | 90 |
tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, |
91 |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo |
|
92 |
consequat Duis aute irure dolor in reprehenderit in voluptate velit esse |
|
93 |
cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat cupidatat non |
|
94 |
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
|
95 |
""", |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
96 |
"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
|
97 |
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
|
98 |
quis nostrud exercitation ullamco laboris nisi"), |
f34ef2c64605
cleanup/fix cut variants
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
343
diff
changeset
|
99 |
] |
0 | 100 |
for text, expected in data: |
101 |
got = uilib.text_cut(text, 30) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
102 |
self.assertEqual(got, expected) |
0 | 103 |
|
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
104 |
def test_soup2xhtml_0(self): |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
105 |
self.assertEqual(uilib.soup2xhtml('hop\r\nhop', 'ascii'), |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
106 |
'hop\nhop') |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
107 |
|
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
108 |
def test_soup2xhtml_1_1(self): |
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
109 |
self.assertEqual(uilib.soup2xhtml('hop', 'ascii'), |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
110 |
'hop') |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
111 |
self.assertEqual(uilib.soup2xhtml('hop<div>', 'ascii'), |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
112 |
'hop<div/>') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
113 |
self.assertEqual(uilib.soup2xhtml('hop <div>', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
114 |
'hop <div/>') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
115 |
self.assertEqual(uilib.soup2xhtml('<div> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
116 |
'<div> hop</div>') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
117 |
self.assertEqual(uilib.soup2xhtml('hop <div> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
118 |
'hop <div> hop</div>') |
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
119 |
|
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
120 |
def test_soup2xhtml_1_2(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
121 |
self.assertEqual(uilib.soup2xhtml('hop </div>', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
122 |
'hop ') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
123 |
self.assertEqual(uilib.soup2xhtml('</div> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
124 |
'<div/> hop') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
125 |
self.assertEqual(uilib.soup2xhtml('hop </div> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
126 |
'<div>hop </div> hop') |
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
127 |
|
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
128 |
def test_soup2xhtml_2_1(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
129 |
self.assertEqual(uilib.soup2xhtml('hop <body>', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
130 |
'hop ') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
131 |
self.assertEqual(uilib.soup2xhtml('<body> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
132 |
' hop') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
133 |
self.assertEqual(uilib.soup2xhtml('hop <body> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
134 |
'hop hop') |
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
135 |
|
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
136 |
def test_soup2xhtml_2_2a(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
137 |
self.assertEqual(uilib.soup2xhtml('hop </body>', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
138 |
'hop ') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
139 |
self.assertEqual(uilib.soup2xhtml('</body> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
140 |
' hop') |
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
141 |
|
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
142 |
@skipIf(lxml_version < ['2', '2'], 'expected behaviour on recent version of lxml only') |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
143 |
def test_soup2xhtml_2_2b(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
144 |
self.assertEqual(uilib.soup2xhtml('hop </body> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
145 |
'hop hop') |
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
146 |
|
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
147 |
def test_soup2xhtml_3_1(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
148 |
self.assertEqual(uilib.soup2xhtml('hop <html>', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
149 |
'hop ') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
150 |
self.assertEqual(uilib.soup2xhtml('<html> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
151 |
' hop') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
152 |
self.assertEqual(uilib.soup2xhtml('hop <html> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
153 |
'hop hop') |
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
154 |
|
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
155 |
def test_soup2xhtml_3_2(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
156 |
self.assertEqual(uilib.soup2xhtml('hop </html>', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
157 |
'hop ') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
158 |
self.assertEqual(uilib.soup2xhtml('</html> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
159 |
' hop') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
160 |
self.assertEqual(uilib.soup2xhtml('hop </html> hop', 'ascii'), |
5730
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
161 |
'hop hop') |
784025c15a3c
[xhtml] fix soup2xhtml to deal with malformed div,body and html tags which may leads to malformed return value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
162 |
|
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
163 |
def test_soup2xhtml_3_3(self): |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
164 |
self.assertEqual(uilib.soup2xhtml('<script>test</script> hop ', 'ascii'), |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
165 |
' hop ') |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
166 |
|
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5730
diff
changeset
|
167 |
def test_js(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
168 |
self.assertEqual(str(uilib.js.pouet(1, "2")), |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5730
diff
changeset
|
169 |
'pouet(1,"2")') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
170 |
self.assertEqual(str(uilib.js.cw.pouet(1, "2")), |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5730
diff
changeset
|
171 |
'cw.pouet(1,"2")') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
172 |
self.assertEqual(str(uilib.js.cw.pouet(1, "2").pouet(None)), |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5730
diff
changeset
|
173 |
'cw.pouet(1,"2").pouet(null)') |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5730
diff
changeset
|
174 |
|
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
175 |
def test_embedded_css(self): |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
176 |
incoming = u"""voir le ticket <style type="text/css">@font-face { font-family: "Cambria"; }p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0cm 0cm 10pt; font-size: 12pt; font-family: "Times New Roman"; }a:link, span.MsoHyperlink { color: blue; text-decoration: underline; }a:visited, span.MsoHyperlinkFollowed { color: purple; text-decoration: underline; }div.Section1 { page: Section1; }</style></p><p class="MsoNormal">text</p>""" |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
177 |
expected = 'voir le ticket <p class="MsoNormal">text</p>' |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
178 |
self.assertMultiLineEqual(uilib.soup2xhtml(incoming, 'ascii'), expected) |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
179 |
|
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
180 |
def test_unknown_namespace(self): |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
181 |
incoming = '''<table cellspacing="0" cellpadding="0" width="81" border="0" x:str="" style="width: 61pt; border-collapse: collapse"> |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
182 |
<colgroup><col width="81" style="width: 61pt; mso-width-source: userset; mso-width-alt: 2962"/></colgroup> |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
183 |
<tbody><tr height="17" style="height: 12.75pt"><td width="81" height="17" style="border-right: #e0dfe3; border-top: #e0dfe3; border-left: #e0dfe3; width: 61pt; border-bottom: #e0dfe3; height: 12.75pt; background-color: transparent"><font size="2">XXXXXXX</font></td></tr></tbody> |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
184 |
</table>''' |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
185 |
expected = '''<table cellspacing="0" cellpadding="0" width="81" border="0">\ |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
186 |
<colgroup><col width="81"/></colgroup>\ |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
187 |
<tbody><tr height="17"><td width="81" height="17">XXXXXXX</td></tr></tbody>\ |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
188 |
</table>''' |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
189 |
self.assertMultiLineEqual(uilib.soup2xhtml(incoming, 'ascii'), expected) |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
190 |
|
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6366
diff
changeset
|
191 |
|
7568
c5ee33fb6a3b
[test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
192 |
class DocTest(DocTest): |
c5ee33fb6a3b
[test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
193 |
module = uilib |
c5ee33fb6a3b
[test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
194 |
|
c5ee33fb6a3b
[test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
195 |
|
0 | 196 |
if __name__ == '__main__': |
197 |
unittest_main() |
|
198 |