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: cthedot $'
     3  __date__ = '$LastChangedDate: 2007-11-25 18:04:08 +0100 (So, 25 Nov 2007) $'
     4  __version__ = '$LastChangedRevision: 693 $'
     5
     6  import xml.dom
     7  import basetest
     8  from cssutils.css.selectorlist import SelectorList
     9
    10 -class SelectorListTestCase(basetest.BaseTestCase):
    11
    12 -    def setUp(self):
    13          self.r = SelectorList()
    14
    15 -    def test_init(self):
    16          "SelectorList.__init__() and .length"
    17          s = SelectorList()
    18          self.assertEqual(0, s.length)
    19
    20          s = SelectorList('a, b')
    21          self.assertEqual(2, s.length)
    22          self.assertEqual(u'a, b', s.selectorText)
    23
    24          s = SelectorList(selectorText='a')
    25          self.assertEqual(1, s.length)
    26          self.assertEqual(u'a', s.selectorText)
    27
    28 -    def test_appendSelector(self):
    29          "SelectorList.appendSelector() and .length"
    30          s = SelectorList()
    31          s.appendSelector('a')
    32          self.assertEqual(1, s.length)
    33
    34          self.assertRaises(xml.dom.InvalidModificationErr,
    35                            s.appendSelector, 'b,')
    36          self.assertEqual(1, s.length)
    37
    38          self.assertEqual(u'a', s.selectorText)
    39
    40          s.append('b')
    41          self.assertEqual(2, s.length)
    42          self.assertEqual(u'a, b', s.selectorText)
    43
    44          s.append('a')
    45          self.assertEqual(2, s.length)
    46          self.assertEqual(u'b, a', s.selectorText)
    47
    48          # __setitem__
    49          self.assertRaises(IndexError, s.__setitem__, 4, 'x')
    50          s[1] = 'c'
    51          self.assertEqual(2, s.length)
    52          self.assertEqual(u'b, c', s.selectorText)
    53          # TODO: remove duplicates?
    54  #        s[0] = 'c'
    55  #        self.assertEqual(1, s.length)
    56  #        self.assertEqual(u'c', s.selectorText)
    57
    58
    59
    60 -    def test_selectorText(self):
    61          "SelectorList.selectorText"
    62          s = SelectorList()
    63          s.selectorText = u'a, b'
    64          self.assertEqual(u'a, b', s.selectorText)
    65          self.assertRaises(xml.dom.SyntaxErr, s._setSelectorText, u',')
    66          # not changed as invalid!
    67          self.assertEqual(u'a, b', s.selectorText)
    68
    69          tests = {
    70              u'*': None,
    71              u'/*1*/*': None,
    72              u'/*1*/*, a': None,
    73              u'a, b': None,
    74              u'a ,b': u'a, b',
    75              u'a , b': u'a, b',
    76              u'a, b, c': u'a, b, c',
    77              u'#a, x#a, .b, x.b': u'#a, x#a, .b, x.b',
    78              }
    79          # do not parse as not complete
    80          self.do_equal_r(tests, att='selectorText')
    81
    82          tests = {
    83              u'': xml.dom.SyntaxErr,
    84              u' ': xml.dom.SyntaxErr,
    85              u',': xml.dom.SyntaxErr,
    86              u'a,': xml.dom.SyntaxErr,
    87              u',a': xml.dom.SyntaxErr,
    88              u'/* 1 */,a': xml.dom.SyntaxErr,
    89              }
    90          # only set as not complete
    91          self.do_raise_r(tests, att='_setSelectorText')
    92
    93
    94  if __name__ == '__main__':
    95      import unittest
    96      unittest.main()
    97