~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to tests/test_gtkwidgets.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
1
#!/usr/bin/python
 
2
# -*- coding: utf-8; -*-
2
3
 
 
4
import os
 
5
import sys
 
6
from test import test_support
3
7
import unittest
 
8
 
 
9
from gi.repository import Gtk, TimezoneMap
 
10
import mock
 
11
 
4
12
from ubiquity import segmented_bar, gtkwidgets
5
 
from test import test_support
6
 
from gi.repository import Gtk, GObject, TimezoneMap
7
 
import sys, os
8
 
import mock
 
13
 
 
14
 
 
15
class MockController(object):
 
16
    def get_string(self, name, lang=None, prefix=None):
 
17
        return "%s: %s" % (lang, name)
 
18
 
9
19
 
10
20
class WidgetTests(unittest.TestCase):
11
21
    def setUp(self):
34
44
        sb.remove_all()
35
45
        self.assertEqual(sb.segments, [])
36
46
        self.win.show_all()
37
 
        GObject.timeout_add(500, Gtk.main_quit)
38
 
        Gtk.main()
 
47
        gtkwidgets.refresh()
39
48
 
40
49
    def test_timezone_map(self):
41
50
        tzmap = TimezoneMap.TimezoneMap()
43
52
        #tzmap.select_city('America/New_York')
44
53
        self.win.show_all()
45
54
        self.win.connect('destroy', Gtk.main_quit)
46
 
        GObject.timeout_add(500, Gtk.main_quit)
47
 
        Gtk.main()
 
55
        gtkwidgets.refresh()
48
56
 
49
57
    @mock.patch('ubiquity.misc.drop_privileges')
50
58
    @mock.patch('ubiquity.misc.regain_privileges')
52
60
        from gi.repository import GdkPixbuf, Gst
53
61
        Gst.init(sys.argv)
54
62
        WRITE_TO = '/tmp/nonexistent-directory/windows_square.png'
55
 
        fs = gtkwidgets.FaceSelector()
 
63
        fs = gtkwidgets.FaceSelector(None)
56
64
        fs.selected_image = Gtk.Image()
57
 
        pb = GdkPixbuf.Pixbuf.new_from_file('pixmaps/windows_square.png')
 
65
        PATH = os.environ.get('UBIQUITY_PATH', False) or '/usr/share/ubiquity'
 
66
        png = os.path.join(PATH, 'pixmaps', 'windows_square.png')
 
67
        pb = GdkPixbuf.Pixbuf.new_from_file(png)
58
68
        fs.selected_image.set_from_pixbuf(pb)
59
69
        fs.save_to(WRITE_TO)
60
70
        self.assertTrue(os.path.exists(WRITE_TO))
61
71
        import shutil
62
72
        shutil.rmtree(os.path.dirname(WRITE_TO))
63
73
 
 
74
    def test_face_selector_translated(self):
 
75
        fs = gtkwidgets.FaceSelector(MockController())
 
76
        fs.translate('zz')
 
77
        self.assertEqual('zz: webcam_photo_label', fs.photo_label.get_text())
 
78
        self.assertEqual(
 
79
            'zz: webcam_existing_label', fs.existing_label.get_text())
 
80
        self.assertEqual(
 
81
            'zz: webcam_take_button',
 
82
            fs.webcam.get_property('take-button').get_label())
 
83
 
64
84
    def test_state_box(self):
65
85
        sb = gtkwidgets.StateBox('foobar')
66
86
        self.assertEqual(sb.get_property('label'), 'foobar')
109
129
        self.model = Gtk.TreeStore(str, object, object)
110
130
        self.manager = nm.NetworkManager(self.model)
111
131
 
112
 
    def test_get_vendor_and_model_null(self):
 
132
    @mock.patch('subprocess.Popen')
 
133
    def test_get_vendor_and_model_null(self, mock_subprocess):
 
134
        mock_subprocess.return_value.communicate.return_value = (
 
135
            '', 'device path not found\n')
113
136
        self.assertEqual(nm.get_vendor_and_model('bogus'), ('',''))
114
137
 
115
138
    @mock.patch('subprocess.Popen')
126
149
                dbus.Byte(114), dbus.Byte(115), dbus.Byte(101), dbus.Byte(97)]
127
150
        self.assertEqual(nm.decode_ssid(ssid), 'Ubuntu-Battersea')
128
151
 
 
152
    def test_decode_ssid_utf8(self):
 
153
        ssid = [dbus.Byte(82), dbus.Byte(195), dbus.Byte(169), dbus.Byte(115),
 
154
                dbus.Byte(101), dbus.Byte(97), dbus.Byte(117)]
 
155
        self.assertEqual(nm.decode_ssid(ssid), u'Réseau')
 
156
 
 
157
    def test_decode_ssid_latin1(self):
 
158
        ssid = [dbus.Byte(82), dbus.Byte(233), dbus.Byte(115), dbus.Byte(101),
 
159
                dbus.Byte(97), dbus.Byte(117)]
 
160
        self.assertEqual(nm.decode_ssid(ssid), u'R\ufffdseau')
 
161
 
129
162
    def test_ssid_in_model(self):
130
163
        iterator = self.model.append(None, ['/foo', 'Intel', 'Wireless'])
131
164
        for ssid in ('Orange', 'Apple', 'Grape'):