@@ -642,14 +642,6 @@ class BigItem:
642642 z : Optional [int ] = None
643643
644644
645- @attrs .define
646- class SmallItem :
647- """Same with ``BigItem`` but removes the required ``x`` field."""
648-
649- y : Optional [int ] = None
650- z : Optional [int ] = None
651-
652-
653645@attrs .define
654646class BigPage (ItemPage [BigItem ]):
655647 select_fields : Optional [SelectFields ] = None
@@ -911,27 +903,3 @@ async def test_select_fields_include_exclude() -> None:
911903 assert item == BigItem (x = 1 , y = None , z = 3 )
912904 assert page .fields_to_extract == {"x" , "z" }
913905 assert page .call_counter == {"x" : 1 , "z" : 1 }
914-
915-
916- @pytest .mark .asyncio
917- async def test_select_fields_swap_item_cls () -> None :
918- # Basic case
919- page = BigPage (SelectFields (exclude = ["x" ], swap_item_cls = SmallItem ))
920- item = await page .to_item ()
921- assert item == SmallItem (y = 2 , z = 3 )
922- assert page .fields_to_extract == {"y" , "z" }
923- assert page .call_counter == {"y" : 1 , "z" : 1 }
924-
925- page = BigPage (SelectFields (include = ["y" , "z" ], swap_item_cls = SmallItem ))
926- item = await page .to_item ()
927- assert item == SmallItem (y = 2 , z = 3 )
928- assert page .fields_to_extract == {"y" , "z" }
929- assert page .call_counter == {"y" : 1 , "z" : 1 }
930-
931- # If page object supplies the new item class with unknown fields, it should
932- # raise an error
933- expected_type_error_msg = r"__init__\(\) got an unexpected keyword argument 'x'"
934- page = BigPage (SelectFields (swap_item_cls = SmallItem ))
935- with pytest .raises (TypeError , match = expected_type_error_msg ):
936- await page .to_item ()
937- assert page .fields_to_extract == {"x" , "y" , "z" }
0 commit comments