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