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

Source Code for Module cssutils.tests.test_selector

  1  """Testcases for cssutils.css.selector.Selector.""" 
  2  __author__ = '$LastChangedBy: doerwalter $' 
  3  __date__ = '$LastChangedDate: 2007-08-02 22:58:23 +0200 (Do, 02 Aug 2007) $' 
  4  __version__ = '0.9.2b3, $LastChangedRevision: 160 $' 
  5   
  6  import xml.dom 
  7   
  8  import basetest 
  9   
 10  from cssutils.css.selector import Selector 
 11   
 12   
13 -class SelectorTestCase(basetest.BaseTestCase):
14
15 - def setUp(self):
16 self.r = Selector('*')
17
18 - def test_init(self):
19 "Selector.__init__()" 20 s = Selector('*')
21
22 - def test_selectorText(self):
23 "Selector.selectorText" 24 tests = { 25 u'''*''': None, 26 u'''*/*x*/''': None, 27 u'''* /*x*/''': None, 28 u'''*:hover''': None, 29 u'''* :hover''': None, 30 u'''*:lang(fr)''': None, 31 u'''* :lang(fr)''': None, 32 u'''*::first-line''': None, 33 u'''* ::first-line''': None, 34 u'''*[lang=fr]''': None, 35 u'''[lang=fr]''': None, 36 37 u'''a''': None, 38 u'''h1''': None, 39 u'''.a a''': None, 40 41 u'''a1''': None, 42 u'''a1-1''': None, 43 u'''.a1-1''': None, 44 u'''.a1._1''': None, 45 46 u'''[x]''': None, 47 u'''*[x]''': None, 48 u'''a[x]''': None, 49 u'''a[ x]''': 'a[x]', 50 u'''a[x ]''': 'a[x]', 51 u'''a [x]''': 'a [x]', 52 u'''* [x]''': None, # is really * *[x] 53 54 u'''a[x="1"]''': None, 55 u'''a[x ="1"]''': 'a[x="1"]', 56 u'''a[x= "1"]''': 'a[x="1"]', 57 u'''a[x = "1"]''': 'a[x="1"]', 58 u'''a[ x = "1"]''': 'a[x="1"]', 59 u'''a[x = "1" ]''': 'a[x="1"]', 60 u'''a[ x = "1" ]''': 'a[x="1"]', 61 u'''a [ x = "1" ]''': 'a [x="1"]', 62 63 u'''a[x~=a1]''': None, 64 u'''a[x ~=a1]''': 'a[x~=a1]', 65 u'''a[x~= a1]''': 'a[x~=a1]', 66 u'''a[x ~= a1]''': 'a[x~=a1]', 67 u'''a[ x ~= a1]''': 'a[x~=a1]', 68 u'''a[x ~= a1 ]''': 'a[x~=a1]', 69 u'''a[ x ~= a1 ]''': 'a[x~=a1]', 70 u'''a [ x ~= a1 ]''': 'a [x~=a1]', # same as next! 71 u'''a *[ x ~= a1 ]''': 'a *[x~=a1]', 72 73 u'''a[x|=en]''': None, 74 u'''a[x|= en]''': 'a[x|=en]', 75 u'''a[x |=en]''': 'a[x|=en]', 76 u'''a[x |= en]''': 'a[x|=en]', 77 u'''a[ x |= en]''': 'a[x|=en]', 78 u'''a[x |= en ]''': 'a[x|=en]', 79 u'''a[ x |= en]''': 'a[x|=en]', 80 u'''a [ x |= en]''': 'a [x|=en]', 81 # CSS3 82 u'''a[x^=en]''': None, 83 u'''a[x$=en]''': None, 84 u'''a[x*=en]''': None, 85 86 u'''a[/*1*/x/*2*/]''': None, 87 u'''a[/*1*/x/*2*/=/*3*/a/*4*/]''': None, 88 u'''a[/*1*/x/*2*/~=/*3*/a/*4*/]''': None, 89 u'''a[/*1*/x/*2*/|=/*3*/a/*4*/]''': None, 90 91 u'''a b''': None, 92 u'''a b''': 'a b', 93 u'''a #b''': 'a #b', 94 u'''a .b''': 'a .b', 95 u'''ab''': 'ab', 96 u'''a.b''': None, 97 u'''a.b.c''': None, 98 99 u'''#a''': None, 100 u'''#a1''': None, 101 u'''#1a''': None, # valid to grammar but not for HTML 102 u'''#1''': None, # valid to grammar but not for HTML 103 u'''a#b''': None, 104 u'''a #b''': None, 105 106 u'''a>b''': None, 107 u'''a> b''': 'a>b', 108 u'''a >b''': 'a>b', 109 u'''a > b''': 'a>b', 110 # CSS2 combinator + 111 u'''a+b''': None, 112 u'''a+ b''': 'a+b', 113 u'''a +b''': 'a+b', 114 u'''a + b''': 'a+b', 115 # CSS3 combinator ~ 116 u'''a~b''': None, 117 u'''a~ b''': 'a~b', 118 u'''a ~b''': 'a~b', 119 u'''a ~ b''': 'a~b', 120 121 u'''a+ b c''': 'a+b c', 122 # namespaces 123 u'''|e''': None, 124 u'''*|e''': None, 125 u'''n|e''': None, 126 u'''n|*''': None, 127 u'''*|b[x|a]''': None, 128 129 u'''x:lang() y''': None, 130 u'''x:nth-child(odd) y''': None, 131 } 132 # do not parse as not complete 133 self.do_equal_r(tests, att='selectorText') 134 135 tests = { 136 u'': xml.dom.SyntaxErr, 137 u'1': xml.dom.SyntaxErr, 138 139 u'#': xml.dom.SyntaxErr, 140 u'|': xml.dom.SyntaxErr, 141 142 u':': xml.dom.SyntaxErr, 143 u'::': xml.dom.SyntaxErr, 144 u': a': xml.dom.SyntaxErr, 145 u':: a': xml.dom.SyntaxErr, 146 u'::a()': xml.dom.SyntaxErr, # pseudoelement only 147 u':::a': xml.dom.SyntaxErr, 148 u':1': xml.dom.SyntaxErr, 149 150 u'#.x': xml.dom.SyntaxErr, 151 u'.': xml.dom.SyntaxErr, 152 u'.1': xml.dom.SyntaxErr, 153 u'.a.1': xml.dom.SyntaxErr, 154 155 u'[a': xml.dom.SyntaxErr, 156 u'a]': xml.dom.SyntaxErr, 157 u'[a b]': xml.dom.SyntaxErr, 158 u'[=b]': xml.dom.SyntaxErr, 159 u'[a=]': xml.dom.SyntaxErr, 160 u'[a|=]': xml.dom.SyntaxErr, 161 u'[a~=]': xml.dom.SyntaxErr, 162 u'[a=1]': xml.dom.SyntaxErr, 163 164 u'a +': xml.dom.SyntaxErr, 165 u'a >': xml.dom.SyntaxErr, 166 u'a ++ b': xml.dom.SyntaxErr, 167 u'a + > b': xml.dom.SyntaxErr, 168 169 170 u'*:lang(': xml.dom.SyntaxErr, 171 172 # only one selector! 173 u',': xml.dom.InvalidModificationErr, 174 u',a': xml.dom.InvalidModificationErr, 175 u'a,': xml.dom.InvalidModificationErr, 176 } 177 # only set as not complete 178 self.do_raise_r(tests, att='_setSelectorText')
179 180 181 if __name__ == '__main__': 182 import unittest 183 unittest.main() 184