当前位置: 首页>>代码示例>>Python>>正文


Python Mock.value方法代码示例

本文整理汇总了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)
开发者ID:lowks,项目名称:paqforms,代码行数:14,代码来源:test_validators.py

示例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)
开发者ID:lowks,项目名称:paqforms,代码行数:15,代码来源:test_validators.py

示例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)
开发者ID:fiorix,项目名称:cyclone,代码行数:10,代码来源:test_web.py

示例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)
开发者ID:lowks,项目名称:paqforms,代码行数:21,代码来源:test_validators.py

示例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)
开发者ID:carriercomm,项目名称:dynamite,代码行数:12,代码来源:FakeEtcdClient.py

示例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
开发者ID:arsaboo,项目名称:home-assistant,代码行数:13,代码来源:conftest.py

示例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
开发者ID:carriercomm,项目名称:dynamite,代码行数:13,代码来源:FakeEtcdClient.py


注:本文中的unittest.mock.Mock.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。