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')
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')
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))
def test_short_repr_mock_with_spec(self): self.assertRegex(objgraph._short_repr(mock.Mock(spec=list)), '<Mock')
def test_short_repr_magic_mocked_name(self): self.assertRegex( objgraph._short_repr(mock.Mock(__name__=mock.MagicMock())), '<Mock')
def test_short_repr_function(self): self.assertRegex(objgraph._short_repr(sample_func), 'function sample_func at .*')
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))
def test_short_repr_magic_mocked_name(self): self.assertRegex(objgraph._short_repr(mock.Mock( __name__=mock.MagicMock())), '<Mock')