uitests: Finish virtmanager.py coverage

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson
2020-08-29 12:37:52 -04:00
parent 687658832e
commit 87eb36dda1
4 changed files with 62 additions and 26 deletions
+27
View File
@@ -1,6 +1,8 @@
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import unittest.mock
from tests.uitests import utils as uiutils
@@ -122,3 +124,28 @@ class VMMCLI(uiutils.UITestCase):
# Give it a little time to work
uiutils.check(lambda: self.app.topwin.active)
self.app.topwin.keyCombo("<alt>F4")
def testCLINoFirstRun(self):
# Test a simple case of loading without any config override
self.app.open(first_run=False, use_uri=False)
self.sleep(2)
uiutils.check(lambda: self.app.topwin.showing)
def testCLINoFork(self):
# Test app without forking
self.app.open(first_run=False, use_uri=False, no_fork=False)
assert self.app.wait_for_exit() is True
uiutils.check(lambda: self.app.topwin.showing)
self.app.topwin.keyCombo("<alt>F4")
def testCLIGTKArgs(self):
# Ensure gtk arg passthrough works
self.app.open(extra_opts=["--gtk-debug=misc"])
uiutils.check(lambda: self.app.topwin.showing)
self.app.topwin.keyCombo("<alt>F4")
@unittest.mock.patch.dict('os.environ', {"DISPLAY": ""})
def testCLINoDisplay(self):
# Ensure missing display exits
self.app.open(will_fail=True)
self.app.wait_for_exit()
+3
View File
@@ -139,6 +139,9 @@ class VMMConnect(uiutils.UITestCase):
c.click()
# Delete it
c.click(button=3)
self.app.root.find("conn-disconnect", "menu item").click()
uiutils.check(lambda: "Not Connected" in c.text)
c.click(button=3)
self.app.root.find("conn-delete", "menu item").click()
self._click_alert_button("will remove the connection", "Yes")
uiutils.check(lambda: c.dead)
+23 -18
View File
@@ -542,10 +542,11 @@ class VMMDogtailApp(object):
def open(self, extra_opts=None, check_already_running=True, use_uri=True,
window_name=None, xmleditor_enabled=False, keyfile=None,
break_setfacl=False):
break_setfacl=False, first_run=True, no_fork=True,
will_fail=False):
extra_opts = extra_opts or []
if tests.utils.TESTCONFIG.debug:
if tests.utils.TESTCONFIG.debug and no_fork:
stdout = sys.stdout
stderr = sys.stderr
extra_opts.append("--debug")
@@ -554,9 +555,11 @@ class VMMDogtailApp(object):
stderr = open(os.devnull)
cmd = [sys.executable]
cmd += [os.path.join(os.getcwd(), "virt-manager"),
"--test-first-run",
"--no-fork"]
cmd += [os.path.join(os.getcwd(), "virt-manager")]
if no_fork:
cmd += ["--no-fork"]
if first_run:
cmd += ["--test-first-run"]
if use_uri:
cmd += ["--connect", self.uri]
@@ -581,8 +584,19 @@ class VMMDogtailApp(object):
if check_already_running:
self.error_if_already_running()
self._proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
self._root = dogtail.tree.root.application("virt-manager")
self._topwin = self._root.find(window_name, "(frame|dialog|alert)")
if not will_fail:
self._root = dogtail.tree.root.application("virt-manager")
self._topwin = self._root.find(window_name, "(frame|dialog|alert)")
def wait_for_exit(self):
# Wait for shutdown for 2 sec
waittime = 2
for ignore in range(int(waittime / .05)):
time.sleep(.05)
if self._proc.poll() is not None:
self._proc = None
return True
return False
def stop(self):
"""
@@ -598,18 +612,9 @@ class VMMDogtailApp(object):
self._proc = None
return
def _wait_for_exit():
# Wait for shutdown for 2 sec
waittime = 2
for ignore in range(int(waittime / .05)):
time.sleep(.05)
if self._proc.poll() is not None:
self._proc = None
return True
if _wait_for_exit():
if self.wait_for_exit():
return
log.warning("App didn't exit gracefully from SIGINT. Killing...")
self._proc.kill()
_wait_for_exit()
self.wait_for_exit()
+9 -8
View File
@@ -31,7 +31,7 @@ warnings.simplefilter("ignore")
try:
gi.check_version("3.22.0")
except (ValueError, AttributeError):
except (ValueError, AttributeError): # pragma: no cover
print("pygobject3 3.22.0 or later is required.")
sys.exit(1)
@@ -63,7 +63,7 @@ def _import_gtk(leftovers):
from gi.repository import Gtk
leftovers = sys.argv[1:]
if Gtk.check_version(3, 22, 0):
if Gtk.check_version(3, 22, 0): # pragma: no cover
print("gtk3 3.22.0 or later is required.")
sys.exit(1)
@@ -74,7 +74,7 @@ def _import_gtk(leftovers):
# This ensures we can init gsettings correctly
from . import config
ignore = config
except Exception as e:
except Exception as e: # pragma: no cover
# Don't just let the exception raise here. abrt reports bugs
# when users mess up su/sudo and DISPLAY isn't set. Printing
# it avoids the issue
@@ -111,7 +111,8 @@ def drop_tty():
# tty. This prevents libvirt's SSH tunnels from prompting
# for user input if SSH keys/agent aren't configured.
if os.fork() != 0:
os._exit(0) # pylint: disable=protected-access
# pylint: disable=protected-access
os._exit(0) # pragma: no cover
os.setsid()
@@ -121,7 +122,7 @@ def drop_stdio():
for fd in range(0, 2):
try:
os.close(fd)
except OSError:
except OSError: # pragma: no cover
pass
os.open(os.devnull, os.O_RDWR)
@@ -260,7 +261,7 @@ def main():
show_window = vmmEngine.CLI_SHOW_DOMAIN_DELETE
domain = options.show_domain_delete
if show_window and options.uri is None:
if show_window and options.uri is None: # pragma: no cover
raise RuntimeError("can't use --show-* options without --connect")
skip_autostart = False
@@ -288,9 +289,9 @@ def main():
def runcli():
try:
main()
except KeyboardInterrupt:
except KeyboardInterrupt: # pragma: no cover
log.debug("Received KeyboardInterrupt. Exiting application.")
except Exception as run_e:
if "Gtk" not in globals():
raise
raise # pragma: no cover
_show_startup_error(str(run_e), "".join(traceback.format_exc()))