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-10-16 21:42:37 +0200 (Di, 16 Okt 2007) $'
     4  __version__ = '$LastChangedRevision: 489 $'
     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 -    def test_selectorText(self):
    41          "SelectorList.selectorText"
    42          s = SelectorList()
    43          s.selectorText = u'a, b'
    44          self.assertEqual(u'a, b', s.selectorText)
    45          self.assertRaises(xml.dom.SyntaxErr, s._setSelectorText, u',')
    46          # not changed as invalid!
    47          self.assertEqual(u'a, b', s.selectorText)
    48
    49          tests = {
    50              u'*': None,
    51              u'/*1*/*': None,
    52              u'/*1*/*, a': None,
    53              u'a, b': None,
    54              u'a ,b': u'a, b',
    55              u'a , b': u'a, b',
    56              u'a, b, c': u'a, b, c',
    57              u'#a, x#a, .b, x.b': u'#a, x#a, .b, x.b',
    58              }
    59          # do not parse as not complete
    60          self.do_equal_r(tests, att='selectorText')
    61
    62          tests = {
    63              u'': xml.dom.SyntaxErr,
    64              u' ': xml.dom.SyntaxErr,
    65              u',': xml.dom.SyntaxErr,
    66              u'a,': xml.dom.SyntaxErr,
    67              u',a': xml.dom.SyntaxErr,
    68              u'/* 1 */,a': xml.dom.SyntaxErr,
    69              }
    70          # only set as not complete
    71          self.do_raise_r(tests, att='_setSelectorText')
    72
    73
    74  if __name__ == '__main__':
    75      import unittest
    76      unittest.main()
    77