From bf61adcbad247eb6eab72221c4b860f00febb2aa Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Wed, 13 Dec 2023 18:36:52 +0400 Subject: [PATCH 1/2] Fix logic in assert_deps. --- tests/test_web_poet_rules.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_web_poet_rules.py b/tests/test_web_poet_rules.py index afab22d2..48820d90 100644 --- a/tests/test_web_poet_rules.py +++ b/tests/test_web_poet_rules.py @@ -134,7 +134,7 @@ def assert_deps(deps: List[Dict[str, Any]], expected: Dict[str, Any], size: int # Only checks the first element for now since it's used alongside crawling # a single item. assert not deps[0].keys() - expected.keys() - assert all(True for k, v in expected.items() if isinstance(deps[0][k], v)) + assert all(isinstance(deps[0][k], v) for k, v in expected.items()) def assert_warning_tokens(caught_warnings, expected_warning_tokens): @@ -573,7 +573,7 @@ def test_item_return_individually_defined() -> None: assert_warning_tokens(caught_warnings, expected_warning_tokens) assert item == AItem(name="independent A2") - assert_deps(deps, {"item": IndependentA2Page}) + assert_deps(deps, {"item": AItem}) # calling the actual page objects should still work @@ -677,7 +677,7 @@ def test_item_return_individually_defined_first_rule_higher_priority() -> None: assert not any(True for w in caught_warnings if msg in str(w.message)) assert item == BItem(name="independent B1") - assert_deps(deps, {"item": IndependentB1Page}) + assert_deps(deps, {"item": BItem}) # calling the actual page objects should still work @@ -781,7 +781,7 @@ def test_item_return_individually_defined_second_rule_higher_priority() -> None: assert not any(True for w in caught_warnings if msg in str(w.message)) assert item == CItem(name="independent C2") - assert_deps(deps, {"item": IndependentC2Page}) + assert_deps(deps, {"item": CItem}) item, deps = yield crawl_item_and_deps(IndependentC1Page) assert item == CItem(name="independent C1") From 4df98a3d38ae20b73f4e933f3717900e425e6fc1 Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Wed, 13 Dec 2023 18:52:24 +0400 Subject: [PATCH 2/2] Fix logic in assert_warning_tokens. --- tests/test_web_poet_rules.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/test_web_poet_rules.py b/tests/test_web_poet_rules.py index 48820d90..185c7929 100644 --- a/tests/test_web_poet_rules.py +++ b/tests/test_web_poet_rules.py @@ -139,13 +139,9 @@ def assert_deps(deps: List[Dict[str, Any]], expected: Dict[str, Any], size: int def assert_warning_tokens(caught_warnings, expected_warning_tokens): results = [] - for warning in caught_warnings: + for expected in expected_warning_tokens: results.append( - all( - True - for expected in expected_warning_tokens - if expected in str(warning.message) - ) + any(expected in str(warning.message) for warning in caught_warnings) ) assert all(results)