diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-16 11:03:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-16 11:03:18 +0000 |
commit | 347467d3fa6fb239f917c05c4cf7f6c3fe7f9b30 (patch) | |
tree | 44ae9f59984c8a36b93f29a729f10473653f9f19 /test/test-gutil.py | |
parent | Adding upstream version 2.2.2. (diff) | |
download | nvme-stas-347467d3fa6fb239f917c05c4cf7f6c3fe7f9b30.tar.xz nvme-stas-347467d3fa6fb239f917c05c4cf7f6c3fe7f9b30.zip |
Adding upstream version 2.3~rc1.upstream/2.3_rc1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test-gutil.py')
-rwxr-xr-x | test/test-gutil.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/test-gutil.py b/test/test-gutil.py new file mode 100755 index 0000000..3039867 --- /dev/null +++ b/test/test-gutil.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 +import unittest +from staslib import gutil + + +class GutilUnitTest(unittest.TestCase): + '''Run unit test for gutil.py''' + + def _on_success(self, op_obj: gutil.AsyncTask, data): + op_obj.kill() + + def _on_fail(self, op_obj: gutil.AsyncTask, err, fail_cnt): + op_obj.kill() + + def _operation(self, data): + return data + + def test_AsyncTask(self): + op = gutil.AsyncTask(self._on_success, self._on_fail, self._operation, 'hello') + + self.assertIsInstance(str(op), str) + self.assertEqual(op.as_dict(), {'fail count': 0, 'completed': None, 'alive': True}) + + op.retry(10) + self.assertIsNotNone(op.as_dict().get('retry timer')) + + errmsg = 'something scarry happened' + op._errmsg = errmsg + self.assertEqual(op.as_dict().get('error'), errmsg) + + +if __name__ == '__main__': + unittest.main() |