コード例 #1
0
ファイル: test_Timer.py プロジェクト: rorygrandin/j5basic
 def test_args(self):
     """Test passing args"""
     tm = TimerDriver(expectarg=True)
     timer = Timer.Timer(tm.timefunc, args=(True, ))
     thread = threading.Thread(target=timer.start)
     thread.start()
     self.sleep(3)
     timer.stop = True
     assert tm.lasttime is not None
     self.finish_wait(thread, tm.errors)
コード例 #2
0
ファイル: test_Timer.py プロジェクト: rorygrandin/j5basic
 def test_short_run(self):
     """Test stopping immediately"""
     tm = TimerDriver(expectarg=True)
     timer = Timer.Timer(tm.timefunc,
                         kwargs={"testarg": True},
                         resolution=10)
     thread = threading.Thread(target=timer.start)
     thread.start()
     timer.stop = True
     assert tm.lasttime is None
     self.finish_wait(thread, tm.errors)
コード例 #3
0
ファイル: test_Timer.py プロジェクト: rorygrandin/j5basic
 def test_twosec(self):
     """Test a non one second resolution"""
     tm = TimerDriver(2)
     timer = Timer.Timer(tm.timefunc, resolution=2)
     thread = threading.Thread(target=timer.start)
     thread.start()
     self.sleep(5)
     timer.stop = True
     assert tm.lasttime is not None
     assert 2 <= tm.ticks <= 3
     self.finish_wait(thread, tm.errors)
コード例 #4
0
ファイル: test_Timer.py プロジェクト: rorygrandin/j5basic
 def test_missed(self):
     """Test missing time events by sleeping in the target function"""
     tm = TimerDriver(1)
     timer = Timer.Timer(tm.sleepfunc, args=(iter([0, 2, 3, 0, 6]), ))
     thread = threading.Thread(target=timer.start)
     thread.start()
     start_time = time.time()
     # make sure our sleep happens within the last 6-second pause
     self.sleep(12)
     print(time.time(), tm.lasttime)
     timer.stop = True
     assert tm.lasttime is not None
     assert 4 <= tm.ticks <= 5
     self.finish_wait(thread, tm.errors, 6)