diff options
author | Benjamin Drung <bdrung@debian.org> | 2023-06-10 08:55:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-10 09:21:49 +0000 |
commit | 88837172f69eabc408ae3945d82e0270b8e07440 (patch) | |
tree | d6b7fa06694f45d25f54f6ea9ded93c981e51f6f /test/test-gtimer.py | |
parent | Initial commit. (diff) | |
download | nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.tar.xz nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.zip |
Adding upstream version 2.2.1.upstream/2.2.1
Signed-off-by: Benjamin Drung <bdrung@debian.org>
Diffstat (limited to 'test/test-gtimer.py')
-rwxr-xr-x | test/test-gtimer.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/test-gtimer.py b/test/test-gtimer.py new file mode 100755 index 0000000..8562049 --- /dev/null +++ b/test/test-gtimer.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +import unittest +from staslib import gutil + + +class Test(unittest.TestCase): + '''Unit tests for class GTimer''' + + def test_new_timer(self): + tmr = gutil.GTimer(interval_sec=5) + self.assertEqual(tmr.get_timeout(), 5) + self.assertEqual(tmr.time_remaining(), 0) + self.assertEqual(str(tmr), '5.0s [off]') + tmr.set_timeout(new_interval_sec=18) + self.assertEqual(tmr.get_timeout(), 18) + self.assertEqual(tmr.time_remaining(), 0) + + def test_callback(self): + tmr = gutil.GTimer(interval_sec=1, user_cback=lambda: "ok") + self.assertEqual(tmr._callback(), "ok") + tmr.set_callback(user_cback=lambda: "notok") + self.assertEqual(tmr._callback(), "notok") + tmr.kill() + self.assertEqual(tmr._user_cback, None) + self.assertRaises(TypeError, tmr._user_cback) + + def test_start_timer(self): + tmr = gutil.GTimer(interval_sec=1, user_cback=lambda: "ok") + self.assertEqual(str(tmr), '1.0s [off]') + tmr.start() + self.assertNotEqual(tmr.time_remaining(), 0) + self.assertNotEqual(str(tmr), '1.0s [off]') + + def test_clear(self): + tmr = gutil.GTimer(interval_sec=1, user_cback=lambda: "ok") + tmr.start() + tmr.clear() + self.assertEqual(tmr.time_remaining(), 0) + self.assertEqual(str(tmr), '1.0s [0s]') + + +if __name__ == '__main__': + unittest.main() |