Package cssutils :: Package tests :: Module test_selectorlist |
[hide private]
[frames] | no frames]

# Source Code for Module cssutils.tests.test_selectorlist

     1  """Testcases for cssutils.css.selectorlist.SelectorList."""
     2  __author__ = '$LastChangedBy: doerwalter $'
     3  __date__ = '$LastChangedDate: 2007-08-07 11:24:45 +0200 (Di, 07 Aug 2007) $'
     4  __version__ = '0.9.2a1, $LastChangedRevision: 184 $'
     5
     6  import xml.dom
     7
     8  import basetest
     9
    10  from cssutils.css.selectorlist import SelectorList
    11
    12
    13 -class SelectorListTestCase(basetest.BaseTestCase):
    14
    15 -    def setUp(self):
    16          self.r = SelectorList()
    17
    18 -    def test_init(self):
    19          "SelectorList.__init__() and .length"
    20          s = SelectorList()
    21          self.assertEqual(0, s.length)
    22
    23          s = SelectorList('a, b')
    24          self.assertEqual(2, s.length)
    25          self.assertEqual(u'a, b', s.selectorText)
    26
    27          s = SelectorList(selectorText='a')
    28          self.assertEqual(1, s.length)
    29          self.assertEqual(u'a', s.selectorText)
    30
    31
    32 -    def test_appendSelector(self):
    33          "SelectorList.appendSelector() and .length"
    34          s = SelectorList()
    35          s.appendSelector('a')
    36          self.assertEqual(1, s.length)
    37
    38          self.assertRaises(xml.dom.InvalidModificationErr,
    39                            s.appendSelector, 'b,')
    40          self.assertEqual(1, s.length)
    41
    42          self.assertEqual(u'a', s.selectorText)
    43
    44
    45 -    def test_selectorText(self):
    46          "SelectorList.selectorText"
    47          s = SelectorList()
    48          s.selectorText = u'a, b'
    49          self.assertEqual(u'a, b', s.selectorText)
    50          self.assertRaises(xml.dom.SyntaxErr, s._setSelectorText, u',')
    51          # not changed as invalid!
    52          self.assertEqual(u'a, b', s.selectorText)
    53
    54          tests = {
    55              u'*': None,
    56              u'/*1*/ *': None,
    57              u'/*1*/ *, a': None,
    58              u'a, b': None,
    59              u'a ,b': u'a, b',
    60              u'a , b': u'a, b',
    61              u'a, b, c': u'a, b, c',
    62              u'#a, x#a, .b, x.b': u'#a, x#a, .b, x.b',
    63              }
    64          # do not parse as not complete
    65          self.do_equal_r(tests, att='selectorText')
    66
    67          tests = {
    68              u'': xml.dom.SyntaxErr,
    69              u' ': xml.dom.SyntaxErr,
    70              u',': xml.dom.SyntaxErr,
    71              u'a,': xml.dom.SyntaxErr,
    72              u',a': xml.dom.SyntaxErr,
    73              u'/* 1 */,a': xml.dom.SyntaxErr,
    74              }
    75          # only set as not complete
    76          self.do_raise_r(tests, att='_setSelectorText')
    77
    78
    79  if __name__ == '__main__':
    80      import unittest
    81      unittest.main()
    82