本文整理汇总了Python中yattag.Doc.input方法的典型用法代码示例。如果您正苦于以下问题:Python Doc.input方法的具体用法?Python Doc.input怎么用?Python Doc.input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yattag.Doc
的用法示例。
在下文中一共展示了Doc.input方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_input_no_slash
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import input [as 别名]
def test_input_no_slash(self):
doc = Doc(stag_end = '>')
doc.input('passw', type="password")
self.assertTrue(
doc.getvalue() in (
'<input name="passw" type="password">',
'<input type="password" name="passw">'
)
)
示例2: test_input_radio
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import input [as 别名]
def test_input_radio(self):
doc, tag, text = Doc(defaults = {'color': 'red'}).tagtext()
with tag('body'):
for color in ('blue', 'red', 'pink', 'yellow', 'ugly-yellow'):
doc.input(('type', 'radio'), id = 'color-input', name = "color", value = color)
text(color)
root = ET.fromstring(doc.getvalue())
self.assertEqual(
root[2].attrib['name'], 'color'
)
self.assertEqual(
root[3].attrib['type'], 'radio'
)
self.assertEqual(
root[1].attrib['checked'], 'checked'
)
self.assertRaises(
KeyError, lambda: root[0].attrib['checked']
)
示例3: test_input_text
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import input [as 别名]
def test_input_text(self):
doc, tag, text = Doc(
defaults = {'color': 'yellow'},
errors = {'color': 'yellow not available'}
).tagtext()
with tag('body'):
doc.input('color', ('data-stuff', 'stuff'), type = 'text')
root = ET.fromstring(doc.getvalue())
self.assertEqual(
root[1].attrib['value'],
'yellow'
)
self.assertEqual(
root[1].attrib['data-stuff'],
'stuff'
)
self.assertTrue(
'error' in root[1].attrib['class']
)
示例4: test_input_checkbox
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import input [as 别名]
def test_input_checkbox(self):
doc, tag, text = Doc(defaults = {'gift-wrap': 'yes'}).tagtext()
with tag('body'):
doc.input('gift-wrap', type='checkbox', value = "yes")
root = ET.fromstring(doc.getvalue())
self.assertEqual(
root[0].attrib['checked'], 'checked'
)
doc, tag, text = Doc(defaults = {'extras': ['fast-shipping', 'gift-wrap']}).tagtext()
with tag('body'):
for extra in ('fast-shipping', 'extension-of-warranty', 'gift-wrap'):
doc.input('extras', type="checkbox", value = extra)
root = ET.fromstring(doc.getvalue())
self.assertEqual(
root[0].attrib['checked'], 'checked'
)
self.assertRaises(
KeyError, lambda: root[1].attrib['checked']
)
self.assertEqual(
root[2].attrib['checked'], 'checked'
)