~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to tests/test_language.py

  • Committer: Colin Watson
  • Date: 2012-04-30 23:38:41 UTC
  • mfrom: (5402 trunk)
  • mto: This revision was merged to the branch mainline in revision 5403.
  • Revision ID: cjwatson@canonical.com-20120430233841-xb0qsk46lnhski7m
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf8; -*-
2
1
#!/usr/bin/python
 
2
# -*- coding: utf-8; -*-
3
3
 
 
4
import os
4
5
import unittest
 
6
from test.test_support import EnvironmentVarGuard
 
7
 
 
8
from gi.repository import Gtk
5
9
import mock
6
 
import sys, os
7
 
 
8
 
from ubiquity import i18n
9
 
from gi.repository import Gtk
10
 
 
11
 
os.environ['UBIQUITY_GLADE'] = 'gui/gtk'
 
10
 
 
11
from ubiquity import i18n, plugin_manager
12
12
 
13
13
def side_effect_factory(real_method):
14
14
    new_path = 'd-i/source/localechooser/debian/localechooser' \
20
20
            return real_method(path, *args, **kw)
21
21
    return side_effect
22
22
 
23
 
class LanguageTests(unittest.TestCase):
 
23
class OEMUserLanguageTests(unittest.TestCase):
24
24
    def setUp(self):
25
25
        for obj in ('ubiquity.misc.execute',
26
26
                'ubiquity.misc.execute_root'):
28
28
            patcher.start()
29
29
            self.addCleanup(patcher.stop)
30
30
 
31
 
        sys.path.insert(0, 'ubiquity/plugins')
32
 
        ubi_language = __import__('ubi-language')
33
 
        sys.path.pop()
 
31
        ubi_language = plugin_manager.load_plugin('ubi-language')
34
32
 
35
33
        controller = mock.Mock()
36
34
        controller.oem_user_config = True
42
40
        # I would love to test whether the actual allocations are all the
43
41
        # same height; however, GTK+3.0 does not allow access to the
44
42
        # GtkIconViewItem GList.
45
 
        real_method = open
46
 
        method = mock.patch('__builtin__.open')
47
 
        mocked_method = method.start()
48
 
        mocked_method.side_effect = side_effect_factory(real_method)
49
 
        self.addCleanup(method.stop)
 
43
        if 'UBIQUITY_TEST_INSTALLED' not in os.environ:
 
44
            real_method = open
 
45
            method = mock.patch('__builtin__.open')
 
46
            mocked_method = method.start()
 
47
            mocked_method.side_effect = side_effect_factory(real_method)
 
48
            self.addCleanup(method.stop)
50
49
 
51
50
        current_language, sorted_choices, language_display_map = \
52
51
            i18n.get_languages(0, False)
65
64
                longest_length = length
66
65
                longest = choice
67
66
        pad = self.gtk.iconview.get_property('item-padding')
68
 
        layout =  self.gtk.iconview.create_pango_layout(longest)
 
67
        layout = self.gtk.iconview.create_pango_layout(longest)
69
68
        self.assertEqual(layout.get_pixel_size()[0] + pad * 2, width)
 
69
 
 
70
 
 
71
class LanguageTests(unittest.TestCase):
 
72
    def setUp(self):
 
73
        
 
74
        for obj in ('ubiquity.misc.execute',
 
75
                'ubiquity.misc.execute_root'):
 
76
            patcher = mock.patch(obj)
 
77
            patcher.start()
 
78
            self.addCleanup(patcher.stop)
 
79
 
 
80
        ubi_language = plugin_manager.load_plugin('ubi-language')
 
81
 
 
82
        self.controller = mock.Mock()
 
83
        self.controller.oem_user_config = False
 
84
        self.controller.oem_config = False
 
85
        self.ubi_language = ubi_language
 
86
        # Set the environment variable needed in order for PageGtk to hook up
 
87
        # the Try Ubuntu button with the appropriate action.
 
88
        with EnvironmentVarGuard() as environ:
 
89
            environ['UBIQUITY_GREETER'] = '1'
 
90
            self.gtk = self.ubi_language.PageGtk(self.controller)
 
91
 
 
92
    def test_try_ubuntu_clicks(self):
 
93
        from ubiquity import gtkwidgets
 
94
        # Ensure that the mock changes state correctly.
 
95
        self.controller.allowed_change_step.return_value = True
 
96
        def side_effect(*args):
 
97
            assert len(args) == 1 and type(args[0]) is bool
 
98
            self.controller.allowed_change_step.return_value = args[0]
 
99
        self.controller.allow_change_step.side_effect = side_effect
 
100
        # Multiple clicks on Try Ubuntu crash the installer.  LP: #911907
 
101
        self.gtk.try_ubuntu.clicked()
 
102
        self.gtk.try_ubuntu.clicked()
 
103
        # Process the clicks.
 
104
        gtkwidgets.refresh()
 
105
        # When the Try Ubuntu button is clicked, the dbfilter's ok_handler()
 
106
        # methods should have been called only once.
 
107
        self.assertEqual(self.controller.dbfilter.ok_handler.call_count, 1)