Unity 8
 All Classes Functions
fixture_setup.py
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Unity Autopilot Test Suite
4 # Copyright (C) 2014 Canonical
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 
20 import fixtures
21 from autopilot import introspection
22 
23 from unity8 import process_helpers
24 from unity8.shell import emulators
25 
26 
27 class LaunchDashApp(fixtures.Fixture):
28 
29  """Fixture to launch the Dash app."""
30 
31  def __init__(self, binary_path, variables):
32  """Initialize an instance.
33 
34  :param str binary_path: The path to the Dash app binary.
35  :param variables: The variables to use when launching the app.
36  :type variables: A dictionary.
37 
38  """
39  super(LaunchDashApp, self).__init__()
40  self.binary_path = binary_path
41  self.variables = variables
42 
43  def setUp(self):
44  """Launch the dash app when the fixture is used."""
45  super(LaunchDashApp, self).setUp()
46  self.addCleanup(self.stop_application)
48 
49  def launch_application(self):
50  binary_arg = 'BINARY={}'.format(self.binary_path)
51  testability_arg = 'QT_LOAD_TESTABILITY={}'.format(1)
52  env_args = [
53  '{}={}'.format(key, value) for key, value in self.variables.items()
54  ]
55  all_args = [binary_arg, testability_arg] + env_args
56 
57  pid = process_helpers.start_job('unity8-dash', *all_args)
58  return introspection.get_proxy_object_for_existing_process(
59  pid=pid,
60  emulator_base=emulators.UnityEmulatorBase,
61  )
62 
63  def stop_application(self):
64  process_helpers.stop_job('unity8-dash')