def test_get_or_generate_shallow_copier_for_uncached_copier(): mock_copier = object() @attr.define() class StubModel: ... with mock.patch.object(attr_extensions, "generate_shallow_copier", return_value=mock_copier): assert attr_extensions.get_or_generate_shallow_copier(StubModel) is mock_copier attr_extensions.generate_shallow_copier.assert_called_once_with(StubModel) assert attr_extensions._SHALLOW_COPIERS[StubModel] is mock_copier
def test_get_or_generate_shallow_copier_for_cached_copier(): mock_copier = object() @attr.define() class StubModel: ... attr_extensions._SHALLOW_COPIERS = { type("b", (), {}): object(), StubModel: mock_copier, type("a", (), {}): object(), } assert attr_extensions.get_or_generate_shallow_copier(StubModel) is mock_copier