~ubuntu-branches/ubuntu/utopic/autopilot-legacy/utopic-proposed

« back to all changes in this revision

Viewing changes to autopilot/tests/unit/test_globals.py

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-04-30 00:05:58 UTC
  • Revision ID: package-import@ubuntu.com-20140430000558-zmi37a3yf8podvwr
Tags: upstream-1.4.1+14.10.20140430
ImportĀ upstreamĀ versionĀ 1.4.1+14.10.20140430

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Autopilot Functional Test Tool
 
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
from testtools import TestCase
 
21
from testtools.matchers import Equals
 
22
 
 
23
import autopilot.globals as _g
 
24
 
 
25
 
 
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.
 
29
 
 
30
    """
 
31
    original_value = getattr(object, attr_name)
 
32
    cleanup_enabled.addCleanup(
 
33
        lambda: setattr(object, attr_name, original_value)
 
34
    )
 
35
 
 
36
 
 
37
class DebugProfileFunctionTests(TestCase):
 
38
 
 
39
    def setUp(self):
 
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')
 
44
 
 
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))
 
49
 
 
50
 
 
51
class TimeoutFunctionTests(TestCase):
 
52
 
 
53
    def setUp(self):
 
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')
 
59
 
 
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())
 
63
 
 
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())
 
68
 
 
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())