added tests and descriptions
@@ -27,6 +27,7 @@ import tempfile
import time
import sys
import unittest
+import io
from opae.admin.utils.progress import progress
@@ -36,7 +37,13 @@ else:
temp_cfg = {}
class test_progress(unittest.TestCase):
+ TEST_SIZE = 4096*100
+
def test_notty(self):
+ """test_notty
+ Given the progress object time is set to a valid time and out stream
+ The tool runs successfully with output stream to stdout
+ """
with tempfile.NamedTemporaryFile(mode='w+',
**temp_cfg) as stream:
with progress(time=10, stream=stream) as prg:
@@ -47,8 +54,54 @@ class test_progress(unittest.TestCase):
print(stream.read())
def test_time0(self):
+ """test_time0
+ Given the progress object time is set to a valid time
+ The tool runs successfully with output stream to stdout
+ """
with progress(time=0) as prg:
for _ in range(10):
prg.tick()
time.sleep(0.1)
+ def test_noop(self):
+ """test_noop
+ Given the progress object null is set to True
+ The progress reporting tool becomes a 'noop' method
+ """
+ with progress(time=0, null=True) as prg:
+ for _ in range(10):
+ prg.tick()
+ time.sleep(0.1)
+
+ def test_stream_readonly(self):
+ """test_stream_readonly
+ Given the progress object with read-only stream
+ The tool prints Error but runs successfully and redirect stream to stdout
+ """
+ stream = io.IOBase()
+ with progress(time=10, stream=stream) as prg:
+ for _ in range(100):
+ prg.tick()
+ time.sleep(0.1)
+
+ def test_time_set_none(self):
+ """test_time_set_none
+ Given the progress object time is set to none
+ The tool fails with RunTimeError
+ """
+ with progress(time=None) as prg:
+ for _ in range(10):
+ with self.assertRaises(RuntimeError):
+ prg.tick()
+ time.sleep(0.1)
+
+ def test_bytes_set_none(self):
+ """test_bytes_set_none
+ Given the progress object bytes is set to none
+ The tool fails with RunTimeError
+ """
+ with progress(bytes=None) as prg:
+ for _ in range(10):
+ with self.assertRaises(RuntimeError):
+ prg.update(self.TEST_SIZE)
+ time.sleep(0.1)
