This file is indexed.

/usr/lib/python2.7/dist-packages/cssutils/tests/test_cssrule.py is in python-cssutils 1.0-4.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
"""Testcases for cssutils.css.CSSRule"""

import xml.dom
import basetest
import cssutils.css

class CSSRuleTestCase(basetest.BaseTestCase):
    """
    base class for all CSSRule subclass tests

    overwrite setUp with the appriopriate values, will be used in
    test_init and test_readonly
    overwrite all tests as you please, use::

        super(CLASSNAME, self).test_TESTNAME(params)

    to use the base class tests too
    """
    def setUp(self):
        """
        OVERWRITE!
        self.r is the rule
        self.rRO the readonly rule
        relf.r_type the type as defined in CSSRule
        """
        super(CSSRuleTestCase, self).setUp()
        
        self.sheet = cssutils.css.CSSStyleSheet()
        self.r = cssutils.css.CSSRule()
        self.rRO = cssutils.css.CSSRule()
        self.rRO._readonly = True # must be set here!
        self.r_type = cssutils.css.CSSRule.UNKNOWN_RULE
        self.r_typeString = 'UNKNOWN_RULE'

    def tearDown(self):
        cssutils.ser.prefs.useDefaults()
        
    def test_init(self):
        "CSSRule.type and init"
        self.assertEqual(self.r_type, self.r.type)
        self.assertEqual(self.r_typeString, self.r.typeString)
        self.assertEqual(u'', self.r.cssText)
        self.assertEqual(None, self.r.parentRule)
        self.assertEqual(None, self.r.parentStyleSheet)

    def test_parentRule_parentStyleSheet_type(self):
        "CSSRule.parentRule .parentStyleSheet .type"
        rules = [
             ('@charset "ascii";', cssutils.css.CSSRule.CHARSET_RULE),
             ('@import "x";', cssutils.css.CSSRule.IMPORT_RULE),
             ('@namespace "x";', cssutils.css.CSSRule.NAMESPACE_RULE),
             ('@font-face { src: url(x) }', cssutils.css.CSSRule.FONT_FACE_RULE),
             ('''@media all {
                    @x;
                    a { color: red }
                    /* c  */
                }''', cssutils.css.CSSRule.MEDIA_RULE),
             ('@page :left { color: red }', cssutils.css.CSSRule.PAGE_RULE),
             ('@unknown;', cssutils.css.CSSRule.UNKNOWN_RULE),
             ('b { left: 0 }', cssutils.css.CSSRule.STYLE_RULE),        
             ('/*1*/', cssutils.css.CSSRule.COMMENT) # must be last for add test
        ]
        mrt = [cssutils.css.CSSRule.UNKNOWN_RULE,  
               cssutils.css.CSSRule.STYLE_RULE,
               cssutils.css.CSSRule.COMMENT]
        def test(s):
            for i, rule in enumerate(s):                    
                self.assertEqual(rule.parentRule, None)
                self.assertEqual(rule.parentStyleSheet, s)
                #self.assertEqual(rule.type, rules[i][1])
                if rule.MEDIA_RULE == rule.type:
                    for j, r in enumerate(rule):
                        self.assertEqual(r.parentRule, rule)
                        self.assertEqual(r.parentStyleSheet, s)
                        self.assertEqual(r.type, mrt[j])

                if i == 0: # check encoding
                    self.assertEqual('ascii', s.encoding)
                elif i == 2: # check namespaces
                    self.assertEqual('x', s.namespaces[''])

        cssText = u''.join(r[0] for r in rules)
        # parsing               
        s = cssutils.parseString(cssText)
        test(s)
        # sheet.cssText
        s = cssutils.css.CSSStyleSheet()
        s.cssText = cssText
        test(s)
        # sheet.add CSS
        s = cssutils.css.CSSStyleSheet()
        for css, type_ in rules:
            s.add(css)
        test(s)
        # sheet.insertRule CSS
        s = cssutils.css.CSSStyleSheet()
        for css, type_ in rules:
            s.insertRule(css)
        test(s)
        
        types = [cssutils.css.CSSCharsetRule, 
                 cssutils.css.CSSImportRule,
                 cssutils.css.CSSNamespaceRule, 
                 cssutils.css.CSSFontFaceRule,
                 cssutils.css.CSSMediaRule, 
                 cssutils.css.CSSPageRule,
                 cssutils.css.CSSUnknownRule,
                 cssutils.css.CSSStyleRule, 
                 cssutils.css.CSSComment]
        # sheet.add CSSRule
        s = cssutils.css.CSSStyleSheet()
        for i, (css, type_) in enumerate(rules):
            rule = types[i]()
            rule.cssText = css
            s.add(rule)
        test(s)
        # sheet.insertRule CSSRule
        s = cssutils.css.CSSStyleSheet()
        for i, (css, type_) in enumerate(rules):
            rule = types[i]()
            rule.cssText = css
            s.insertRule(rule)
        test(s)

    def test_CSSMediaRule_cssRules_parentRule_parentStyleSheet_type(self):
        "CSSMediaRule.cssRules.parentRule .parentStyleSheet .type"
        rules = [
             ('b { left: 0 }', cssutils.css.CSSRule.STYLE_RULE),        
             ('/*1*/', cssutils.css.CSSRule.COMMENT),
             ('@x;', cssutils.css.CSSRule.UNKNOWN_RULE)
        ]
        def test(s):
            mr = s.cssRules[0]
            for i, rule in enumerate(mr):                    
                self.assertEqual(rule.parentRule, mr)
                self.assertEqual(rule.parentStyleSheet, s)
                self.assertEqual(rule.parentStyleSheet, mr.parentStyleSheet)
                self.assertEqual(rule.type, rules[i][1])

        cssText = '@media all { %s }' % u''.join(r[0] for r in rules)
        # parsing               
        s = cssutils.parseString(cssText)
        test(s)
        # sheet.cssText
        s = cssutils.css.CSSStyleSheet()
        s.cssText = cssText
        test(s)

        def getMediaSheet():
            s = cssutils.css.CSSStyleSheet()
            s.cssText = '@media all {}'
            return s, s.cssRules[0]
        # sheet.add CSS
        s, mr = getMediaSheet()
        for css, type_ in rules:
            mr.add(css)
        test(s)
        # sheet.insertRule CSS
        s, mr = getMediaSheet()
        for css, type_ in rules:
            mr.insertRule(css)
        test(s)
        
        types = [cssutils.css.CSSStyleRule, 
                 cssutils.css.CSSComment,
                 cssutils.css.CSSUnknownRule]
        # sheet.add CSSRule
        s, mr = getMediaSheet()
        for i, (css, type_) in enumerate(rules):
            rule = types[i]()
            rule.cssText = css
            mr.add(rule)
        test(s)
        # sheet.insertRule CSSRule
        s, mr = getMediaSheet()
        for i, (css, type_) in enumerate(rules):
            rule = types[i]()
            rule.cssText = css
            mr.insertRule(rule)
        test(s)

    def test_readonly(self):
        "CSSRule readonly"
        self.rRO = cssutils.css.CSSRule()
        self.rRO._readonly = True
        self.assertEqual(True, self.rRO._readonly)
        self.assertEqual(u'', self.rRO.cssText)
        self.assertRaises(xml.dom.NoModificationAllowedErr,
                          self.rRO._setCssText, u'x')
        self.assertEqual(u'', self.rRO.cssText)

    def _test_InvalidModificationErr(self, startwithspace):
        """
        CSSRule.cssText InvalidModificationErr

        called by subclasses

        startwithspace

        for test starting with this not the test but " test" is tested
        e.g. " @page {}"
        exception is the style rule test
        """
        tests = (u'',
                 u'/* comment */',
                 u'@charset "utf-8";',
                 u'@font-face {}',
                 u'@import url(x);',
                 u'@media all {}',
                 u'@namespace "x";'
                 u'@page {}',
                 u'@unknown;',
                 u'@variables;',
                 # TODO:
                 #u'@top-left {}'
                 u'a style rule {}'
                 )
        for test in tests:
            if startwithspace in (u'a style rule', ) and test in (
                u'/* comment */', u'a style rule {}'):
                continue

            if test.startswith(startwithspace):
                test = u' %s' % test

            self.assertRaises(xml.dom.InvalidModificationErr,
                 self.r._setCssText, test)

        # check that type is readonly
        self.assertRaises(AttributeError, self.r.__setattr__, 'parentRule', None)
        self.assertRaises(AttributeError, self.r.__setattr__, 'parentStyleSheet', None)
        self.assertRaises(AttributeError, self.r.__setattr__, 'type', 1)
        self.assertRaises(AttributeError, self.r.__setattr__, 'typeString', "")


if __name__ == '__main__':
    import unittest
    unittest.main()