diff --git a/gluon/html.py b/gluon/html.py
index ba14d7b2..83d53f7d 100644
--- a/gluon/html.py
+++ b/gluon/html.py
@@ -663,7 +663,7 @@ class XML(XmlComponent):
"""
to be considered experimental since the behavior of this method
is questionable
- another option could be `TAG(self.text).elements(*args,**kwargs)`
+ another option could be `TAG(self.text).elements(*args, **kwargs)`
"""
return []
@@ -760,7 +760,7 @@ class DIV(XmlComponent):
Examples:
>>> a=DIV()
- >>> a.insert(0,SPAN('x'))
+ >>> a.insert(0, SPAN('x'))
>>> print a
x
"""
@@ -856,7 +856,7 @@ class DIV(XmlComponent):
"""
components = []
for c in self.components:
- if isinstance(c, (allowed_parents,CAT)):
+ if isinstance(c, (allowed_parents, CAT)):
pass
elif wrap_lambda:
c = wrap_lambda(c)
@@ -1027,7 +1027,7 @@ class DIV(XmlComponent):
Examples:
>>> a = DIV(DIV(SPAN('x'),3,DIV(SPAN('y'))))
- >>> for c in a.elements('span',first_only=True): c[0]='z'
+ >>> for c in a.elements('span', first_only=True): c[0]='z'
>>> print a
z3
y
>>> for c in a.elements('span'): c[0]='z'
@@ -1059,7 +1059,7 @@ class DIV(XmlComponent):
>>> a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc'))))
>>> b = a.elements('span.abc', replace=P('x', _class='xyz'))
- >>> print a
+ >>> print a # We should .xml() here instead of print
x
x
x
"replace" can be a callable, which will be passed the original element and
diff --git a/gluon/tests/test_html.py b/gluon/tests/test_html.py
index da1b604d..5c233bc5 100644
--- a/gluon/tests/test_html.py
+++ b/gluon/tests/test_html.py
@@ -14,11 +14,14 @@ from html import *
from html import verifyURL
from html import truncate_string
from storage import Storage
+from html import XML_pickle, XML_unpickle
+from html import TAG_pickler, TAG_unpickler
class TestBareHelpers(unittest.TestCase):
- # TODO: def test_xmlescape(self):
+ # xmlescape() = covered by other tests
+
# TODO: def test_call_as_list(self):
def test_truncate_string(self):
@@ -26,6 +29,8 @@ class TestBareHelpers(unittest.TestCase):
self.assertEqual(truncate_string('Lorem ipsum dolor sit amet, consectetur adipiscing elit, '
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
length=30), 'Lorem ipsum dolor sit amet,...')
+ self.assertEqual(truncate_string('Short text shorter than the length parameter.', length=100),
+ 'Short text shorter than the length parameter.')
# French text
self.assertEqual(truncate_string('Un texte en français avec des accents et des caractères bizarre.', length=30),
'Un texte en français avec d...')
@@ -169,9 +174,9 @@ class TestBareHelpers(unittest.TestCase):
self.assertEqual(XML('
Test
Test
', sanitize=True),
XML('
Test
Test
'))
- # TODO: def test_XML_unpickle(self):
-
- # TODO: def test_XML_pickle(self):
+ def test_XML_pickle_unpickle(self):
+ # weird test
+ self.assertEqual(XML_unpickle(XML_pickle('data to be pickle')[1][0]), 'data to be pickle')
def test_DIV(self):
# Empty DIV()
@@ -199,7 +204,31 @@ class TestBareHelpers(unittest.TestCase):
self.assertEqual(a.xml(), '
a
b
')
self.assertEqual([el.xml() for el in s.siblings()], ['
b
'])
self.assertEqual(s.sibling().xml(), '
b
')
+ # siblings with wrong args
self.assertEqual(s.siblings('a'), [])
+ # siblings with good args
+ self.assertEqual(s.siblings('div')[0].xml(), '
b
')
+ # Check for siblings with wrong kargs and value
+ self.assertEqual(s.siblings(a='d'), [])
+ # Check for siblings with good kargs and value
+ # Can't figure this one out what is a right value here??
+ # Commented for now...
+ # self.assertEqual(s.siblings(div='
b
'), ???)
+ # No other sibling should return None
+ self.assertEqual(DIV(P('First element')).element('p').sibling(), None)
+ # --------------------------------------------------------------------------------------------------------------
+ # This use unicode to hit xmlescape() line :
+ # """
+ # elif isinstance(data, unicode):
+ # data = data.encode('utf8', 'xmlcharrefreplace')
+ # """
+ self.assertEqual(DIV(u'Texte en français avec des caractères accentués...').xml(),
+ '
Texte en fran\xc3\xa7ais avec des caract\xc3\xa8res accentu\xc3\xa9s...
')
+ # --------------------------------------------------------------------------------------------------------------
+ self.assertEqual(DIV('Test with an ID', _id='id-of-the-element').xml(),
+ '
Test with an ID
')
+ self.assertEqual(DIV().element('p'), None)
+
# Corner case for raise coverage of one line
# I think such assert fail cause of python 2.6
# Work under python 2.7
@@ -215,9 +244,10 @@ class TestBareHelpers(unittest.TestCase):
# CAT(' ')
self.assertEqual(CAT(' ').xml(), ' ')
- # TODO: def test_TAG_unpickler(self):
-
- # TODO: def test_TAG_pickler(self):
+ def test_TAG_pickler_unpickler(self):
+ # weird test
+ self.assertEqual(TAG_unpickler(TAG_pickler(TAG.div('data to be pickle'))[1][0]).xml(),
+ '
data to be pickle
')
def test_TAG(self):
self.assertEqual(TAG.first(TAG.second('test'), _key=3).xml(),
@@ -225,6 +255,9 @@ class TestBareHelpers(unittest.TestCase):
# ending in underscore "triggers" style
self.assertEqual(TAG.first_(TAG.second('test'), _key=3).xml(),
'')
+ # unicode test for TAG
+ self.assertEqual(TAG.div(u'Texte en français avec des caractères accentués...').xml(),
+ '
Texte en fran\xc3\xa7ais avec des caract\xc3\xa8res accentu\xc3\xa9s...