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) 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 SettingsWizard tests."""
21 
22 import fixtures
23 import os
24 
25 from os.path import expanduser
26 
27 
28 class SettingsWizard(fixtures.Fixture):
29  WIZARD_FILE = expanduser("~") + \
30  '/.config/ubuntu-system-settings/wizard-has-run'
31 
32  def __init__(self, enable):
33  super().__init__()
34  self.enable = enable
35 
36  def setUp(self):
37  super().setUp()
38  original_state = self.is_settings_wizard_enabled()
39  self.addCleanup(self.set_settings_wizard, original_state)
40  if self.enable != original_state:
41  self.set_settings_wizard(self.enable)
42 
43  def is_settings_wizard_enabled(self):
44  return not os.path.exists(self.WIZARD_FILE)
45 
46  def set_settings_wizard(self, enabled):
47  if enabled:
48  self.enable_settings_wizard()
49  else:
50  self.disable_settings_wizard()
51 
52  def enable_settings_wizard(self):
53  if os.path.exists(self.WIZARD_FILE):
54  os.remove(self.WIZARD_FILE)
55 
56  def disable_settings_wizard(self):
57  if not os.path.exists(self.WIZARD_FILE):
58  open(self.WIZARD_FILE, 'a').close()