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

# Source Code for Module cssutils.tests.test_cssutils

     1  # -*- coding: iso-8859-1 -*-
     2  """
     3  testcases for cssutils.css.CSSCharsetRule
     4  """
     5  __all__ = ['CSSutilsTestCase']
     6  __author__ = '$LastChangedBy: doerwalter $'
     7  __date__ = '$LastChangedDate: 2007-08-02 22:58:23 +0200 (Do, 02 Aug 2007) $'
     8  __version__ = '0.9.2a1, $LastChangedRevision: 160 $'
     9
    10
    11  import codecs
    12  import os
    13
    14  import basetest
    15
    16  import cssutils
    17
    18
    19 -class CSSutilsTestCase(basetest.BaseTestCase):
    20
    21 -    def test_parse(self):
    22          "cssutils.parse()"
    23          # temp css for tests
    24          name = '__cssutils_temptestfile__.css'
    25          css = u'a:after { content: "äu\u2020" }'
    26
    27          if os.path.exists(name):
    28              raise IOError('skipping test as file "%s" exists' % name)
    29
    30          css = u'a:after { content: "äu\u2020" }'
    31          t = codecs.open(name, 'w', encoding='utf-8')
    32          t.write(css)
    33          t.close()
    34          self.assertRaises(
    35              UnicodeDecodeError, cssutils.parse, name, 'ascii')
    36          s = cssutils.parse(name, 'iso-8859-1') #???
    37          s = cssutils.parse(name, 'utf-8')
    38          self.assertEqual(cssutils.css.CSSStyleSheet, type(s))
    39
    40          css = u'a:after { content: "ä" }'
    41          t = codecs.open(name, 'w', 'iso-8859-1')
    42          t.write(css)
    43          t.close()
    44          self.assertRaises(
    45              UnicodeDecodeError, cssutils.parse, name, 'ascii')
    46          s = cssutils.parse(name, 'iso-8859-1')
    47          self.assertEqual(cssutils.css.CSSStyleSheet, type(s))
    48
    49          # clean up
    50          os.remove(name)
    51
    52
    53 -    def test_parseString(self):
    54          "cssutils.parseString()"
    55          exp = '''a {
    56      left: 0
    57      }'''
    58          s = cssutils.parseString(exp)
    59          self.assertEqual(cssutils.css.CSSStyleSheet, type(s))
    60          self.assertEqual(exp, s.cssText)
    61
    62
    63 -    def test_setCSSSerializer(self):
    64          "cssutils.setSerializer() and cssutils.ser"
    65          s = cssutils.parseString('a { left: 0 }')
    66          exp4 = '''a {
    67      left: 0
    68      }'''
    69          exp1 = '''a {
    70   left: 0
    71   }'''
    72          self.assertEqual(exp4, s.cssText)
    73          newser = cssutils.CSSSerializer(cssutils.serialize.Preferences(indent=' '))
    74          cssutils.setSerializer(newser)
    75          self.assertEqual(exp1, s.cssText)
    76          newser = cssutils.CSSSerializer(cssutils.serialize.Preferences(indent='    '))
    77          cssutils.ser = newser
    78          self.assertEqual(exp4, s.cssText)
    79
    80
    81  if __name__ == '__main__':
    82      import unittest
    83      unittest.main()
    84