Back to index

unity  6.0.0
__init__.py
Go to the documentation of this file.
00001 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
00002 # Copyright 2012 Canonical
00003 # Author: Thomi Richards
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License version 3, as published
00007 # by the Free Software Foundation.
00008 
00009 """Autopilot test case class for all Launcher tests"""
00010 
00011 from autopilot.emulators.X11 import ScreenGeometry
00012 from autopilot.testcase import multiply_scenarios
00013 
00014 from unity.tests import UnityTestCase
00015 
00016 
00017 def _make_scenarios():
00018     """Make scenarios for launcher test cases based on the number of configured
00019     monitors.
00020     """
00021     screen_geometry = ScreenGeometry()
00022     num_monitors = screen_geometry.get_num_monitors()
00023 
00024     # it doesn't make sense to set only_primary when we're running in a single-monitor setup.
00025     if num_monitors == 1:
00026         return [('Single Monitor', {'launcher_monitor': 0, 'only_primary': False})]
00027 
00028     monitor_scenarios = [('Monitor %d' % (i), {'launcher_monitor': i}) for i in range(num_monitors)]
00029     launcher_mode_scenarios = [('launcher_on_primary', {'only_primary': True}),
00030                                 ('launcher on all', {'only_primary': False})]
00031     return multiply_scenarios(monitor_scenarios, launcher_mode_scenarios)
00032 
00033 
00034 class LauncherTestCase(UnityTestCase):
00035     """A base class for all launcher tests that uses scenarios to run on
00036     each launcher (for multi-monitor setups).
00037     """
00038     scenarios = _make_scenarios()
00039 
00040     def setUp(self):
00041         super(LauncherTestCase, self).setUp()
00042         self.screen_geo = ScreenGeometry()
00043         self.set_unity_log_level("unity.launcher", "DEBUG")
00044         self.addCleanup(self.set_unity_log_level, "unity.launcher", "INFO")
00045 
00046         self.set_unity_option('num_launchers', int(self.only_primary))
00047         self.launcher_instance = self.get_launcher()
00048 
00049         if self.only_primary:
00050             try:
00051                 old_primary_screen = self.screen_geo.get_primary_monitor()
00052                 self.screen_geo.set_primary_monitor(self.launcher_monitor)
00053                 self.addCleanup(self.screen_geo.set_primary_monitor, old_primary_screen)
00054             except ScreenGeometry.BlacklistedDriverError:
00055                 self.skipTest("Impossible to set the monitor %d as primary" % self.launcher_monitor)
00056 
00057     def get_launcher(self):
00058         """Get the launcher for the current scenario."""
00059         return self.launcher.get_launcher_for_monitor(self.launcher_monitor)