[gnome-settings-daemon] tests: Create a new gnome-session for each test



commit 1895ddf473ec260c3b87012adaa91903bb70c227
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jan 25 09:06:57 2013 +0100

    tests: Create a new gnome-session for each test
    
    Instead of re-using our current one. This will allow us testing
    cases where the session needs to exit.

 plugins/power/test.py |   33 +++++++++++++++++++++++++++++++--
 tests/gsdtestcase.py  |   32 --------------------------------
 2 files changed, 31 insertions(+), 34 deletions(-)
---
diff --git a/plugins/power/test.py b/plugins/power/test.py
index dbf7b9a..ee6079c 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -31,6 +31,26 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
     '''Test the power plugin'''
 
     def setUp(self):
+        self.session_log = open(os.path.join(self.workdir, 'gnome-session.log'), 'wb')
+        self.session = subprocess.Popen(['gnome-session', '-f',
+                                         '-a', os.path.join(self.workdir, 'autostart'),
+                                         '--session=dummy', '--debug'],
+                                        stdout=self.session_log,
+                                        stderr=subprocess.STDOUT)
+
+        # wait until the daemon is on the bus
+        try:
+            self.wait_for_bus_object('org.gnome.SessionManager',
+                                     '/org/gnome/SessionManager')
+        except:
+            # on failure, print log
+            with open(self.session_log.name) as f:
+                print('----- session log -----\n%s\n------' % f.read())
+            raise
+
+        self.obj_session_mgr = self.session_bus_con.get_object(
+            'org.gnome.SessionManager', '/org/gnome/SessionManager')
+
         # start mock upowerd
         (self.upowerd, self.obj_upower) = self.spawn_server_template(
             'upower', {'OnBattery': True, 'LidIsClosed': False}, stdout=subprocess.PIPE)
@@ -92,8 +112,7 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
             pass
 
     def tearDown(self):
-        # reactivate screen, in case tests triggered a display blank
-        self.reset_idle_timer()
+        self.stop_session()
 
         daemon_running = self.daemon.poll() == None
         self.daemon.terminate()
@@ -123,6 +142,16 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
         # we check this at the end so that the other cleanup always happens
         self.assertTrue(daemon_running, 'daemon died during the test')
 
+    def stop_session(self):
+        '''Stop GNOME session'''
+
+        assert self.session
+        self.session.terminate()
+        self.session.wait()
+
+        self.session_log.flush()
+        self.session_log.close()
+
     def get_status(self):
         return self.obj_session_presence_props.Get('org.gnome.SessionManager.Presence', 'status')
 
diff --git a/tests/gsdtestcase.py b/tests/gsdtestcase.py
index 0947805..df2159d 100644
--- a/tests/gsdtestcase.py
+++ b/tests/gsdtestcase.py
@@ -89,7 +89,6 @@ class GSDTestCase(dbusmock.DBusTestCase):
         klass.p_notify.terminate()
         klass.p_notify.wait()
         klass.stop_monitor()
-        klass.stop_session()
         dbusmock.DBusTestCase.tearDownClass()
         klass.stop_xorg()
         shutil.rmtree(klass.workdir)
@@ -128,37 +127,6 @@ class GSDTestCase(dbusmock.DBusTestCase):
             os.makedirs(d)
         shutil.copy(os.path.join(os.path.dirname(__file__), 'dummyapp.desktop'), d)
 
-        klass.session_log = open(os.path.join(klass.workdir, 'gnome-session.log'), 'wb')
-        klass.session = subprocess.Popen(['gnome-session', '-f',
-                                          '-a', os.path.join(klass.workdir, 'autostart'),
-                                          '--session=dummy', '--debug'],
-                                         stdout=klass.session_log,
-                                         stderr=subprocess.STDOUT)
-
-        # wait until the daemon is on the bus
-        try:
-            klass.wait_for_bus_object('org.gnome.SessionManager',
-                                      '/org/gnome/SessionManager')
-        except:
-            # on failure, print log
-            with open(klass.session_log.name) as f:
-                print('----- session log -----\n%s\n------' % f.read())
-            raise
-
-        klass.obj_session_mgr = klass.session_bus_con.get_object(
-            'org.gnome.SessionManager', '/org/gnome/SessionManager')
-
-    @classmethod
-    def stop_session(klass):
-        '''Stop GNOME session'''
-
-        assert klass.session
-        klass.session.terminate()
-        klass.session.wait()
-
-        klass.session_log.flush()
-        klass.session_log.close()
-
     @classmethod
     def start_monitor(klass):
         '''Start dbus-monitor'''



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]