Ejemplo n.º 1
0
 def test_tick_with_arbitrary_increment(self):
     stime.reset()
     stime.tick(5.9)
     stime.tick(6.1)
     self.assertEqual(
         stime.time(), 12.0,
         "expected time to be sum of increments after multiple ticks")
Ejemplo n.º 2
0
    def test_timer_does_not_ring_before_set_time(self):
        # create a new timer using stime as a time source
        cooking_timer = Timer(time_source=stime)
        cooking_timer.set_alarm(
            1561120200)  # Unix timestamp for 21 June 2019 around noon

        stime.reset(1561120199)  # a second before alarm time
        is_ringing = cooking_timer.is_ringing(
        )  # calls stime.time() because it is the timer time_source
        self.assertEqual(is_ringing, False,
                         "expected the timer NOT to ring before alarm time")
Ejemplo n.º 3
0
    def test_timer_rings_at_set_time(self):
        # create a new timer using stime as a time source
        cooking_timer = Timer(time_source=stime)
        cooking_timer.set_alarm(
            1561120200)  # Unix timestamp for 21 June 2019 around noon

        stime.reset(1561120200)  # exactly alarm time
        is_ringing = cooking_timer.is_ringing(
        )  # calls stime.time() because it is the timer time_source
        self.assertEqual(is_ringing, True,
                         "expected the timer to ring at alarm time")
Ejemplo n.º 4
0
    def test_timer_rings_for_five_seconds(self):
        # create a new timer using stime as a time source
        cooking_timer = Timer(time_source=stime)
        cooking_timer.set_alarm(
            1561120200)  # Unix timestamp for 21 June 2019 around noon

        stime.reset(1561120205)  # 5 seconds after alarm time
        is_ringing = cooking_timer.is_ringing(
        )  # calls stime.time() because it is the timer time_source
        self.assertEqual(
            is_ringing, True,
            "expected the timer to be ringing 5 seconds after alarm time")

        stime.tick()  # add 1 more second
        is_ringing = cooking_timer.is_ringing(
        )  # calls stime.time() because it is the timer time_source
        self.assertEqual(
            is_ringing, False,
            "expected the timer NOT to be ringing 6 seconds after alarm time")
Ejemplo n.º 5
0
 def test_reset_defaults_to_zero(self):
     stime.reset()
     self.assertEqual(stime.time(), 0.0,
                      "expected time to be 0.0 after being reset")
Ejemplo n.º 6
0
 def test_monotonic_is_alias_of_time(self):
     stime.reset(0.1)
     stime.tick()
     stime.tick(4)
     self.assertEqual(stime.monotonic(), stime.time(),
                      "expected monotonic() to be an alias of time()")
Ejemplo n.º 7
0
 def test_tick_with_arbitrary_increment(self):
     stime.reset()
     stime.tick(6.3)
     self.assertEqual(
         stime.time(), 6.3,
         "expected time to be 6.3 after ticking with 6.3 increment")
Ejemplo n.º 8
0
 def test_tick_defaults_to_one_second(self):
     stime.reset()
     stime.tick()
     self.assertEqual(stime.time(), 1.0,
                      "expected time to be 1.0 after one tick")
Ejemplo n.º 9
0
 def test_reset_to_arbitrary_value(self):
     stime.reset(4.7)
     self.assertEqual(
         stime.time(), 4.7,
         "expected time to be 4.7 after being reset to that value")