Skip to content

Commit

Permalink
add call_counter to all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnzZ committed Mar 1, 2023
1 parent 227b610 commit 77b06ca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ async def test_select_fields() -> None:
page = BigPage(response)
assert page.fields_to_ignore == ["z"]
assert await page.to_item() == BigItem(x=1, y=2, z=None)
assert page.call_counter == {"x": 1, "y": 1}
assert await item_from_select_fields(page) == BigItem(x=1, y=2, z=None)
assert page.call_counter == {"x": 2, "y": 2}

Expand All @@ -682,20 +683,23 @@ async def test_select_fields() -> None:
page = BigPage(response, select_fields=SelectFields(None))
assert page.fields_to_ignore == ["z"]
assert await page.to_item() == BigItem(x=1, y=2, z=None)
assert page.call_counter == {"x": 1, "y": 1}
assert await item_from_select_fields(page) == BigItem(x=1, y=2, z=None)
assert page.call_counter == {"x": 2, "y": 2}

# Same case as above but given an empty dict
page = BigPage(response, select_fields=SelectFields({}))
assert page.fields_to_ignore == ["z"]
assert await page.to_item() == BigItem(x=1, y=2, z=None)
assert page.call_counter == {"x": 1, "y": 1}
assert await item_from_select_fields(page) == BigItem(x=1, y=2, z=None)
assert page.call_counter == {"x": 2, "y": 2}

# Select all fields
page = BigPage(response, select_fields=SelectFields({"*": True}))
assert page.fields_to_ignore == []
assert await page.to_item() == BigItem(x=1, y=2, z=3)
assert page.call_counter == {"x": 1, "y": 1, "z": 1}
assert await item_from_select_fields(page) == BigItem(x=1, y=2, z=3)
assert page.call_counter == {"x": 2, "y": 2, "z": 2}

Expand All @@ -713,13 +717,15 @@ async def test_select_fields() -> None:
page = BigPage(response, select_fields=SelectFields({"*": False, "x": True}))
assert page.fields_to_ignore == ["y", "z"]
assert await page.to_item() == BigItem(x=1, y=None, z=None)
assert page.call_counter == {"x": 1}
assert await item_from_select_fields(page) == BigItem(x=1, y=None, z=None)
assert page.call_counter == {"x": 2}

# Include all fields but one
page = BigPage(response, select_fields=SelectFields({"*": True, "y": False}))
assert page.fields_to_ignore == ["y"]
assert await page.to_item() == BigItem(x=1, y=None, z=3)
assert page.call_counter == {"x": 1, "z": 1}
assert await item_from_select_fields(page) == BigItem(x=1, y=None, z=3)
assert page.call_counter == {"x": 2, "z": 2}

Expand All @@ -730,6 +736,7 @@ async def test_select_fields() -> None:
)
assert page.fields_to_ignore == []
assert await page.to_item() == BigItem(x=1, y=2, z=3)
assert page.call_counter == {"x": 1, "y": 1, "z": 1}
assert await item_from_select_fields(page) == BigItem(x=1, y=2, z=3)
assert page.call_counter == {"x": 2, "y": 2, "z": 2}

Expand All @@ -738,6 +745,7 @@ async def test_select_fields() -> None:
assert page.fields_to_ignore == ["x", "z"]
with pytest.raises(TypeError, match=expected_type_error_msg):
await page.to_item()
assert page.call_counter == {"y": 1}
with pytest.raises(TypeError, match=expected_type_error_msg):
await item_from_select_fields(page)
assert page.call_counter == {"y": 2}
Expand Down

0 comments on commit 77b06ca

Please sign in to comment.