Esempio n. 1
0
async def test_behavior_reentrance_protection(alice):
    behavior = Behavior(always, SimpleLogic())
    async with behavior.apply(alice):
        with pytest.raises(ValidationError, match="Reentrance: Behavior"):
            async with behavior.apply(alice):
                # this block should not be hit
                raise AssertionError("should not be hit")
Esempio n. 2
0
def test_behaviour_should_apply(alice):
    def _is_alice(connection, logic):
        return connection is alice

    behavior = Behavior(_is_alice, SimpleLogic())

    assert behavior.should_apply_to(alice) is True
    assert behavior.should_apply_to(bob) is False
Esempio n. 3
0
 def as_behavior(self, qualifier: QualifierFn = None) -> BehaviorAPI:
     if qualifier is None:
         # mypy bug: https://github.com/python/mypy/issues/708
         if self.qualifier is None:  # type: ignore
             raise TypeError("No qualifier provided or found on class")
         # mypy bug: https://github.com/python/mypy/issues/708
         qualifier = self.qualifier  # type: ignore
     return Behavior(qualifier, self)
Esempio n. 4
0
async def test_behavior_logic_reuse_protection_on_apply(alice):
    logic = SimpleLogic()
    behavior_a = Behavior(always, logic)
    behavior_b = Behavior(always, logic)
    async with behavior_a.apply(alice):
        with pytest.raises(ValidationError, match="Reentrance: Logic"):
            async with behavior_b.apply(alice):
                # this block should not be hit
                raise AssertionError("should not be hit")
async def test_behavior_crash(alice):
    behavior = Behavior(always, CrashingLogic())
    async with behavior.apply(alice) as future:
        with pytest.raises(BehaviorCrash):
            await future