1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Autopilot Functional Test Tool
4
# Copyright (C) 2014 Canonical
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.
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.
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/>.
20
from testtools import TestCase
21
from testtools.matchers import Equals
23
import autopilot.globals as _g
26
def restore_value(cleanup_enabled, object, attr_name):
27
"""Ensure that, at the end of the current test, object.attr_name is
28
restored to it's current state.
31
original_value = getattr(object, attr_name)
32
cleanup_enabled.addCleanup(
33
lambda: setattr(object, attr_name, original_value)
37
class DebugProfileFunctionTests(TestCase):
40
super(DebugProfileFunctionTests, self).setUp()
41
# since we're modifying a global in our tests, make sure we restore
42
# the original value after each test has run:
43
restore_value(self, _g, '_debug_profile_fixture')
45
def test_can_set_and_get_fixture(self):
46
fake_fixture = object()
47
_g.set_debug_profile_fixture(fake_fixture)
48
self.assertThat(_g.get_debug_profile_fixture(), Equals(fake_fixture))
51
class TimeoutFunctionTests(TestCase):
54
super(TimeoutFunctionTests, self).setUp()
55
# since we're modifying a global in our tests, make sure we restore
56
# the original value after each test has run:
57
restore_value(self, _g, '_default_timeout_value')
58
restore_value(self, _g, '_long_timeout_value')
60
def test_default_timeout_values(self):
61
self.assertEqual(10.0, _g.get_default_timeout_period())
62
self.assertEqual(30.0, _g.get_long_timeout_period())
64
def test_can_set_default_timeout_value(self):
65
new_value = self.getUniqueInteger()
66
_g.set_default_timeout_period(new_value)
67
self.assertEqual(new_value, _g.get_default_timeout_period())
69
def test_can_set_long_timeout_value(self):
70
new_value = self.getUniqueInteger()
71
_g.set_long_timeout_period(new_value)
72
self.assertEqual(new_value, _g.get_long_timeout_period())