~ubuntu-branches/ubuntu/utopic/ibus-cangjie/utopic-updates

« back to all changes in this revision

Viewing changes to tests/test_prefs.py

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2015-05-26 09:19:14 UTC
  • mfrom: (6.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20150526091914-bterkby7t7a62eux
Tags: 2.4-1~utopic1
Backporting wily release sync to utopic to fix multiple UX issues
as per upstream request (LP: #1452376)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import unittest
21
21
 
22
22
 
 
23
def has_graphical():
 
24
    """Detect if we have graphical capabilities
 
25
 
 
26
    It is very common to run the unit tests in an environment which does not
 
27
    have any graphical capabilities.
 
28
 
 
29
    This is for example the case in a CI server, or when building RPMs for
 
30
    Fedora.
 
31
 
 
32
    This function is useful to detect these situation, so that we can
 
33
    automatically skip the tests which can't run without.
 
34
    """
 
35
    try:
 
36
        from gi.repository import Gtk
 
37
 
 
38
    except RuntimeError as e:
 
39
        # On some platforms (e.g Ubuntu 12.04 where our CI is running) we
 
40
        # can't import Gtk without a display.
 
41
        return False
 
42
 
 
43
    # But other platforms (e.g Fedora 21) can import Gtk just fine even
 
44
    # without a display...
 
45
 
 
46
    from gi.repository import Gdk
 
47
 
 
48
    if Gdk.Display.get_default() is None:
 
49
        # ... We don't have a display
 
50
        return False
 
51
 
 
52
    return True
 
53
 
 
54
 
23
55
class PrefsTestCase(unittest.TestCase):
24
56
    def setUp(self):
25
57
        self.ui_file = os.path.join(os.environ["PREFERENCES_UI_DIR"],
37
69
        except ET.ParseError as e:
38
70
            raise AssertionError(e)
39
71
 
 
72
    @unittest.skipUnless(has_graphical(), "Can't use GtkBuilder")
40
73
    def test_ui_file_is_valid_gtk_builder(self):
41
 
        try:
42
 
            from gi.repository import Gtk
43
 
 
44
 
        except RuntimeError as e:
45
 
            # It seems on some platforms (notably, Ubuntu 12.04 where are CI
46
 
            # is running) we can't import Gtk without a display, but on others
47
 
            # (e.g Fedora 20) we can. There isn't much we can do except
48
 
            # skipping this test if importing Gtk fails, but the test is still
49
 
            # useful on those platforms where it works.
50
 
            self.skipTest("Could not import Gtk: %s" % e)
51
 
 
 
74
        from gi.repository import Gtk
52
75
        b = Gtk.Builder()
53
76
 
54
77
        try: