Unity 8
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, 2015 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 """Set up and clean up fixtures for the Unity acceptance tests."""
21 
22 import os
23 import subprocess
24 import sysconfig
25 
26 import fixtures
27 
28 import unity8
29 
30 
31 class FakeScopes(fixtures.Fixture):
32 
33  def setUp(self):
34  super().setUp()
35  self.useFixture(
36  fixtures.EnvironmentVariable(
37  'QML2_IMPORT_PATH',
38  newvalue=self._get_fake_scopes_library_path()))
39 
40  def _get_fake_scopes_library_path(self):
42  mock_path = 'qml/scopefakes/'
43  else:
44  mock_path = os.path.join(
45  '../lib/', sysconfig.get_config_var('MULTIARCH'),
46  'unity8/qml/scopefakes/')
47  lib_path = unity8.get_lib_path()
48  ld_library_path = os.path.abspath(os.path.join(lib_path, mock_path))
49 
50  if not os.path.exists(ld_library_path):
51  raise RuntimeError(
52  'Expected library path does not exists: %s.' % (
53  ld_library_path))
54  return ld_library_path
55 
56 
57 class Tutorial(fixtures.Fixture):
58 
59  def __init__(self, enable):
60  super().__init__()
61  self.enable = enable
62 
63  def setUp(self):
64  super().setUp()
65  original_state = self._is_tutorial_enabled()
66  if self.enable != original_state:
67  self.addCleanup(self._set_tutorial, original_state)
68  self._set_tutorial(self.enable)
69 
70  def _is_tutorial_enabled(self):
71  command = [
72  'dbus-send', '--system', '--print-reply',
73  '--dest=org.freedesktop.Accounts',
74  '/org/freedesktop/Accounts/User32011',
75  'org.freedesktop.DBus.Properties.Get',
76  'string:com.canonical.unity.AccountsService',
77  'string:demo-edges'
78  ]
79  output = subprocess.check_output(command, universal_newlines=True)
80  return True if output.count('true') else False
81 
82  def _set_tutorial(self, value):
83  value_string = 'true' if value else 'false'
84  command = [
85  'dbus-send', '--system', '--print-reply',
86  '--dest=com.canonical.PropertyService',
87  '/com/canonical/PropertyService',
88  'com.canonical.PropertyService.SetProperty',
89  'string:edge', 'boolean:{}'.format(value_string)
90  ]
91  subprocess.check_output(command)
def running_installed_tests()
Definition: __init__.py:31
def get_lib_path()
Definition: __init__.py:36