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