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

# Source Code for Module cssutils.tests.test_medialist

      1  # -*- coding: iso-8859-1 -*-
      2  """
      3  testcases for cssutils.stylesheets.MediaList
      4  """
      5  __author__ = '$LastChangedBy: cthedot $'
      6  __date__ = '$LastChangedDate: 2007-09-25 21:42:03 +0200 (Di, 25 Sep 2007) $'
      7  __version__ = '$LastChangedRevision: 451 $'
      8
      9  import xml.dom
     10  import basetest
     11  import cssutils.stylesheets
     12
     13 -class MediaListTestCase(basetest.BaseTestCase):
     14
     15 -    def setUp(self):
     16          super(MediaListTestCase, self).setUp()
     17          self.r = cssutils.stylesheets.MediaList()
     18
     19 -    def test_set(self):
     20          "MediaList.mediaText 1"
     21          ml = cssutils.stylesheets.MediaList()
     22
     23          self.assertEqual(0, ml.length)
     24          self.assertEqual(u'all', ml.mediaText)
     25
     26          ml.mediaText = u' print   , screen '
     27          self.assertEqual(2, ml.length)
     28          self.assertEqual(u'print, screen', ml.mediaText)
     29
     30          ml.mediaText = u' print , all  , screen '
     31          self.assertEqual(u'all', ml.mediaText)
     32          self.assertEqual(1, ml.length)
     33
     34          self.assertRaises(xml.dom.InvalidCharacterErr,
     35                            ml.appendMedium, u'test')
     36
     37 -    def test_append(self):
     38          "MediaList.append() 1"
     39          ml = cssutils.stylesheets.MediaList()
     40
     41          ml.appendMedium(u'print')
     42          self.assertEqual(1, ml.length)
     43          self.assertEqual(u'print', ml.mediaText)
     44
     45          ml.appendMedium(u'screen')
     46          self.assertEqual(2, ml.length)
     47          self.assertEqual(u'print, screen', ml.mediaText)
     48
     49          # automatic del and append!
     50          ml.appendMedium(u'print')
     51          self.assertEqual(2, ml.length)
     52          self.assertEqual(u'screen, print', ml.mediaText)
     53
     54          # automatic del and append!
     55          ml.appendMedium(u'SCREEN')
     56          self.assertEqual(2, ml.length)
     57          self.assertEqual(u'print, SCREEN', ml.mediaText)
     58
     59          # append invalid MediaQuery
     60          mq = cssutils.stylesheets.MediaQuery()
     61          ml.appendMedium(mq)
     62          self.assertEqual(2, ml.length)
     63          self.assertEqual(u'print, SCREEN', ml.mediaText)
     64
     65 -    def test_appendAll(self):
     66          "MediaList.append() 2"
     67          ml = cssutils.stylesheets.MediaList()
     68          ml.appendMedium(u'print')
     69          ml.appendMedium(u'tv')
     70          self.assertEqual(2, ml.length)
     71          self.assertEqual(u'print, tv', ml.mediaText)
     72
     73          ml.appendMedium(u'all')
     74          self.assertEqual(1, ml.length)
     75          self.assertEqual(u'all', ml.mediaText)
     76
     77          ml.appendMedium(u'print')
     78          self.assertEqual(1, ml.length)
     79          self.assertEqual(u'all', ml.mediaText)
     80
     81          self.assertRaises(xml.dom.InvalidCharacterErr, ml.appendMedium, u'test')
     82
     83 -    def test_delete(self):
     84          "MediaList.deleteMedium()"
     85          ml = cssutils.stylesheets.MediaList()
     86
     87          self.assertRaises(xml.dom.NotFoundErr, ml.deleteMedium, u'all')
     88          self.assertRaises(xml.dom.NotFoundErr, ml.deleteMedium, u'test')
     89
     90          ml.appendMedium(u'print')
     91          ml.deleteMedium(u'print')
     92          ml.appendMedium(u'tV')
     93          ml.deleteMedium(u'Tv')
     94          self.assertEqual(0, ml.length)
     95          self.assertEqual(u'all', ml.mediaText)
     96
     97 -    def test_item(self):
     98          "MediaList.item()"
     99          ml = cssutils.stylesheets.MediaList()
    100          ml.appendMedium(u'print')
    101          ml.appendMedium(u'screen')
    102
    103          self.assertEqual(u'print', ml.item(0))
    104          self.assertEqual(u'screen', ml.item(1))
    105          self.assertEqual(None, ml.item(2))
    106
    107 -    def test_handheld(self):
    108          "MediaList handheld"
    109          ml = cssutils.stylesheets.MediaList()
    110
    111          ml.mediaText = u' handheld , all  , screen '
    112          self.assertEqual(2, ml.length)
    113          self.assertEqual(u'all, handheld', ml.mediaText)
    114
    115 -    def test_mediaText(self):
    116          "MediaList.mediaText 2"
    117          tests = {
    118              u'': u'all',
    119              u'ALL': u'ALL',
    120              u'Tv': u'Tv',
    121              u'all': None,
    122              u'all, handheld': None,
    123              u'tv': None,
    124              u'tv, handheld, print': None,
    125              u'tv and (color), handheld and (width: 1px) and (color)': None,
    126              }
    127          self.do_equal_r(tests, att='mediaText')
    128
    129          tests = {
    130              u'UNKNOWN': xml.dom.InvalidCharacterErr,
    131              u'a,b': xml.dom.InvalidCharacterErr,
    132              u'a and (color)': xml.dom.InvalidCharacterErr,
    133              u'not': xml.dom.SyntaxErr, # known but need media
    134              u'only': xml.dom.SyntaxErr, # known but need media
    135              u'not tv,': xml.dom.SyntaxErr, # known but need media
    136              u'all;': xml.dom.SyntaxErr,
    137              u'all, and(color)': xml.dom.SyntaxErr,
    138              u'all,': xml.dom.SyntaxErr,
    139              u'all, ': xml.dom.SyntaxErr,
    140              u'all ,': xml.dom.SyntaxErr,
    141              u'all, /*1*/': xml.dom.SyntaxErr,
    142              u'all and (color),': xml.dom.SyntaxErr,
    143              u'all tv, print': xml.dom.SyntaxErr,
    144              }
    145          self.do_raise_r(tests, att='_setMediaText')
    146
    147 -    def test_comments(self):
    148          "MediaList.mediaText comments"
    149          tests = {
    150              u'/*1*/ tv /*2*/, /*3*/ handheld /*4*/, print': None,
    151              }
    152          self.do_equal_r(tests, att='mediaText')
    153
    154 -    def test_reprANDstr(self):
    155          "MediaList.__repr__(), .__str__()"
    156          mediaText='tv, print'
    157
    158          s = cssutils.stylesheets.MediaList(mediaText=mediaText)
    159
    160          self.assert_(mediaText in str(s))
    161
    162          s2 = eval(repr(s))
    163          self.assert_(isinstance(s2, s.__class__))
    164          self.assert_(mediaText == s2.mediaText)
    165
    166
    167  if __name__ == '__main__':
    168      import unittest
    169      unittest.main()
    170