~savilerow-team/savilerow/fix_lp1279119

« back to all changes in this revision

Viewing changes to tests/tests/test_themes.py

  • Committer: Alex Chiang
  • Date: 2014-02-05 11:56:28 UTC
  • mfrom: (65.1.7 savvy)
  • Revision ID: achiang@canonical.com-20140205115628-r0jbn3oalud12oqq
doc: many improvements to individual test case documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import os
3
3
import subprocess
4
4
 
5
 
path = os.path.expanduser("~/.config/ubuntu-ui-toolkit/theme.ini")
 
5
#: Specify the name of a custom visual theme for Ubuntu UI
 
6
custom_theme = os.path.expanduser("~/.config/ubuntu-ui-toolkit/theme.ini")
 
7
#: Relative XDG path to location of custom theme files. This is an example only.
 
8
themedir = 'themes/Ubuntu/Custom'
6
9
themestring = "theme=themes.Ubuntu.Custom"
7
 
themedir = 'themes/Ubuntu/Custom'
8
 
data_dirs = subprocess.check_output(['initctl', 'get-env', 'XDG_DATA_DIRS']).split(':')
9
10
 
10
11
class ThemeCustomizationTests(AutopilotTestCase):
 
12
    """
 
13
    Downstreams may customize the visual color scheme of Ubuntu Touch,
 
14
    including the overall color palatte as well as individual UI widgets.
 
15
 
 
16
    The mechanism for doing so is two-fold:
 
17
 
 
18
      * create the elements of a new visual theme
 
19
      * configure the Unity shell to use the custom theme
 
20
    
 
21
    Downstreams *may* create new visual themes.
 
22
 
 
23
    If a new visual theme is created, downstreams *must* specify the new
 
24
    theme by modifying the contents of the theme.ini file.
 
25
    """
11
26
 
12
27
    def test_for_presence_of_theme_customization_file(self):
13
 
        """Check to see if the dconf file contains entry for disabled scopes"""
14
 
        dconffile = open(path, "r")
 
28
        """
 
29
        The presence of this file controls the visual theme of the Unity
 
30
        shell:
 
31
 
 
32
          ~/.config/ubuntu-ui-toolkit/theme.ini
 
33
 
 
34
        Downstreams *must* modify the contents of this file to point to
 
35
        the name of the new theme.
 
36
 
 
37
        Downstreams *must not* change the name of this file.
 
38
        """
 
39
        dconffile = open(custom_theme, "r")
15
40
        customk = dconffile.read()
16
41
        dconffile.close()
17
42
        if "%s" % (themestring) in customk.splitlines():
18
43
            self.assertTrue(True)
19
44
        else:
20
 
            print "Error reading theme.ini at %s" % (path)
 
45
            print "Error reading theme.ini at %s" % (custom_theme)
21
46
            self.assertTrue(False)
22
47
 
23
48
 
24
49
    def test_theme_dir_in_datadirs(self):
25
 
        '''Check to see if the themedir exists somewhere in XDG_DATA_DIRS'''
 
50
        """
 
51
        If a downstream creates a custom visual theme, the theme's files
 
52
        will be shipped in a subdirectory of:
 
53
 
 
54
          /custom/xdg/data
 
55
 
 
56
        This test verifies the custom visual theme files are present in
 
57
        the filesystem.
 
58
 
 
59
        Downstreams *must* modify the value of `themedir` to search for
 
60
        the specific subdirectory containing the custome theme files.
 
61
        """
26
62
        themedirfound = False
 
63
        data_dirs = subprocess.check_output(['initctl', 'get-env',
 
64
                                             'XDG_DATA_DIRS']).split(':')
27
65
        for dir in data_dirs:
28
 
            #initctl get-env adds a \n to the end of the output, we need to strip() it out
 
66
            # We use a relative path in `themedir` because we don't
 
67
            # necessarily know the full path to the custom XDG data
 
68
            # directory. Currently, the path is set to /custom/xdg/data
 
69
            # in ubuntu-touch-customization-hooks, but that could
 
70
            # theoretically change. So use the relative path, and glom
 
71
            # it together with every XDG_DATA_DIR path we discover in
 
72
            # the environment and test for its presence. Not spectacular
 
73
            # but it works.
 
74
            #
 
75
            # Note that initctl get-env adds a \n to the end of the
 
76
            # output so we need to strip() it out
29
77
            if os.path.isdir(os.path.join(dir.strip(), themedir)):
30
78
                themedirfound = True
31
79
        self.assertTrue(themedirfound)