def test_get_or_generate_deep_copier_for_uncached_function(): class StubClass: ... mock_copier = object() attr_extensions._DEEP_COPIERS = {StubClass: mock_copier} with mock.patch.object(attr_extensions, "generate_deep_copier"): assert attr_extensions.get_or_generate_deep_copier(StubClass) is mock_copier attr_extensions.generate_deep_copier.assert_not_called()
def test_get_or_generate_deep_copier_for_cached_function(): class StubClass: ... mock_copier = object() attr_extensions._DEEP_COPIERS = {} with mock.patch.object(attr_extensions, "generate_deep_copier", return_value=mock_copier): assert attr_extensions.get_or_generate_deep_copier(StubClass) is mock_copier attr_extensions.generate_deep_copier.assert_called_once_with(StubClass) assert attr_extensions._DEEP_COPIERS[StubClass] is mock_copier