def test_special_boolean_html_attrs(self): s = attrs(fake_context, attrs={'checked': True}) self.assertEqual(s, u'checked="checked"') s = attrs(fake_context, attrs={'checked': False}) self.assertEqual(s, u'') s = attrs(fake_context, attrs={'checked': None}) self.assertEqual(s, u'')
def test_special_boolean_html_attrs(self): s = attrs(fake_context, attrs={'checked':True}) self.assertEqual(s, u'checked="checked"') s = attrs(fake_context, attrs={'checked':False}) self.assertEqual(s, u'') s = attrs(fake_context, attrs={'checked':None}) self.assertEqual(s, u'')
def etree(context, tagname, attrs, content): starttag = "" endtag = "" if tagname: if attrs: starttag = "<%s %s>" % (tagname, tw2_mu.attrs(context, attrs=attrs)) else: starttag = "<%s>" % tagname if tagname in ("input", "br", "hr", "img"): endtag = "" else: endtag = "</%s>" % tagname c = "" if isinstance(content, list): c = "".join([etree(context, *entry) for entry in content]) elif isinstance(content, tuple): c = etree(context, *content) elif content: #c = Markup(content) c = content element = starttag + c + endtag #log.debug("**** element=" + element) return element
def test_normal_attrs(self): s = attrs(fake_context, attrs={'a': 5, 'b': 3}) self.failUnless(s == u'a="5" b="3"' or s == u'b="3" a="5"')
def test_none_attrs(self): """Attributes with None values are not rendered""" s = attrs(fake_context, attrs={'a': 'hello', 'b': None}) self.assertEqual(s, u'a="hello"')
def test_boolean_attrs(self): s = attrs(fake_context, attrs={'a': True, 'b': False}) self.failUnless(s == u'a="True" b="False"' or s == u'b="False" a="True"')
def test_normal_attrs(self): s = attrs(fake_context, attrs={'a':5, 'b':3}) self.failUnless(s == u'a="5" b="3"' or s == u'b="3" a="5"')
def test_none_attrs(self): """Attributes with None values are not rendered""" s = attrs(fake_context, attrs={'a':'hello', 'b':None}) self.assertEqual(s, u'a="hello"')
def test_boolean_attrs(self): s = attrs(fake_context, attrs={'a':True, 'b':False}) self.failUnless(s == u'a="True" b="False"' or s == u'b="False" a="True"')
def test_normal_attrs_as_args(self): s = attrs(fake_context, {'a':5, 'b':3}) self.failUnless(s == six.u('a="5" b="3"') or s == six.u('b="3" a="5"'))