Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: common/py_utils/py_utils/py_utils_unittest.py

Issue 2451553006: [Common] Move WaitFor from telemetry to common/py_utils (Closed)
Patch Set: nix logging Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/py_utils/py_utils/__init__.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/py_utils/py_utils/py_utils_unittest.py
diff --git a/common/py_utils/py_utils/py_utils_unittest.py b/common/py_utils/py_utils/py_utils_unittest.py
index e045bcab41dcbb98859d872511f5af1800c6bf0d..e614a4541c05f8007644333c9dc1824b51095e5f 100644
--- a/common/py_utils/py_utils/py_utils_unittest.py
+++ b/common/py_utils/py_utils/py_utils_unittest.py
@@ -21,3 +21,35 @@ class PathTest(unittest.TestCase):
def _GetFileInTestDir(file_name):
return os.path.join(os.path.dirname(__file__), 'test_data', file_name)
+
+
+class WaitForTest(unittest.TestCase):
+
+ def testWaitForTrue(self):
+ def ReturnTrue():
+ return True
+ self.assertTrue(py_utils.WaitFor(ReturnTrue, .1))
+
+ def testWaitForFalse(self):
+ def ReturnFalse():
+ return False
+
+ with self.assertRaises(py_utils.TimeoutException):
+ py_utils.WaitFor(ReturnFalse, .1)
+
+ def testWaitForEventuallyTrue(self):
+ # Use list to pass to inner function in order to allow modifying the
+ # variable from the outer scope.
+ c = [0]
+ def ReturnCounterBasedValue():
+ c[0] += 1
+ return c[0] > 2
+
+ self.assertTrue(py_utils.WaitFor(ReturnCounterBasedValue, .5))
+
+ def testWaitForTrueLambda(self):
+ self.assertTrue(py_utils.WaitFor(lambda: True, .1))
+
+ def testWaitForFalseLambda(self):
+ with self.assertRaises(py_utils.TimeoutException):
+ py_utils.WaitFor(lambda: False, .1)
« no previous file with comments | « common/py_utils/py_utils/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698