Пример #1
0
    def test_timer_case2a(self,
                          zero_or_less_default_timeout_arg: IntFloat
                          ) -> None:
        """Test timer case2a.

        Args:
            zero_or_less_default_timeout_arg: pytest fixture for timeout
                                                seconds

        """
        print('mainline entered')
        timer = Timer(default_timeout=zero_or_less_default_timeout_arg)
        time.sleep(abs(zero_or_less_default_timeout_arg * 0.9))
        assert not timer.is_expired()
        time.sleep(abs(zero_or_less_default_timeout_arg))
        assert not timer.is_expired()
        print('mainline exiting')
Пример #2
0
    def test_timer_case3a(self,
                          greater_than_zero_default_timeout_arg: IntFloat
                          ) -> None:
        """Test timer case3a.

        Args:
            greater_than_zero_default_timeout_arg: pytest fixture for
                                                     timeout seconds

        """
        print('mainline entered')
        timer = Timer(default_timeout=greater_than_zero_default_timeout_arg)
        time.sleep(greater_than_zero_default_timeout_arg * 0.9)
        assert not timer.is_expired()
        time.sleep(greater_than_zero_default_timeout_arg)
        assert timer.is_expired()
        print('mainline exiting')
Пример #3
0
    def test_timer_remaining_time1(self,
                                   timeout_arg: IntFloat) -> None:
        """Test timer remaining time1.

        Args:
            timeout_arg: number of seconds to use for timer timeout arg

        """
        tolerance_factor = 0.80
        logger.debug('mainline entered')
        stop_watch = StopWatch()
        sleep_time = timeout_arg/3
        exp_remaining_time1: float = timeout_arg - sleep_time
        exp_remaining_time2: float = timeout_arg - sleep_time * 2
        exp_remaining_time3 = 0.0001

        timer = Timer(timeout=timeout_arg)
        stop_watch.start_clock(clock_iter=1)
        stop_watch.pause(sleep_time, clock_iter=1)

        rem_time = timer.remaining_time()
        assert ((exp_remaining_time1 * tolerance_factor)
                <= cast(float, rem_time)
                <= exp_remaining_time1)
        assert not timer.is_expired()
        logger.debug(f'after third 1: '
                     f'{exp_remaining_time1=}, {rem_time=}')

        stop_watch.pause(sleep_time * 2, clock_iter=1)

        rem_time = timer.remaining_time()
        assert ((exp_remaining_time2 * tolerance_factor)
                <= cast(float, rem_time)
                <= exp_remaining_time2)
        assert not timer.is_expired()
        logger.debug(f'after third 2: '
                     f'{exp_remaining_time2=}, {rem_time=}')

        time.sleep(sleep_time + 0.1)

        rem_time = timer.remaining_time()
        assert exp_remaining_time3 == cast(float, rem_time)
        assert timer.is_expired()

        logger.debug(f'after third 3: '
                     f'{exp_remaining_time3=}, {rem_time=}')

        logger.debug(f'{stop_watch.start_time=} '
                     f'{timer.start_time=}')

        logger.debug('mainline exiting')
Пример #4
0
    def test_timer_remaining_time_none(self) -> None:
        """Test timer remaining time none2."""
        logger.debug('mainline entered')

        timer = Timer(timeout=None)
        time.sleep(1)
        assert timer.remaining_time() is None
        assert not timer.is_expired()

        time.sleep(1)

        assert timer.remaining_time() is None
        assert not timer.is_expired()

        logger.debug('mainline exiting')
Пример #5
0
 def m1(self, sleep_time: float, timeout: float) -> bool:
     timer = Timer(timeout=timeout)
     time.sleep(sleep_time)
     if timer.is_expired():
         return False
     return True