File: test_cssproperties.py

package info (click to toggle)
python-css-parser 1.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: python: 20,584; sh: 11; makefile: 7
file content (66 lines) | stat: -rw-r--r-- 2,693 bytes parent folder | download | duplicates (3)
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
"""Testcases for css_parser.css.cssproperties."""

from __future__ import absolute_import
from __future__ import unicode_literals
import xml.dom
from . import basetest
import css_parser.css
import css_parser.profiles


class CSSPropertiesTestCase(basetest.BaseTestCase):

    #    def test_cssvalues(self):
    #        "cssproperties cssvalues"
    #        # does actually return match object, so a very simplified test...
    #        match = css_parser.css.cssproperties.cssvalues
    #
    #        self.assertEqual(True, bool(match['color']('red')))
    #        self.assertEqual(False, bool(match['top']('red')))
    #
    #        self.assertEqual(True, bool(match['left']('0')))
    #        self.assertEqual(True, bool(match['left']('1px')))
    #        self.assertEqual(True, bool(match['left']('.1px')))
    #        self.assertEqual(True, bool(match['left']('-1px')))
    #        self.assertEqual(True, bool(match['left']('-.1px')))
    #        self.assertEqual(True, bool(match['left']('-0.1px')))

    def test_toDOMname(self):
        "cssproperties _toDOMname(CSSname)"
        _toDOMname = css_parser.css.cssproperties._toDOMname

        self.assertEqual('color', _toDOMname('color'))
        self.assertEqual('fontStyle', _toDOMname('font-style'))
        self.assertEqual('MozOpacity', _toDOMname('-moz-opacity'))
        self.assertEqual('UNKNOWN', _toDOMname('UNKNOWN'))
        self.assertEqual('AnUNKNOWN', _toDOMname('-anUNKNOWN'))

    def test_toCSSname(self):
        "cssproperties _toCSSname(DOMname)"
        _toCSSname = css_parser.css.cssproperties._toCSSname

        self.assertEqual('color', _toCSSname('color'))
        self.assertEqual('font-style', _toCSSname('fontStyle'))
        self.assertEqual('-moz-opacity', _toCSSname('MozOpacity'))
        self.assertEqual('UNKNOWN', _toCSSname('UNKNOWN'))
        self.assertEqual('-anUNKNOWN', _toCSSname('AnUNKNOWN'))

    def test_CSS2Properties(self):
        "CSS2Properties"
        CSS2Properties = css_parser.css.cssproperties.CSS2Properties
        self.assertEqual(type(property()), type(CSS2Properties.color))
        self.assertEqual(sum([len(x) for x in css_parser.profiles.properties.values()]),
                         len(CSS2Properties._properties))

        c2 = CSS2Properties()
        # CSS2Properties has simplified implementation return always None
        self.assertEqual(None, c2.color)
        self.assertEqual(None, c2.__setattr__('color', 1))
        self.assertEqual(None, c2.__delattr__('color'))
        # only defined properties
        self.assertRaises(AttributeError, c2.__getattribute__, 'UNKNOWN')


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