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-08-20 22:09:16 +0200 (Mo, 20 Aug 2007) $'
      7  __version__ = '$LastChangedRevision: 258 $'
      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(1, ml.length)
     32          self.assertEqual(u'all', ml.mediaText)
     33
     34          self.assertRaises(xml.dom.InvalidCharacterErr,
     35                            ml._setMediaText, 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 -    def test_appendAll(self):
     60          "MediaList.append() 2"
     61          ml = cssutils.stylesheets.MediaList()
     62          ml.appendMedium(u'print')
     63          ml.appendMedium(u'tv')
     64          self.assertEqual(2, ml.length)
     65          self.assertEqual(u'print, tv', ml.mediaText)
     66
     67          ml.appendMedium(u'all')
     68          self.assertEqual(1, ml.length)
     69          self.assertEqual(u'all', ml.mediaText)
     70
     71          ml.appendMedium(u'print')
     72          self.assertEqual(1, ml.length)
     73          self.assertEqual(u'all', ml.mediaText)
     74
     75          self.assertRaises(xml.dom.InvalidCharacterErr, ml.appendMedium, u'test')
     76
     77 -    def test_delete(self):
     78          "MediaList.deleteMedium()"
     79          ml = cssutils.stylesheets.MediaList()
     80
     81          self.assertRaises(xml.dom.NotFoundErr, ml.deleteMedium, u'all')
     82          self.assertRaises(xml.dom.NotFoundErr, ml.deleteMedium, u'test')
     83
     84          ml.appendMedium(u'print')
     85          ml.deleteMedium(u'print')
     86          ml.appendMedium(u'tV')
     87          ml.deleteMedium(u'Tv')
     88          self.assertEqual(0, ml.length)
     89          self.assertEqual(u'all', ml.mediaText)
     90
     91 -    def test_item(self):
     92          "MediaList.item()"
     93          ml = cssutils.stylesheets.MediaList()
     94          ml.appendMedium(u'print')
     95          ml.appendMedium(u'screen')
     96
     97          self.assertEqual(u'print', ml.item(0))
     98          self.assertEqual(u'screen', ml.item(1))
     99          self.assertEqual(None, ml.item(2))
    100
    101 -    def test_handheld(self):
    102          "MediaList handheld"
    103          ml = cssutils.stylesheets.MediaList()
    104
    105          ml.mediaText = u' handheld , all  , screen '
    106          self.assertEqual(1, ml.length)
    107          # keeps all explicitly set incl ,
    108          self.assertEqual(5, len(ml.seq)) # ?
    109          self.assertEqual(u'handheld, all', ml.mediaText)
    110
    111 -    def test_mediaText(self):
    112          "MediaList.mediaText 2"
    113          tests = {
    114              u'': u'all',
    115              u'ALL': u'all',
    116              u'Tv': u'tv',
    117              u'all': None,
    118              u'all, handheld': None,
    119              u'tv': None,
    120              u'tv, handheld, print': None,
    121              }
    122          self.do_equal_r(tests, att='mediaText')
    123
    124          tests = {
    125              u'all;': xml.dom.SyntaxErr,
    126              u'UNKNOWN': xml.dom.SyntaxErr,
    127              }
    128          self.do_raise_p(tests)
    129
    130 -    def test_comments(self):
    131          "MediaList.mediaText comments"
    132          tests = {
    133              u'/*1*/tv/*2*/, /*3*/handheld/*4*/, tv': None,
    134              }
    135          self.do_equal_r(tests, att='mediaText')
    136
    137 -    def test_reprANDstr(self):
    138          "MediaList.__repr__(), .__str__()"
    139          mediaText='tv, print'
    140
    141          s = cssutils.stylesheets.MediaList(mediaText=mediaText)
    142
    143          self.assert_(mediaText in str(s))
    144
    145          s2 = eval(repr(s))
    146          self.assert_(isinstance(s2, s.__class__))
    147          self.assert_(mediaText == s2.mediaText)
    148
    149
    150  if __name__ == '__main__':
    151      import unittest
    152      unittest.main()
    153