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


Python mock.m方法代码示例

本文整理汇总了Python中unittest.mock.m方法的典型用法代码示例。如果您正苦于以下问题:Python mock.m方法的具体用法?Python mock.m怎么用?Python mock.m使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock的用法示例。


在下文中一共展示了mock.m方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dir

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_dir(self):
        mock = Mock()
        attrs = set(dir(mock))
        type_attrs = set([m for m in dir(Mock) if not m.startswith('_')])

        # all public attributes from the type are included
        self.assertEqual(set(), type_attrs - attrs)

        # creates these attributes
        mock.a, mock.b
        self.assertIn('a', dir(mock))
        self.assertIn('b', dir(mock))

        # instance attributes
        mock.c = mock.d = None
        self.assertIn('c', dir(mock))
        self.assertIn('d', dir(mock))

        # magic methods
        mock.__iter__ = lambda s: iter([])
        self.assertIn('__iter__', dir(mock)) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:23,代码来源:testmock.py

示例2: test_side_effect_iterator_exceptions

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_side_effect_iterator_exceptions(self):
        for Klass in Mock, MagicMock:
            iterable = (ValueError, 3, KeyError, 6)
            m = Klass(side_effect=iterable)
            self.assertRaises(ValueError, m)
            self.assertEqual(m(), 3)
            self.assertRaises(KeyError, m)
            self.assertEqual(m(), 6) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:10,代码来源:testmock.py

示例3: test_magic_methods_mock_calls

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_magic_methods_mock_calls(self):
        for Klass in Mock, MagicMock:
            m = Klass()
            m.__int__ = Mock(return_value=3)
            m.__float__ = MagicMock(return_value=3.0)
            int(m)
            float(m)

            self.assertEqual(m.mock_calls, [call.__int__(), call.__float__()])
            self.assertEqual(m.method_calls, []) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:12,代码来源:testmock.py

示例4: test_attribute_deletion

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_attribute_deletion(self):
        # this behaviour isn't *useful*, but at least it's now tested...
        for Klass in Mock, MagicMock, NonCallableMagicMock, NonCallableMock:
            m = Klass()
            original = m.foo
            m.foo = 3
            del m.foo
            self.assertEqual(m.foo, original)

            new = m.foo = Mock()
            del m.foo
            self.assertEqual(m.foo, new) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:14,代码来源:testmock.py

示例5: test_mock_parents

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_mock_parents(self):
        for Klass in Mock, MagicMock:
            m = Klass()
            original_repr = repr(m)
            m.return_value = m
            self.assertIs(m(), m)
            self.assertEqual(repr(m), original_repr)

            m.reset_mock()
            self.assertIs(m(), m)
            self.assertEqual(repr(m), original_repr)

            m = Klass()
            m.b = m.a
            self.assertIn("name='mock.a'", repr(m.b))
            self.assertIn("name='mock.a'", repr(m.a))
            m.reset_mock()
            self.assertIn("name='mock.a'", repr(m.b))
            self.assertIn("name='mock.a'", repr(m.a))

            m = Klass()
            original_repr = repr(m)
            m.a = m()
            m.a.return_value = m

            self.assertEqual(repr(m), original_repr)
            self.assertEqual(repr(m.a()), original_repr) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:29,代码来源:testmock.py

示例6: test_attach_mock_return_value

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_attach_mock_return_value(self):
        classes = Mock, MagicMock, NonCallableMagicMock, NonCallableMock
        for Klass in Mock, MagicMock:
            for Klass2 in classes:
                m = Klass()

                m2 = Klass2(name='foo')
                m.attach_mock(m2, 'return_value')

                self.assertIs(m(), m2)
                self.assertIn("name='mock()'", repr(m2))

                m2.foo()
                self.assertEqual(m.mock_calls, call().foo().call_list()) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:16,代码来源:testmock.py

示例7: test_create_autospec_with_name

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_create_autospec_with_name(self):
        m = mock.create_autospec(object(), name='sweet_func')
        self.assertIn('sweet_func', repr(m))

    #Issue21238 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:testmock.py

示例8: test_mock_unsafe

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_mock_unsafe(self):
        m = Mock()
        with self.assertRaises(AttributeError):
            m.assert_foo_call()
        with self.assertRaises(AttributeError):
            m.assret_foo_call()
        m = Mock(unsafe=True)
        m.assert_foo_call()
        m.assret_foo_call()

    #Issue21262 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:testmock.py

示例9: test_assert_not_called

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_assert_not_called(self):
        m = Mock()
        m.hello.assert_not_called()
        m.hello()
        with self.assertRaises(AssertionError):
            m.hello.assert_not_called()

    #Issue21256 printout of keyword args should be in deterministic order 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:testmock.py

示例10: test_override_tuple_methods

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_override_tuple_methods(self):
        c = call.count()
        i = call.index(132,'hello')
        m = Mock()
        m.count()
        m.index(132,"hello")
        self.assertEqual(m.method_calls[0], c)
        self.assertEqual(m.method_calls[1], i) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:testmock.py

示例11: test_attach_mock

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_attach_mock(self):
        classes = Mock, MagicMock, NonCallableMagicMock, NonCallableMock
        for Klass in classes:
            for Klass2 in classes:
                m = Klass()

                m2 = Klass2(name='foo')
                m.attach_mock(m2, 'bar')

                self.assertIs(m.bar, m2)
                self.assertIn("name='mock.bar'", repr(m2))

                m.bar.baz(1)
                self.assertEqual(m.mock_calls, [call.bar.baz(1)])
                self.assertEqual(m.method_calls, [call.bar.baz(1)]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:testmock.py

示例12: test_assert_called_with_any

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_assert_called_with_any(self):
        m = MagicMock()
        m(MagicMock())
        m.assert_called_with(mock.ANY) 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:6,代码来源:testmock.py

示例13: test_assert_called

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_assert_called(self):
        m = Mock()
        with self.assertRaises(AssertionError):
            m.hello.assert_called()
        m.hello()
        m.hello.assert_called()

        m.hello()
        m.hello.assert_called() 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:11,代码来源:testmock.py

示例14: test_assert_called_once

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_assert_called_once(self):
        m = Mock()
        with self.assertRaises(AssertionError):
            m.hello.assert_called_once()
        m.hello()
        m.hello.assert_called_once()

        m.hello()
        with self.assertRaises(AssertionError):
            m.hello.assert_called_once()

    #Issue21256 printout of keyword args should be in deterministic order 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:14,代码来源:testmock.py

示例15: test_sorted_call_signature

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import m [as 别名]
def test_sorted_call_signature(self):
        m = Mock()
        m.hello(name='hello', daddy='hero')
        text = "call(daddy='hero', name='hello')"
        self.assertEqual(repr(m.hello.call_args), text)

    #Issue21270 overrides tuple methods for mock.call objects 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:9,代码来源:testmock.py


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