summaryrefslogtreecommitdiffstats
path: root/test/test-gutil.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtest/test-gutil.py33
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()