~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to tests/test_gtkui.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
#!/usr/bin/python
1
2
# -*- coding: utf-8; -*-
2
 
#!/usr/bin/python
3
3
 
4
4
import os
5
 
os.environ['UBIQUITY_PLUGIN_PATH'] = 'ubiquity/plugins'
6
 
os.environ['UBIQUITY_GLADE'] = 'gui/gtk'
7
 
 
 
5
from test import test_support
8
6
import unittest
 
7
 
9
8
import mock
10
9
 
11
10
class TestFrontend(unittest.TestCase):
13
12
        for obj in ('ubiquity.misc.drop_privileges',
14
13
                    'ubiquity.misc.regain_privileges',
15
14
                    'ubiquity.misc.execute',
 
15
                    'ubiquity.misc.dmimodel',
16
16
                    'ubiquity.frontend.base.drop_privileges',
17
17
                    'ubiquity.frontend.gtk_ui.Wizard.customize_installer',
18
18
                    'ubiquity.nm.wireless_hardware_present',
19
19
                    'ubiquity.nm.NetworkManager.start',
20
20
                    'ubiquity.nm.NetworkManager.get_state',
21
 
                    'ubiquity.misc.add_connection_watch',
22
21
                    'ubiquity.misc.has_connection',
23
22
                    'ubiquity.upower.setup_power_watch',
24
 
                    'dbus.mainloop.glib.DBusGMainLoop'):
 
23
                    'dbus.mainloop.glib.DBusGMainLoop',
 
24
                    'gi.repository.UbiquityWebcam.Webcam.available',
 
25
                    'ubiquity.i18n.reset_locale',
 
26
                    ):
25
27
            patcher = mock.patch(obj)
26
 
            patcher.start()
 
28
            patched_obj = patcher.start()
27
29
            self.addCleanup(patcher.stop)
28
30
            if obj in ('ubiquity.misc.wireless_hardware_present',
29
31
                       'ubiquity.misc.has_connection'):
30
 
                patcher.return_value = False
 
32
                patched_obj.return_value = False
 
33
            elif obj == 'gi.repository.UbiquityWebcam.Webcam.available':
 
34
                patched_obj.return_value = True
 
35
            elif obj == 'ubiquity.i18n.reset_locale':
 
36
                patched_obj.return_value = 'en_US.UTF-8'
31
37
 
32
38
    def test_question_dialog(self):
33
39
        from ubiquity.frontend import gtk_ui
42
48
                                     options=(u'♥', u'£'))
43
49
            self.assertEqual(ret, u'♥')
44
50
 
 
51
    # TODO: I'm not entirely sure this makes sense, but the numbers are
 
52
    # currently rather unstable and seem to depend quite a lot on the theme.
 
53
    # This may have something to do with pixmaps not being set up properly
 
54
    # when testing against a build tree.
 
55
    @unittest.skipIf('UBIQUITY_TEST_INSTALLED' in os.environ,
 
56
                     'only testable against a build tree')
45
57
    def test_pages_fit_on_a_netbook(self):
46
 
        from gi.repository import Gtk, GObject
47
58
        from ubiquity.frontend import gtk_ui
48
 
        ui = gtk_ui.Wizard('test-ubiquity')
49
 
        ui.set_page(1)
50
 
        ui.translate_pages()
51
 
        GObject.timeout_add(250, Gtk.main_quit)
52
 
        Gtk.main()
53
 
        alloc = ui.live_installer.get_allocation()
54
 
        print alloc.height
55
 
        self.assertLessEqual(alloc.width, 640)
56
 
        self.assertLessEqual(alloc.height, 500)
 
59
        with test_support.EnvironmentVarGuard() as env:
 
60
            env['UBIQUITY_MIGRATION_ASSISTANT'] = '1'
 
61
            ui = gtk_ui.Wizard('test-ubiquity')
 
62
            ui.translate_pages()
 
63
            for page in ui.pages:
 
64
                ui.set_page(page.module.NAME)
 
65
                ui.refresh()
 
66
                ui.refresh()
 
67
                if 'UBIQUITY_TEST_SHOW_ALL_PAGES' in os.environ:
 
68
                    print(page.module.NAME)
 
69
                    import time
 
70
                    time.sleep(3)
 
71
                alloc = ui.live_installer.get_allocation()
 
72
                self.assertLessEqual(alloc.width, 640)
 
73
                self.assertLessEqual(alloc.height, 500)
 
74
                if page.module.NAME == 'partman':
 
75
                    ui.allow_change_step(False)
57
76
 
58
77
    def test_interface_translated(self):
59
78
        import subprocess
61
80
        from gi.repository import Gtk
62
81
        ui = gtk_ui.Wizard('test-ubiquity')
63
82
        missing_translations = []
64
 
        with mock.patch_object(ui, 'translate_widget') as translate_widget:
 
83
        with mock.patch.object(ui, 'translate_widget') as translate_widget:
65
84
            def side_effect(widget, lang=None, prefix=None):
66
85
                label  = isinstance(widget, Gtk.Label)
67
86
                button = isinstance(widget, Gtk.Button)