sh_cpl/unittests/unittests_reactive_extenstions/scheduler_test_case.py

36 lines
768 B
Python
Raw Normal View History

2023-04-16 21:46:17 +02:00
import time
import unittest
from datetime import datetime
from cpl_core.console import Console
from cpl_reactive_extensions.timer import Timer
class SchedulerTestCase(unittest.TestCase):
def setUp(self):
pass
def test_timer(self):
count = 0
def task():
nonlocal count
Console.write_line(datetime.now(), "Hello world")
count += 1
timer = Timer(100, task)
time.sleep(0.25)
self.assertEqual(count, 2)
timer.clear()
def test_schedule(self):
2023-04-16 22:01:15 +02:00
count = 0
def task():
nonlocal count
Console.write_line(datetime.now(), "Hello world")
count += 1
# async_scheduler.schedule(task, 100)
time.sleep(2)