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

# Source Code for Module cssutils.tests.test_cssvalue

      1  """Testcases for cssutils.css.CSSValue and CSSPrimitiveValue."""
      2  __author__ = '$LastChangedBy: cthedot $'
      3  __date__ = '$LastChangedDate: 2007-09-02 11:49:40 +0200 (So, 02 Sep 2007) $'
      4  __version__ = '$LastChangedRevision: 312 $'
      5
      6  # from decimal import Decimal # maybe for later tests?
      7  import xml.dom
      8  import basetest
      9  import cssutils
     10  import types
     11
     12 -class CSSValueTestCase(basetest.BaseTestCase):
     13
     14 -    def test_init(self):
     15          "CSSValue.__init__()"
     16          v = cssutils.css.CSSValue()
     17          self.assert_(u'' == v.cssText)
     18          self.assert_(None is  v.cssValueType)
     19          self.assert_(None == v.cssValueTypeString)
     20
     21 -    def test_cssText(self):
     22          "CSSValue.cssText"
     23          v = cssutils.css.CSSValue()
     24          v.cssText = u'1px'
     25          self.assert_(v.CSS_PRIMITIVE_VALUE == v.cssValueType)
     26          self.assert_(v.CSS_PX == v.primitiveType)
     27          self.assert_(u'1px' == v.cssText)
     28          self.assert_(False is v.valid)
     29
     30          v = cssutils.css.CSSValue(_propertyName="left")
     31          v.cssText = u'1px'
     32          self.assert_(v.CSS_PRIMITIVE_VALUE == v.cssValueType)
     33          self.assert_(v.CSS_PX == v.primitiveType)
     34          self.assert_(u'1px' == v.cssText)
     35          self.assert_(True is v.valid)
     36
     37          v = cssutils.css.CSSValue(_propertyName="font-family")
     38          v.cssText = u'a  ,b,  c  ,"d or d", "e, " '
     39          self.assertEqual(v.CSS_PRIMITIVE_VALUE, v.cssValueType)
     40          self.assertEqual(v.CSS_STRING, v.primitiveType)
     41          self.assertEqual(u'a, b, c, "d or d", "e, "', v.cssText)
     42          self.assert_(True is v.valid)
     43
     44          v.cssText = u'  1   px    '
     45          self.assert_(v.CSS_VALUE_LIST == v.cssValueType)
     46          self.assert_('1 px' == v._value)
     47          self.assert_('1 px' == v.cssText)
     48          self.assert_(False is v.valid)
     49
     50          v.cssText = u'  normal 1px a, b, "c" end   '
     51          self.assert_(v.CSS_VALUE_LIST == v.cssValueType)
     52          self.assert_('normal 1px a, b, "c" end' == v._value)
     53          self.assert_('normal 1px a, b, "c" end' == v.cssText)
     54          self.assert_(False is v.valid)
     55          for i, x in enumerate(v):
     56              self.assertEqual(x.CSS_PRIMITIVE_VALUE, x.cssValueType)
     57              if x == 0:
     58                  self.assertEqual(x.CSS_IDENT, x.primitiveType)
     59                  self.assertEqual(u'normal', x.cssText)
     60              elif x == 1:
     61                  self.assertEqual(x.CSS_PX, x.primitiveType)
     62                  self.assertEqual(u'1px', x.cssText)
     63              if x == 2:
     64                  self.assertEqual(x.CSS_STRING, x.primitiveType)
     65                  self.assertEqual(u'a, b, "c"', x.cssText)
     66              if x == 3:
     67                  self.assertEqual(x.CSS_IDENT, x.primitiveType)
     68                  self.assertEqual(u'end', x.cssText)
     69
     70
     71          v = cssutils.css.CSSValue(_propertyName="left")
     72          v.cssText = u'  1   px    '
     73          self.assert_(v.CSS_VALUE_LIST == v.cssValueType)
     74          self.assert_(u'1 px' == v.cssText)
     75          self.assert_(False is v.valid)
     76
     77          v.cssText = u'expression(document.body.clientWidth > 972 ? "1014px": "100%" )'
     78          self.assert_(v.CSS_PRIMITIVE_VALUE == v.cssValueType)
     79          self.assert_(v.CSS_UNKNOWN == v.primitiveType)
     80          self.assertEqual('expression(document.body.clientWidth > 972 ? "1014px": "100%" )',
     81                           v._value)
     82          self.assert_('expression(document.body.clientWidth > 972 ? "1014px": "100%" )'
     83                        == v.cssText)
     84          self.assert_(False is v.valid)
     85
     86 -    def test_valid(self):
     87          "CSSValue.valid"
     88          # context property must be set
     89          tests = [
     90              ('color', '1', False),
     91              ('color', 'red', True),
     92              ('left', '1', False),
     93              ('left', '1px', True)
     94              ]
     95          for n, v, exp in tests:
     96              v = cssutils.css.CSSValue(cssText=v, _propertyName=n)
     97              self.assert_(v.valid is exp)
     98
     99 -    def test_cssValueType(self):
    100          "CSSValue.cssValueType .cssValueTypeString"
    101          tests = [
    102              ([u'inherit'], 'CSS_INHERIT'),
    103              (['1', '1%', '1em', '1ex', '1px', '1cm', '1mm', '1in', '1pt', '1pc',
    104                '1deg', '1rad', '1grad', '1ms', '1s', '1hz', '1khz', '1other',
    105                 '"string"', "'str ing'", 'url(x)', 'red',
    106                 'attr(a)', 'counter()', 'rect(1px, 2px,3px,4px)',
    107                 'rgb(0,0,0)', '#000', '#000000', 'rgba(0,0,0,0)'],
    108               'CSS_PRIMITIVE_VALUE'),
    109              ([u'1px 1px', 'red blue green x'], 'CSS_VALUE_LIST')
    110              #([], 'CSS_CUSTOM') # what is a custom value?
    111              ]
    112          for values, name in tests:
    113              for value in values:
    114                  v = cssutils.css.CSSValue(cssText=value)
    115                  self.assertEqual(value, v.cssText)
    116                  self.assertEqual(name, v.cssValueTypeString)
    117                  self.assertEqual(getattr(v, name), v.cssValueType)
    118
    119 -    def test_readonly(self):
    120          "(CSSValue._readonly)"
    121          v = cssutils.css.CSSValue(cssText='inherit')
    122          self.assert_(False is v._readonly)
    123
    124          v = cssutils.css.CSSValue(cssText='inherit', readonly=True)
    125          self.assert_(True is v._readonly)
    126          self.assert_(u'inherit', v.cssText)
    127          self.assertRaises(xml.dom.NoModificationAllowedErr, v._setCssText, u'x')
    128          self.assert_(u'inherit', v.cssText)
    129
    130 -    def test_reprANDstr(self):
    131          "CSSValue.__repr__(), .__str__()"
    132          cssText='inherit'
    133
    134          s = cssutils.css.CSSValue(cssText=cssText)
    135
    136          self.assert_(cssText in str(s))
    137
    138          s2 = eval(repr(s))
    139          self.assert_(isinstance(s2, s.__class__))
    140          self.assert_(cssText == s2.cssText)
    141
    142
    143 -class CSSPrimitiveValueTestCase(basetest.BaseTestCase):
    144
    145 -    def test_init(self):
    146          "CSSPrimitiveValue.__init__()"
    147          v = cssutils.css.CSSPrimitiveValue(u'1')
    148          self.assert_(u'1' == v.cssText)
    149          self.assert_(v.valid == False)
    150
    151          self.assert_(v.CSS_PRIMITIVE_VALUE == v.cssValueType)
    152          self.assert_("CSS_PRIMITIVE_VALUE" == v.cssValueTypeString)
    153
    154          self.assert_(v.CSS_NUMBER == v.primitiveType)
    155          self.assert_("CSS_NUMBER" == v.primitiveTypeString)
    156
    157          # DUMMY to be able to test empty constructor call
    158          #self.assertRaises(xml.dom.SyntaxErr, v.__init__, None)
    159
    160          #self.assertRaises(xml.dom.InvalidAccessErr, v.getCounterValue)
    161          #self.assertRaises(xml.dom.InvalidAccessErr, v.getRGBColorValue)
    162          #self.assertRaises(xml.dom.InvalidAccessErr, v.getRectValue)
    163          #self.assertRaises(xml.dom.InvalidAccessErr, v.getStringValue)
    164
    165 -    def test_CSS_UNKNOWN(self):
    166          "CSSPrimitiveValue.CSS_UNKNOWN"
    167          v = cssutils.css.CSSPrimitiveValue(u'expression(false)')
    168          self.assert_(v.valid == False)
    169          self.assert_(v.CSS_UNKNOWN == v.primitiveType)
    170          self.assert_('CSS_UNKNOWN' == v.primitiveTypeString)
    171
    172 -    def test_CSS_NUMBER_AND_OTHER_DIMENSIONS(self):
    173          "CSSPrimitiveValue.CSS_NUMBER .. CSS_DIMENSION"
    174          defs = [
    175              ('', 'CSS_NUMBER'),
    176              ('%', 'CSS_PERCENTAGE'),
    177              ('em', 'CSS_EMS'),
    178              ('ex', 'CSS_EXS'),
    179              ('px', 'CSS_PX'),
    180              ('cm', 'CSS_CM'),
    181              ('mm', 'CSS_MM'),
    182              ('in', 'CSS_IN'),
    183              ('pt', 'CSS_PT'),
    184              ('pc', 'CSS_PC'),
    185              ('deg', 'CSS_DEG'),
    186              ('rad', 'CSS_RAD'),
    187              ('grad', 'CSS_GRAD'),
    188              ('ms', 'CSS_MS'),
    189              ('s', 'CSS_S'),
    190              ('hz', 'CSS_HZ'),
    191              ('khz', 'CSS_KHZ'),
    192              ('other_dimension', 'CSS_DIMENSION')]
    193          for dim, name in defs:
    194              for n in (0, -1, 1, 1.1, -1.1):
    195                  v = cssutils.css.CSSPrimitiveValue('%i%s' % (n, dim))
    196                  self.assert_(getattr(v, name) == v.primitiveType)
    197                  self.assert_(name == v.primitiveTypeString)
    198
    199 -    def test_CSS_STRING_AND_OTHER(self):
    200          "CSSPrimitiveValue.CSS_STRING .. CSS_RGBCOLOR"
    201          defs = [
    202              (('""', "''", '"some thing"', "' A\\ND '"), 'CSS_STRING'),
    203              (('url(a)', 'url("a b")', "url(' ')"), 'CSS_URI'),
    204              (('some', 'or_anth-er'), 'CSS_IDENT'),
    205              (('attr(a)', 'attr(b)'), 'CSS_ATTR'),
    206              (('counter(1)', 'counter(2)'), 'CSS_COUNTER'),
    207              (('rect(1,2,3,4)',), 'CSS_RECT'),
    208              (('rgb(1,2,3)', 'rgb(10%, 20%, 30%)', '#123', '#123456'),
    209                   'CSS_RGBCOLOR'),
    210              (('rgba(1,2,3,4)','rgba(10%, 20%, 30%, 40%)', ),
    211                   'CSS_RGBACOLOR')
    212              ]
    213          for examples, name in defs:
    214              for x in examples:
    215                  v = cssutils.css.CSSPrimitiveValue(x)
    216                  #self.assertEqual(getattr(v, name), v.primitiveType)
    217                  self.assertEqual(name, v.primitiveTypeString)
    218
    219 -    def test_getFloat(self):
    220          "CSSPrimitiveValue.getFloatValue()"
    221          # NOT TESTED are float values as it seems difficult to
    222          # compare these. Maybe use decimal.Decimal?
    223
    224          v = cssutils.css.CSSPrimitiveValue(u'1px')
    225          tests = {
    226              '0': (v.CSS_NUMBER, 0),
    227              '-1.1': (v.CSS_NUMBER, -1.1),
    228              '1%': (v.CSS_PERCENTAGE, 1),
    229              '-1%': (v.CSS_PERCENTAGE, -1),
    230              '1em': (v.CSS_EMS, 1),
    231              '-1.1em': (v.CSS_EMS, -1.1),
    232              '1ex': (v.CSS_EXS, 1),
    233              '1px': (v.CSS_PX, 1),
    234
    235              '1cm': (v.CSS_CM, 1),
    236              '1cm': (v.CSS_MM, 10),
    237              '254cm': (v.CSS_IN, 100),
    238              '1mm': (v.CSS_MM, 1),
    239              '10mm': (v.CSS_CM, 1),
    240              '254mm': (v.CSS_IN, 10),
    241              '1in': (v.CSS_IN, 1),
    242              '100in': (v.CSS_CM, 254), # ROUNDED!!!
    243              '10in': (v.CSS_MM, 254), # ROUNDED!!!
    244
    245              '1pt': (v.CSS_PT, 1),
    246              '1pc': (v.CSS_PC, 1),
    247
    248              '1deg': (v.CSS_DEG, 1),
    249              '1rad': (v.CSS_RAD, 1),
    250              '1grad': (v.CSS_GRAD, 1),
    251
    252              '1ms': (v.CSS_MS, 1),
    253              '1000ms': (v.CSS_S, 1),
    254              '1s': (v.CSS_S, 1),
    255              '1s': (v.CSS_MS, 1000),
    256
    257              '1hz': (v.CSS_HZ, 1),
    258              '1000hz': (v.CSS_KHZ, 1),
    259              '1khz': (v.CSS_KHZ, 1),
    260              '1khz': (v.CSS_HZ, 1000),
    261
    262              '1DIMENSION': (v.CSS_DIMENSION, 1)
    263              }
    264          for cssText in tests:
    265              v.cssText = cssText
    266              unitType, exp = tests[cssText]
    267              val = v.getFloatValue(unitType)
    268              if unitType in (v.CSS_IN, v.CSS_CM):
    269                  val = round(val)
    270              self.assertEqual(val , exp)
    271
    272 -    def test_setFloat(self):
    273          "CSSPrimitiveValue.setFloatValue()"
    274          V = cssutils.css.CSSPrimitiveValue
    275
    276          tests = {
    277              # unitType, value
    278              (V.CSS_NUMBER, 1): [
    279                  # unitType, setvalue,
    280                  #    getvalue or expected exception, msg or cssText
    281                  (V.CSS_NUMBER, 0, 0, '0'),
    282                  (V.CSS_NUMBER, 0.1, 0.1, '0.1'),
    283                  (V.CSS_NUMBER, -0, 0, '0'),
    284                  (V.CSS_NUMBER, 2, 2, '2'),
    285                  (V.CSS_NUMBER, 2.0, 2, '2'),
    286                  (V.CSS_NUMBER, 2.1, 2.1, '2.1'),
    287                  (V.CSS_NUMBER, -2.1, -2.1, '-2.1'),
    288                  # setting with string does work
    289                  (V.CSS_NUMBER, '1', 1, '1'),
    290                  (V.CSS_NUMBER, '1.1', 1.1, '1.1'),
    291                  (V.CSS_PX, 1, xml.dom.InvalidAccessErr, None),
    292                  (V.CSS_DEG, 1, xml.dom.InvalidAccessErr, None),
    293                  (V.CSS_RAD, 1, xml.dom.InvalidAccessErr, None),
    294                  (V.CSS_GRAD, 1, xml.dom.InvalidAccessErr, None),
    295                  (V.CSS_S, 1, xml.dom.InvalidAccessErr, None),
    296                  (V.CSS_MS, 1, xml.dom.InvalidAccessErr, None),
    297                  (V.CSS_KHZ, 1, xml.dom.InvalidAccessErr, None),
    298                  (V.CSS_HZ, 1, xml.dom.InvalidAccessErr, None),
    299                  (V.CSS_DIMENSION, 1, xml.dom.InvalidAccessErr, None),
    300                  (V.CSS_MM, 2, xml.dom.InvalidAccessErr, None),
    301
    302                  (V.CSS_NUMBER, 'x', xml.dom.InvalidAccessErr,
    303                   'CSSPrimitiveValue: floatValue "x" is not a float'),
    304                  (V.CSS_NUMBER, '1x', xml.dom.InvalidAccessErr,
    305                   'CSSPrimitiveValue: floatValue "1x" is not a float'),
    306
    307                  (V.CSS_STRING, 'x', xml.dom.InvalidAccessErr,
    308                   'CSSPrimitiveValue: unitType CSS_STRING is not a float type'),
    309                  (V.CSS_URI, 'x', xml.dom.InvalidAccessErr,
    310                   'CSSPrimitiveValue: unitType CSS_URI is not a float type'),
    311                  (V.CSS_ATTR, 'x', xml.dom.InvalidAccessErr,
    312                   'CSSPrimitiveValue: unitType CSS_ATTR is not a float type'),
    313                  (V.CSS_IDENT, 'x', xml.dom.InvalidAccessErr,
    314                   'CSSPrimitiveValue: unitType CSS_IDENT is not a float type'),
    315                  (V.CSS_RGBCOLOR, 'x', xml.dom.InvalidAccessErr,
    316                   'CSSPrimitiveValue: unitType CSS_RGBCOLOR is not a float type'),
    317                  (V.CSS_RGBACOLOR, 'x', xml.dom.InvalidAccessErr,
    318                   'CSSPrimitiveValue: unitType CSS_RGBACOLOR is not a float type'),
    319                  (V.CSS_RECT, 'x', xml.dom.InvalidAccessErr,
    320                   'CSSPrimitiveValue: unitType CSS_RECT is not a float type'),
    321                  (V.CSS_COUNTER, 'x', xml.dom.InvalidAccessErr,
    322                   'CSSPrimitiveValue: unitType CSS_COUNTER is not a float type'),
    323                  (V.CSS_EMS, 1, xml.dom.InvalidAccessErr,
    324                   'CSSPrimitiveValue: Cannot coerce primitiveType CSS_NUMBER to CSS_EMS'),
    325                  (V.CSS_EXS, 1, xml.dom.InvalidAccessErr,
    326                   'CSSPrimitiveValue: Cannot coerce primitiveType CSS_NUMBER to CSS_EXS')
    327              ],
    328              (V.CSS_MM, '1mm'): [
    329                  (V.CSS_MM, 2, 2, '2mm'),
    330                  (V.CSS_MM, 0, 0, '0mm'),
    331                  (V.CSS_MM, 0.1, 0.1, '0.1mm'),
    332                  (V.CSS_MM, -0, -0, '0mm'),
    333                  (V.CSS_MM, 3.0, 3, '3mm'),
    334                  (V.CSS_MM, 3.1, 3.1, '3.1mm'),
    335                  (V.CSS_MM, -3.1, -3.1, '-3.1mm'),
    336                  (V.CSS_CM, 1, 10, '10mm'),
    337                  (V.CSS_IN, 10, 254, '254mm'),
    338                  (V.CSS_PT, 1, 1828.8, '1828.8mm'),
    339                  (V.CSS_PX, 1, xml.dom.InvalidAccessErr, None),
    340                  (V.CSS_NUMBER, 2, xml.dom.InvalidAccessErr, None)
    341              ],
    342              (V.CSS_PT, '1pt'): [
    343                  (V.CSS_PT, 2, 2, '2pt'),
    344                  (V.CSS_PC, 12, 1, '1pt'),
    345                  (V.CSS_NUMBER, 1, xml.dom.InvalidAccessErr, None),
    346                  (V.CSS_DEG, 1, xml.dom.InvalidAccessErr, None),
    347                  (V.CSS_PX, 1, xml.dom.InvalidAccessErr, None)
    348              ],
    349              (V.CSS_KHZ, '1khz'): [
    350                  (V.CSS_HZ, 2000, 2, '2khz'),
    351                  (V.CSS_NUMBER, 1, xml.dom.InvalidAccessErr, None),
    352                  (V.CSS_DEG, 1, xml.dom.InvalidAccessErr, None),
    353                  (V.CSS_PX, 1, xml.dom.InvalidAccessErr, None)
    354              ]
    355          }
    356          for test in tests:
    357              initialType, initialValue = test
    358              pv = cssutils.css.CSSPrimitiveValue(initialValue)
    359              for setType, setValue, exp, msg in tests[test]:
    360                  if type(exp) == types.TypeType or\
    361                     type(exp) == types.ClassType: # 2.4 compactibility
    362                      if msg:
    363                          self.assertRaisesMsg(
    364                              exp, msg, pv.setFloatValue, setType, setValue)
    365                      else:
    366                          self.assertRaises(
    367                              exp, pv.setFloatValue, setType, setValue)
    368                  else:
    369                      pv.setFloatValue(setType, setValue)
    370                      self.assertEqual(pv.cssText, msg)
    371                      self.assertEqual(pv.getFloatValue(initialType), exp)
    372                      self.assertEqual(pv._value, msg)
    373
    374
    375 -    def test_getString(self):
    376          "CSSPrimitiveValue.getStringValue()"
    377          v = cssutils.css.CSSPrimitiveValue(u'1px')
    378          self.assert_(v.primitiveType == v.CSS_PX)
    379          self.assertRaises(xml.dom.InvalidAccessErr,
    380                            v.getStringValue)
    381
    382          pv = cssutils.css.CSSPrimitiveValue
    383          tests = {
    384              pv.CSS_STRING: ("'red'", 'red'),
    385              pv.CSS_STRING: ('"red"', 'red'),
    386              pv.CSS_URI: ('url(http://example.com)', None),
    387              pv.CSS_URI: ("url('http://example.com')",
    388                           u"http://example.com"),
    389              pv.CSS_URI: ('url("http://example.com")',
    390                           u'http://example.com'),
    391  #            pv.CSS_URI: ('url("http://example.com?)")',
    392  #                         u'http://example.com?)'),
    393              pv.CSS_IDENT: ('red', None),
    394              pv.CSS_ATTR: ('attr(att-name)',
    395                           u'att-name'), # the name of the attrr
    396              }
    397          for t in tests:
    398              val, exp = tests[t]
    399              if not exp:
    400                  exp = val
    401
    402              v = cssutils.css.CSSPrimitiveValue(val)
    403              self.assertEqual(v.primitiveType, t)
    404              self.assertEqual(v.getStringValue(), exp)
    405
    406
    407 -    def test_setString(self):
    408          "CSSPrimitiveValue.setStringValue()"
    409          # CSS_STRING
    410          v = cssutils.css.CSSPrimitiveValue(u'"a"')
    411          self.assert_(v.CSS_STRING == v.primitiveType)
    412          v.setStringValue(v.CSS_STRING, 'b')
    413          self.assert_('"b"' == v._value)
    414          self.assert_('b' == v.getStringValue())
    415          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    416              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_STRING to CSS_URI',
    417              v.setStringValue, *(v.CSS_URI, 'x'))
    418          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    419              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_STRING to CSS_IDENT',
    420              v.setStringValue, *(v.CSS_IDENT, 'x'))
    421          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    422              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_STRING to CSS_ATTR',
    423              v.setStringValue, *(v.CSS_ATTR, 'x'))
    424
    425          # CSS_IDENT
    426          v = cssutils.css.CSSPrimitiveValue('new')
    427          v.setStringValue(v.CSS_IDENT, 'ident')
    428          self.assert_(v.CSS_IDENT == v.primitiveType)
    429          self.assert_('ident' == v._value)
    430          self.assert_('ident' == v.getStringValue())
    431          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    432              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_IDENT to CSS_URI',
    433              v.setStringValue, *(v.CSS_URI, 'x'))
    434          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    435              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_IDENT to CSS_STRING',
    436              v.setStringValue, *(v.CSS_STRING, '"x"'))
    437          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    438              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_IDENT to CSS_ATTR',
    439              v.setStringValue, *(v.CSS_ATTR, 'x'))
    440
    441          # CSS_URI
    442          v = cssutils.css.CSSPrimitiveValue('url(old)')
    443          v.setStringValue(v.CSS_URI, '(')
    444          self.assertEqual(u'url("(")', v._value)
    445          self.assertEqual(u'(', v.getStringValue())
    446
    447          v.setStringValue(v.CSS_URI, ')')
    448          self.assertEqual(u'url(")")', v._value)
    449          self.assertEqual(u')', v.getStringValue())
    450          self.assertEqual(u'url(")")', v._value)
    451
    452          v.setStringValue(v.CSS_URI, '""')
    453          self.assertEqual(ur'\"\"', v.getStringValue())
    454          self.assertEqual(ur'url("\"\"")', v._value)
    455
    456          v.setStringValue(v.CSS_URI, ',')
    457          self.assertEqual(u'url(",")', v._value)
    458          self.assertEqual(u',', v.getStringValue())
    459
    460          v.setStringValue(v.CSS_URI, ' ')
    461          self.assertEqual(u'url(" ")', v._value)
    462          self.assertEqual(u' ', v.getStringValue())
    463
    464          v.setStringValue(v.CSS_URI, 'a)')
    465          self.assertEqual(u'url("a)")', v._value)
    466          self.assertEqual(u'a)', v.getStringValue())
    467
    468          v.setStringValue(v.CSS_URI, 'a')
    469          self.assert_(v.CSS_URI == v.primitiveType)
    470          self.assert_('url(a)' == v._value)
    471          self.assert_('a' == v.getStringValue())
    472          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    473              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_URI to CSS_IDENT',
    474              v.setStringValue, *(v.CSS_IDENT, 'x'))
    475          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    476              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_URI to CSS_STRING',
    477              v.setStringValue, *(v.CSS_STRING, '"x"'))
    478          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    479              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_URI to CSS_ATTR',
    480              v.setStringValue, *(v.CSS_ATTR, 'x'))
    481
    482          # CSS_ATTR
    483          v = cssutils.css.CSSPrimitiveValue('attr(old)')
    484          v.setStringValue(v.CSS_ATTR, 'a')
    485          self.assert_(v.CSS_ATTR == v.primitiveType)
    486          self.assert_('attr(a)' == v._value)
    487          self.assert_('a' == v.getStringValue())
    488          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    489              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_ATTR to CSS_IDENT',
    490              v.setStringValue, *(v.CSS_IDENT, 'x'))
    491          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    492              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_ATTR to CSS_STRING',
    493              v.setStringValue, *(v.CSS_STRING, '"x"'))
    494          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    495              u'CSSPrimitiveValue: Cannot coerce primitiveType CSS_ATTR to CSS_URI',
    496              v.setStringValue, *(v.CSS_URI, 'x'))
    497
    498          # TypeError as 'x' is no valid type
    499          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    500              u"CSSPrimitiveValue: stringType 'x' (UNKNOWN TYPE) is not a string type",
    501              v.setStringValue, *('x', 'brown'))
    502          # IndexError as 111 is no valid type
    503          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    504              u"CSSPrimitiveValue: stringType 111 (UNKNOWN TYPE) is not a string type",
    505              v.setStringValue, *(111, 'brown'))
    506          # CSS_PX is no string type
    507          self.assertRaisesMsg(xml.dom.InvalidAccessErr,
    508              u"CSSPrimitiveValue: stringType CSS_PX is not a string type",
    509              v.setStringValue, *(v.CSS_PX, 'brown'))
    510
    511  #
    512  #    def test_typeRGBColor(self):
    513  #        v = cssutils.cssprimitivevalue.PrimitiveValue('RGB(1, 5, 10)')
    514  #        self.assertEqual(v.CSS_RGBCOLOR, v.primitiveType)
    515  #        self.assertEqual(u'rgb(1, 5, 10)', v.cssText)
    516  #
    517  #        v = cssutils.cssprimitivevalue.PrimitiveValue('rgb(1, 5, 10)')
    518  #        self.assertEqual(v.CSS_RGBCOLOR, v.primitiveType)
    519  #        self.assertEqual(u'rgb(1, 5, 10)', v.cssText)
    520  #
    521  #        v = cssutils.cssprimitivevalue.PrimitiveValue('rgb(1%, 5%, 10%)')
    522  #        self.assertEqual(v.CSS_RGBCOLOR, v.primitiveType)
    523  #        self.assertEqual(u'rgb(1.0%, 5.0%, 10.0%)', v.cssText)
    524  #
    525  #        v = cssutils.cssprimitivevalue.PrimitiveValue('  rgb(  1 ,5,  10  )')
    526  #        self.assertEqual(v.CSS_RGBCOLOR, v.primitiveType)
    527  #        v = cssutils.cssprimitivevalue.PrimitiveValue('rgb (1,5,10)')
    528  #        self.assertEqual(v.CSS_RGBCOLOR, v.primitiveType)
    529  #        v = cssutils.cssprimitivevalue.PrimitiveValue('rgb(1%, .5%, 10.1%)')
    530  #        self.assertEqual(v.CSS_RGBCOLOR, v.primitiveType)
    531
    532 -    def test_reprANDstr(self):
    533          "CSSPrimitiveValue.__repr__(), .__str__()"
    534          v='111'
    535
    536          s = cssutils.css.CSSPrimitiveValue(v)
    537
    538          self.assert_(v in str(s))
    539          self.assert_('CSS_NUMBER' in str(s))
    540
    541          s2 = eval(repr(s))
    542          self.assert_(isinstance(s2, s.__class__))
    543          self.assert_(v == s2.cssText)
    544
    545
    546 -class CSSValueListTestCase(basetest.BaseTestCase):
    547
    548 -    def test_init(self):
    549          "CSSValueList.__init__()"
    550          v = cssutils.css.CSSValue(cssText=u'red blue', _propertyName='border-color')
    551          self.assert_(v.CSS_VALUE_LIST == v.cssValueType)
    552          self.assert_('red blue' == v._value)
    553          self.assert_('red blue' == v.cssText)
    554          self.assert_(True is v.valid)
    555
    556          self.assert_(2 == v.length)
    557
    558          item = v.item(0)
    559          item.setStringValue(item.CSS_IDENT, 'green')
    560          self.assertEqual('green blue', v._value)
    561          self.assertEqual('green blue', v.cssText)
    562
    563 -    def test_reprANDstr(self):
    564          "CSSValueList.__repr__(), .__str__()"
    565          v='1px 2px'
    566
    567          s = cssutils.css.CSSValue(v)
    568          self.assert_(isinstance(s, cssutils.css.CSSValueList))
    569
    570          self.assert_(v in str(s))
    571
    572          # not "eval()"able!
    573          #s2 = eval(repr(s))
    574
    575
    576  if __name__ == '__main__':
    577      import unittest
    578      unittest.main()
    579