Skip to content

Commit

Permalink
Add a high level test of weak-weak edges.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood committed Jul 9, 2020
1 parent 8a1bb7d commit f44588a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/python/pants/engine/internals/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from contextlib import contextmanager
from dataclasses import dataclass
from textwrap import dedent
from typing import Any
from typing import Any, FrozenSet

from pants.engine.internals.scheduler import ExecutionError
from pants.engine.rules import RootRule, rule
Expand Down Expand Up @@ -116,6 +116,20 @@ async def error_msg_test_rule(union_wrapper: UnionWrapper) -> UnionX:
raise AssertionError("The statement above this one should have failed!")


class BooleanDeps(FrozenSet[bool]):
pass


@rule
async def boolean_cycle(key: bool) -> BooleanDeps:
"""A rule with exactly two instances (bool == two keys), which depend on one another weakly."""
deps = {key}
dep = await Get(BooleanDeps, bool, not key, weak=True)
if dep is not None:
deps.update(dep)
return BooleanDeps(deps)


class TypeCheckFailWrapper:
"""This object wraps another object which will be used to demonstrate a type check failure when
the engine processes an `await Get(...)` statement."""
Expand Down Expand Up @@ -176,6 +190,8 @@ def rules(cls):
RootRule(UnionB),
select_union_b,
a_union_test,
RootRule(bool),
boolean_cycle,
]

def test_use_params(self):
Expand Down Expand Up @@ -215,6 +231,10 @@ def test_consumed_types(self):
self.scheduler.scheduler.rule_graph_consumed_types([A, C], str)
)

def test_weak_gets(self):
assert {True, False} == set(self.request_single_product(BooleanDeps, True))
assert {True, False} == set(self.request_single_product(BooleanDeps, False))

@contextmanager
def _assert_execution_error(self, expected_msg):
with assert_execution_error(self, expected_msg):
Expand Down

0 comments on commit f44588a

Please sign in to comment.