2018-09-21 13:30:41 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""!
|
|
|
|
|
____ ____ ______ __ __ __ _____
|
|
|
|
|
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
|
|
|
|
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
|
|
|
|
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
|
|
|
|
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
|
|
|
|
German BOS Information Script
|
|
|
|
|
by Bastian Schroll
|
|
|
|
|
|
|
|
|
|
@file: test_timer.py
|
|
|
|
|
@date: 21.09.2019
|
|
|
|
|
@author: Bastian Schroll
|
|
|
|
|
@description: Unittests for BOSWatch. File must be _run as "pytest" unittest
|
|
|
|
|
"""
|
|
|
|
|
import logging
|
|
|
|
|
import time
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from boswatch.utils.timer import RepeatedTimer
|
|
|
|
|
|
2018-09-21 14:21:33 +02:00
|
|
|
# todo add more tests to overlap all testcases
|
2018-09-21 13:30:41 +02:00
|
|
|
|
|
|
|
|
class Test_Timer:
|
|
|
|
|
"""!Unittest for the timer class"""
|
|
|
|
|
|
|
|
|
|
def setup_method(self, method):
|
|
|
|
|
logging.debug("[TEST] %s.%s", type(self).__name__, method.__name__)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
2018-09-21 14:21:33 +02:00
|
|
|
def testTargetFast():
|
|
|
|
|
logging.debug("run testTargetFast")
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def testTargetSlow():
|
|
|
|
|
logging.debug("run testTargetSlow start")
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
logging.debug("run testTargetSlow end")
|
2018-09-21 13:30:41 +02:00
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
|
def useTimer(self):
|
|
|
|
|
"""!Server a RepeatedTimer instance"""
|
2018-09-21 14:21:33 +02:00
|
|
|
self.testTimer = RepeatedTimer(0.5, Test_Timer.testTargetFast)
|
2018-09-21 13:30:41 +02:00
|
|
|
time.sleep(0.1)
|
2018-09-21 14:21:33 +02:00
|
|
|
yield 1 # server the timer instance
|
2018-09-21 13:30:41 +02:00
|
|
|
|
|
|
|
|
def test_timerStartStop(self, useTimer):
|
|
|
|
|
assert self.testTimer.start()
|
|
|
|
|
assert self.testTimer.stop()
|
|
|
|
|
|
|
|
|
|
def test_timerStopNotStarted(self, useTimer):
|
|
|
|
|
assert not self.testTimer.stop()
|
|
|
|
|
|
|
|
|
|
def test_timerRun(self, useTimer):
|
|
|
|
|
assert self.testTimer.start()
|
|
|
|
|
time.sleep(0.6)
|
|
|
|
|
assert self.testTimer.stop()
|