mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-10-27 01:55:20 +03:00
uitests: Add check_in_loop helper function
This commit is contained in:
parent
3d9b3528e9
commit
cfd980611a
@ -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")
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user