本文整理汇总了Python中webtest.utils.stringify函数的典型用法代码示例。如果您正苦于以下问题:Python stringify函数的具体用法?Python stringify怎么用?Python stringify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stringify函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __setitem__
def __setitem__(self, name, value):
"""Set the value of the named field. If there is 0 or multiple fields
by that name, it is an error.
Multiple checkboxes of the same name are special-cased; a list may be
assigned to them to check the checkboxes whose value is present in the
list (and uncheck all others).
Setting the value of a ``<select>`` selects the given option (and
confirms it is an option). Setting radio fields does the same.
Checkboxes get boolean values. You cannot set hidden fields or buttons.
Use ``.set()`` if there is any ambiguity and you must provide an index.
"""
fields = self.fields.get(name)
assert fields is not None, (
"No field by the name %r found (fields: %s)"
% (name, ', '.join(map(repr, self.fields.keys()))))
all_checkboxes = all(isinstance(f, Checkbox) for f in fields)
if all_checkboxes and isinstance(value, list):
values = set(utils.stringify(v) for v in value)
for f in fields:
f.checked = f._value in values
else:
assert len(fields) == 1, (
"Multiple fields match %r: %s"
% (name, ', '.join(map(repr, fields))))
fields[0].value = value
示例2: _get_value_for_text
def _get_value_for_text(self, text):
for i, (option_value, checked, option_text) in enumerate(self.options):
if option_text == utils.stringify(text):
return option_value
raise ValueError("Option with text %r not found (from %s)"
% (text, ', '.join(
[repr(t) for o, c, t in self.options])))
示例3: value__set
def value__set(self, value):
if self._forced_value is not NoValue:
self._forced_value = NoValue
for i, (option, checked) in enumerate(self.options):
if option == utils.stringify(value):
self.selectedIndex = i
break
else:
raise ValueError("Option %r not found (from %s)" % (value, ", ".join([repr(o) for o, c in self.options])))
示例4: _get_value_for_texts
def _get_value_for_texts(self, texts):
str_texts = [utils.stringify(text) for text in texts]
value = []
for i, (option, checked, text) in enumerate(self.options):
if text in str_texts:
value.append(option)
str_texts.remove(text)
if str_texts:
raise ValueError(
"Option(s) %r not found (from %s)"
% (', '.join(str_texts),
', '.join([repr(t) for o, c, t in self.options])))
return value
示例5: test_stringify_other
def test_stringify_other(self):
self.assertEquals(utils.stringify(123), "123")
示例6: test_stringify_binary
def test_stringify_binary(self):
self.assertEquals(utils.stringify(b"foo"), "foo")
示例7: test_stringify_text
def test_stringify_text(self):
self.assertEquals(utils.stringify("foo"), "foo")