Skip to content

Commit

Permalink
Merge pull request #181 from scrapinghub/fix-assert-deps
Browse files Browse the repository at this point in the history
Fix logic in assert_deps.
  • Loading branch information
wRAR authored Dec 13, 2023
2 parents 4f5868e + 4df98a3 commit 4f122b4
Showing 1 changed file with 6 additions and 10 deletions.
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

0 comments on commit 4f122b4

Please sign in to comment.