bpo-38473: Handle autospecced functions and methods used with attach_… · python/cpython@66b00a9

@@ -1922,6 +1922,35 @@ def test_attach_mock_patch_autospec(self):

19221922

self.assertEqual(mock_func.mock._extract_mock_name(), 'mock.child')

19231923192419241925+

def test_attach_mock_patch_autospec_signature(self):

1926+

with mock.patch(f'{__name__}.Something.meth', autospec=True) as mocked:

1927+

manager = Mock()

1928+

manager.attach_mock(mocked, 'attach_meth')

1929+

obj = Something()

1930+

obj.meth(1, 2, 3, d=4)

1931+

manager.assert_has_calls([call.attach_meth(mock.ANY, 1, 2, 3, d=4)])

1932+

obj.meth.assert_has_calls([call(mock.ANY, 1, 2, 3, d=4)])

1933+

mocked.assert_has_calls([call(mock.ANY, 1, 2, 3, d=4)])

1934+1935+

with mock.patch(f'{__name__}.something', autospec=True) as mocked:

1936+

manager = Mock()

1937+

manager.attach_mock(mocked, 'attach_func')

1938+

something(1)

1939+

manager.assert_has_calls([call.attach_func(1)])

1940+

something.assert_has_calls([call(1)])

1941+

mocked.assert_has_calls([call(1)])

1942+1943+

with mock.patch(f'{__name__}.Something', autospec=True) as mocked:

1944+

manager = Mock()

1945+

manager.attach_mock(mocked, 'attach_obj')

1946+

obj = Something()

1947+

obj.meth(1, 2, 3, d=4)

1948+

manager.assert_has_calls([call.attach_obj(),

1949+

call.attach_obj().meth(1, 2, 3, d=4)])

1950+

obj.meth.assert_has_calls([call(1, 2, 3, d=4)])

1951+

mocked.assert_has_calls([call(), call().meth(1, 2, 3, d=4)])

1952+1953+19251954

def test_attribute_deletion(self):

19261955

for mock in (Mock(), MagicMock(), NonCallableMagicMock(),

19271956

NonCallableMock()):