From eb06a079832a84cc5ee0e5760c216442033c3339 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 21 Apr 2007 20:48:55 +0000 Subject: [PATCH] Updated tests to cope with new "--dry-run --gui" behaviour (before, --dry-run prevented the GUI from being run; now the GUI runs but the program it selects doesn't). Switched from using socketpair() to os.pipe(), since Python 2.3 doesn't have socketpair. git-svn-id: file:///home/talex/Backups/sf.net/Subversion/zero-install/trunk/0launch@1675 9f8c893c-44ee-0310-b757-c8ca8341c71e --- tests/basetest.py | 3 ++- tests/test-gui | 6 ++++++ tests/test-gui.xml | 11 +++++++++++ tests/testlaunch.py | 10 ++++------ zeroinstall/injector/cli.py | 21 ++++++++++++--------- 5 files changed, 35 insertions(+), 16 deletions(-) create mode 100755 tests/test-gui create mode 100644 tests/test-gui.xml diff --git a/tests/basetest.py b/tests/basetest.py index 266d5cf..53dd272 100755 --- a/tests/basetest.py +++ b/tests/basetest.py @@ -4,7 +4,7 @@ import unittest import logging sys.path.insert(0, '..') -from zeroinstall.injector import trust, basedir, autopolicy, namespaces, model, iface_cache, cli, download +from zeroinstall.injector import trust, basedir, autopolicy, namespaces, model, iface_cache, cli, download, writer from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False class BaseTest(unittest.TestCase): @@ -28,6 +28,7 @@ class BaseTest(unittest.TestCase): if os.environ.has_key('DISPLAY'): del os.environ['DISPLAY'] + namespaces.injector_gui_uri = os.path.join(os.path.dirname(__file__), 'test-gui.xml') logging.getLogger().setLevel(logging.WARN) diff --git a/tests/test-gui b/tests/test-gui new file mode 100755 index 0000000..5dc0486 --- /dev/null +++ b/tests/test-gui @@ -0,0 +1,6 @@ +#!/bin/sh +MYDIR=`dirname "$0"` +cat << EOF + + +EOF diff --git a/tests/test-gui.xml b/tests/test-gui.xml new file mode 100644 index 0000000..727a829 --- /dev/null +++ b/tests/test-gui.xml @@ -0,0 +1,11 @@ + + + ZeroInstall-Test-GUI + dummy GUI interface for testing + + Just for the unit tests! + + + + + diff --git a/tests/testlaunch.py b/tests/testlaunch.py index 3cdb92a..ed8c9e7 100755 --- a/tests/testlaunch.py +++ b/tests/testlaunch.py @@ -102,21 +102,19 @@ class TestLaunch(BaseTest): out, err = self.run_0launch(['--dry-run', 'http://foo']) # Uses local copy of GUI assert out.startswith("Would execute: ") - assert '0launch-gui' in out + assert 'basetest.py' in out self.assertEquals("", err) del os.environ['DISPLAY'] out, err = self.run_0launch(['--gui', '--dry-run']) - assert out.startswith("Would execute: ") - assert '0launch-gui' in out self.assertEquals("", err) + self.assertEquals("Finished\n", out) def testRefreshDisplay(self): os.environ['DISPLAY'] = ':foo' - out, err = self.run_0launch(['--dry-run', '--download-only', - '--refresh', 'http://foo']) + out, err = self.run_0launch(['--dry-run', '--refresh', 'http://foo']) assert out.startswith("Would execute: ") - assert '0launch-gui' in out + assert 'basetest.py' in out self.assertEquals("", err) def testNeedDownload(self): diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index e00fbe9..71a28d8 100755 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -236,39 +236,42 @@ def _fork_gui(iface_uri, gui_args): gui_sel = selections.Selections(gui_policy) from zeroinstall.injector import run - import socket - cli, gui = socket.socketpair() + cli, gui = os.pipe() # socket.socketpair() not in Python 2.3 :-( try: child = os.fork() if child == 0: # We are the child try: try: - cli.close() - os.dup2(gui.fileno(), 1) + os.close(cli) + os.dup2(gui, 1) run.execute_selections(gui_sel, gui_args + ['--', iface_uri]) except: import traceback - traceback.print_exc() + traceback.print_exc(file = sys.stderr) finally: + sys.stderr.flush() os._exit(1) - gui.close() + os.close(gui) gui = None + logging.info("Waiting for selections from GUI...") + xml = "" while True: - got = cli.recv(256) + got = os.read(cli, 256) if not got: break xml += got pid, status = os.waitpid(child, 0) assert pid == child if status == 1 << 8: + logging.info("User cancelled the GUI; aborting") return None # Aborted if status != 0: raise Exception("Error from GUI: code = %d" % status) finally: - if cli is not None: cli.close() - if gui is not None: gui.close() + if cli is not None: os.close(cli) + if gui is not None: os.close(gui) from StringIO import StringIO from zeroinstall.injector import qdom, selections -- 2.11.4.GIT