diff --git a/taskflow/tests/unit/test_types.py b/taskflow/tests/unit/test_types.py index 5e5b074d..e69cac0d 100644 --- a/taskflow/tests/unit/test_types.py +++ b/taskflow/tests/unit/test_types.py @@ -14,12 +14,14 @@ # License for the specific language governing permissions and limitations # under the License. +import time + import networkx as nx -from taskflow.types import graph -from taskflow.types import tree - from taskflow import test +from taskflow.types import graph +from taskflow.types import time as tt +from taskflow.types import tree class GraphTest(test.TestCase): @@ -113,3 +115,44 @@ class TreeTest(test.TestCase): things = list([n.item for n in root.dfs_iter(include_self=True)]) self.assertEqual(set(['animal', 'reptile', 'mammal', 'horse', 'primate', 'monkey', 'human']), set(things)) + + +class StopWatchUtilsTest(test.TestCase): + def test_no_states(self): + watch = tt.StopWatch() + self.assertRaises(RuntimeError, watch.stop) + self.assertRaises(RuntimeError, watch.resume) + + def test_expiry(self): + watch = tt.StopWatch(0.1) + watch.start() + time.sleep(0.2) + self.assertTrue(watch.expired()) + + def test_no_expiry(self): + watch = tt.StopWatch(0.1) + watch.start() + self.assertFalse(watch.expired()) + + def test_elapsed(self): + watch = tt.StopWatch() + watch.start() + time.sleep(0.2) + # NOTE(harlowja): Allow for a slight variation by using 0.19. + self.assertGreaterEqual(0.19, watch.elapsed()) + + def test_pause_resume(self): + watch = tt.StopWatch() + watch.start() + time.sleep(0.05) + watch.stop() + elapsed = watch.elapsed() + time.sleep(0.05) + self.assertAlmostEqual(elapsed, watch.elapsed()) + watch.resume() + self.assertNotEqual(elapsed, watch.elapsed()) + + def test_context_manager(self): + with tt.StopWatch() as watch: + time.sleep(0.05) + self.assertGreater(0.01, watch.elapsed()) diff --git a/taskflow/tests/unit/test_utils.py b/taskflow/tests/unit/test_utils.py index 2c2dac2d..22da1b8b 100644 --- a/taskflow/tests/unit/test_utils.py +++ b/taskflow/tests/unit/test_utils.py @@ -18,12 +18,10 @@ import collections import functools import inspect import sys -import time from taskflow import states from taskflow import test from taskflow.tests import utils as test_utils -from taskflow.types import time as tt from taskflow.utils import lock_utils from taskflow.utils import misc from taskflow.utils import reflection @@ -495,47 +493,6 @@ class IsValidAttributeNameTestCase(test.TestCase): self.assertFalse(misc.is_valid_attribute_name('maƱana')) -class StopWatchUtilsTest(test.TestCase): - def test_no_states(self): - watch = tt.StopWatch() - self.assertRaises(RuntimeError, watch.stop) - self.assertRaises(RuntimeError, watch.resume) - - def test_expiry(self): - watch = tt.StopWatch(0.1) - watch.start() - time.sleep(0.2) - self.assertTrue(watch.expired()) - - def test_no_expiry(self): - watch = tt.StopWatch(0.1) - watch.start() - self.assertFalse(watch.expired()) - - def test_elapsed(self): - watch = tt.StopWatch() - watch.start() - time.sleep(0.2) - # NOTE(harlowja): Allow for a slight variation by using 0.19. - self.assertGreaterEqual(0.19, watch.elapsed()) - - def test_pause_resume(self): - watch = tt.StopWatch() - watch.start() - time.sleep(0.05) - watch.stop() - elapsed = watch.elapsed() - time.sleep(0.05) - self.assertAlmostEqual(elapsed, watch.elapsed()) - watch.resume() - self.assertNotEqual(elapsed, watch.elapsed()) - - def test_context_manager(self): - with tt.StopWatch() as watch: - time.sleep(0.05) - self.assertGreater(0.01, watch.elapsed()) - - class UriParseTest(test.TestCase): def test_parse(self): url = "zookeeper://192.168.0.1:2181/a/b/?c=d"