uitests: Add check_in_loop helper function

This commit is contained in:
Cole Robinson 2015-09-14 12:59:49 -04:00
parent 3d9b3528e9
commit cfd980611a
2 changed files with 18 additions and 8 deletions

View File

@ -143,10 +143,7 @@ class NewVM(unittest.TestCase):
version = uiutils.find_pattern(newvm, "install-os-version-label")
time.sleep(1)
while True:
if "Detecting" not in version.text:
break
time.sleep(.5)
uiutils.check_in_loop(lambda: "Detecting" not in version.text)
self.assertEquals(version.text, "Red Hat Enterprise Linux 5.5")
uiutils.find_fuzzy(newvm, "Forward", "button").click()
@ -157,10 +154,7 @@ class NewVM(unittest.TestCase):
progress = uiutils.find_fuzzy(self.app.root,
"Creating Virtual Machine", "frame")
while True:
if not progress.showing:
break
time.sleep(.5)
uiutils.check_in_loop(lambda: not progress.showing)
time.sleep(.5)
uiutils.find_fuzzy(self.app.root, "rhel5.5 on", "frame")

View File

@ -139,3 +139,19 @@ def print_nodes(root):
print "got exception: %s" % e
root.findChildren(_walk, isLambda=True)
def check_in_loop(func, timeout=-1):
"""
Run the passed func in a loop every .5 seconds until timeout is hit or
the func returns True.
If timeout=-1, check indefinitely.
"""
total_time = 0.0
while True:
time.sleep(.5)
total_time += .5
if func() is True:
return
if timeout > 0 and total_time >= timeout:
raise RuntimeError("Loop condition wasn't met")