示例#1
0
    def test_short_repr_mocked_instance_method(self):
        class MyClass(object):
            def my_method(self):
                pass

        my_mock = mock.create_autospec(MyClass)
        self.assertRegex(objgraph._short_repr(my_mock.my_method), '<MagicMock')
示例#2
0
    def test_short_repr_mocked_instance_method(self):
        class MyClass(object):
            def my_method(self):
                pass

        my_mock = mock.create_autospec(MyClass)
        self.assertRegex(objgraph._short_repr(my_mock.my_method), '<MagicMock')
示例#3
0
    def test_short_repr_mocked_instance_method_bound_with_mocked_name(self):
        class MyClass(object):
            def my_method(self):
                pass

        mock_method = mock.Mock(__name__=mock.MagicMock())

        obj = MyClass()
        with mock.patch.object(obj, 'my_method',
                               types.MethodType(mock_method, obj)):
            self.assertRegex(objgraph._short_repr(obj.my_method), '<Mock')
示例#4
0
    def test_short_repr_mocked_instance_method_bound_with_mocked_name(self):
        class MyClass(object):
            def my_method(self):
                pass

        mock_method = mock.Mock(__name__=mock.MagicMock())

        obj = MyClass()
        with mock.patch.object(obj, 'my_method',
                               types.MethodType(mock_method, obj)):
            self.assertRegex(objgraph._short_repr(obj.my_method), '<Mock')
示例#5
0
    def test_short_repr_unbound_method(self):
        class MyClass(object):
            def a_method(self):
                pass

        self.assertEqual('a_method', objgraph._short_repr(MyClass.a_method))
示例#6
0
 def test_short_repr_mock_with_spec(self):
     self.assertRegex(objgraph._short_repr(mock.Mock(spec=list)), '<Mock')
示例#7
0
 def test_short_repr_magic_mocked_name(self):
     self.assertRegex(
         objgraph._short_repr(mock.Mock(__name__=mock.MagicMock())),
         '<Mock')
示例#8
0
 def test_short_repr_function(self):
     self.assertRegex(objgraph._short_repr(sample_func),
                      'function sample_func at .*')
示例#9
0
 def test_short_repr_lambda(self):
     f = lambda x: x  # noqa
     lambda_lineno = sys._getframe().f_lineno - 1
     self.assertEqual('lambda: tests.py:%s' % lambda_lineno,
                      objgraph._short_repr(f))
示例#10
0
    def test_short_repr_unbound_method(self):
        class MyClass(object):
            def a_method(self):
                pass

        self.assertEqual('a_method', objgraph._short_repr(MyClass.a_method))
示例#11
0
 def test_short_repr_mock_with_spec(self):
     self.assertRegex(objgraph._short_repr(mock.Mock(spec=list)), '<Mock')
示例#12
0
 def test_short_repr_magic_mocked_name(self):
     self.assertRegex(objgraph._short_repr(mock.Mock(
         __name__=mock.MagicMock())), '<Mock')
示例#13
0
文件: tests.py 项目: mgedmin/objgraph
 def test_short_repr_function(self):
     self.assertRegex(objgraph._short_repr(sample_func),
                      'function sample_func at .*')
示例#14
0
文件: tests.py 项目: mgedmin/objgraph
 def test_short_repr_lambda(self):
     f = lambda x: x  # noqa
     lambda_lineno = sys._getframe().f_lineno - 1
     self.assertEqual('lambda: tests.py:%s' % lambda_lineno,
                      objgraph._short_repr(f))