Esempio n. 1
0
    def test_eventually_doesnt_match_after_timeout_trigger(self):
        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=2,
                   timeout_call_trigger=3) as fake_now:
            matcher = eventually(be_true, timeout=0, throttle=0)
            matcher._match(fake_now.sentinel)

            assert not fake_now.sentinel.timeout_triggered(
            ), "Timeout was triggered despite getting a match."
Esempio n. 2
0
    def test_eventually_doesnt_negate_when_truth_condition_not_met(self):
        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=3,
                   timeout_call_trigger=2) as fake_now:
            matcher = eventually(be_true, timeout=0, throttle=0)
            matcher._match(fake_now.sentinel)

            assert not fake_now.sentinel.truth_triggered(
            ), "Match negated despite encountering the truth condition."
Esempio n. 3
0
    def test_eventually_doesnt_match_before_truth_trigger(self):
        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=2,
                   timeout_call_trigger=3) as fake_now:
            matcher = eventually(be_true, timeout=0, throttle=0)
            matcher._match(fake_now.sentinel)

            assert fake_now.sentinel.truth_triggered(
            ), "Did not meet truth condition before returning a match."
Esempio n. 4
0
    def test_eventually_doesnt_negate_before_timeout_trigger(self):
        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=3,
                   timeout_call_trigger=2) as fake_now:
            matcher = eventually(be_true, timeout=0, throttle=0)
            matcher._match(fake_now.sentinel)

            assert fake_now.sentinel.timeout_triggered(
            ), "Match negated without a encountering a timeout trigger."
Esempio n. 5
0
    def test_eventually_negates_match_if_function_matches_after_timeout(self):
        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=3,
                   timeout_call_trigger=2) as fake_now:
            matcher = eventually(be_true, timeout=0, throttle=0)
            match_result = matcher._match(fake_now.sentinel)

            assert not match_result[
                0], "Matcher matched when function never reached truth condition."
Esempio n. 6
0
    def test_eventually_matches_when_function_matches_before_timeout(self):
        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=2,
                   timeout_call_trigger=3) as fake_now:
            matcher = eventually(be_true, timeout=0, throttle=0)
            match_result = matcher._match(fake_now.sentinel)

            assert match_result[0], (
                "Match returned False when truth condition "
                "should have triggered before timeout.")
Esempio n. 7
0
    def test_eventually_sleeps_with_throttle(self):
        expected_throttle = 5

        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=2,
                   timeout_call_trigger=3) as fake_now:

            matcher = eventually(be_true,
                                 timeout=0,
                                 throttle=expected_throttle)
            matcher._match(fake_now.sentinel)

            expect(self.fake_sleep.slept_time).to(equal(expected_throttle))
Esempio n. 8
0
    def test_eventually_configures_timedelta_with_timeout(self):
        expected_timeout = 5

        class FakeTimedelta:
            def __init__(self):
                self.delta = None

            def __call__(self, *, seconds):
                self.delta = seconds

        with patch(f"{self.module_path}.now",
                   new_callable=FakeNow,
                   truth_call_trigger=2,
                   timeout_call_trigger=3) as fake_now:
            with patch(f"{self.module_path}.timedelta",
                       new_callable=FakeTimedelta) as fake_timedelta:
                matcher = eventually(be_true,
                                     timeout=expected_timeout,
                                     throttle=0)
                matcher._match(fake_now.sentinel)

                expect(fake_timedelta.delta).to(equal(expected_timeout))
Esempio n. 9
0
 def test_eventually_matches_when_subject_function_return_matches(self):
     expect(lambda: True).to(eventually(be_true, timeout=0, throttle=0))
Esempio n. 10
0
 def test_eventually_matcher_inherits_from_matcher(self):
     expect(eventually("", timeout=0, throttle=0)).to(be_a(Matcher))