本文整理汇总了Python中unittest.mock.Mock.value方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.value方法的具体用法?Python Mock.value怎么用?Python Mock.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.value方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call_max
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import value [as 别名]
def test_call_max(self):
validator = LengthValidator(max=1)
field = Mock()
field.value = ''
validator(field)
field.value = 'x'
validator(field)
field.value = 'xy'
assert_raises(ValidationError, validator, field)
示例2: test_call_no_args
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import value [as 别名]
def test_call_no_args(self):
"""
Behavior of strings and lists is identical
'xyz' <=> ['x', 'y', 'z']
"""
validator = LengthValidator()
field = Mock()
field.value = ''
validator(field)
field.value = 'x'
validator(field)
示例3: test_get_cookie
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import value [as 别名]
def test_get_cookie(self):
morsel = Mock()
morsel.value = "value"
self.rh.request.cookies = {"testcookie": morsel}
val = self.rh.get_cookie("testcookie")
self.assertEqual(val, "value")
val = self.rh.get_cookie("non_existent")
self.assertEqual(val, None)
示例4: test_call
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import value [as 别名]
def test_call(self):
validator = RepeatValidator('password')
master_field = Mock()
password_field = Mock()
repassword_field = Mock()
master_field.fields = {
'password': password_field,
'repassword': repassword_field,
}
password_field.master = master_field
repassword_field.master = master_field
password_field.value = 'admin'
repassword_field.value = 'admin'
validator(repassword_field)
password_field.value = 'admin'
repassword_field.value = 'root'
assert_raises(ValidationError, validator, repassword_field)
示例5: _get_recursive_structure
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import value [as 别名]
def _get_recursive_structure(self, structure, path, parent):
if not isinstance(structure, dict) or len(structure) == 0:
parent.value = structure
return
for key, subdict in structure.items():
child = Mock()
child.value = None
child.key = path + "/" + key
parent.children.append(child)
self._get_recursive_structure(subdict, child.key, child)
示例6: _factory
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import value [as 别名]
def _factory(device_id, event_type="DEVICE_EVENT", capability='',
attribute='Updated', value='Value'):
event = Mock()
event.event_type = event_type
event.device_id = device_id
event.component_id = 'main'
event.capability = capability
event.attribute = attribute
event.value = value
event.location_id = str(uuid4())
return event
示例7: get
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import value [as 别名]
def get(self, path, recursive=False, sorted=False):
dict_or_attribute = self._get_dict_from_path(path)
result = Mock()
result.children = []
if isinstance(dict_or_attribute, dict):
self._get_recursive_structure(dict_or_attribute, path, result)
else:
result.value = dict_or_attribute
return result