Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic in assert_deps. #181

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions tests/test_web_poet_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,14 @@ 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):
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)

Expand Down Expand Up @@ -573,7 +569,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

Expand Down Expand Up @@ -677,7 +673,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

Expand Down Expand Up @@ -781,7 +777,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")
Expand Down
Loading