1
# -*- coding: utf8; -*-
2
# -*- coding: utf-8; -*-
6
from test.test_support import EnvironmentVarGuard
8
from gi.repository import Gtk
8
from ubiquity import i18n
9
from gi.repository import Gtk
11
os.environ['UBIQUITY_GLADE'] = 'gui/gtk'
11
from ubiquity import i18n, plugin_manager
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)
23
class LanguageTests(unittest.TestCase):
23
class OEMUserLanguageTests(unittest.TestCase):
25
25
for obj in ('ubiquity.misc.execute',
26
26
'ubiquity.misc.execute_root'):
29
29
self.addCleanup(patcher.stop)
31
sys.path.insert(0, 'ubiquity/plugins')
32
ubi_language = __import__('ubi-language')
31
ubi_language = plugin_manager.load_plugin('ubi-language')
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.
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:
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)
51
50
current_language, sorted_choices, language_display_map = \
52
51
i18n.get_languages(0, False)
65
64
longest_length = length
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)
71
class LanguageTests(unittest.TestCase):
74
for obj in ('ubiquity.misc.execute',
75
'ubiquity.misc.execute_root'):
76
patcher = mock.patch(obj)
78
self.addCleanup(patcher.stop)
80
ubi_language = plugin_manager.load_plugin('ubi-language')
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)
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.
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)