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

# Source Code for Module cssutils.tests.test_mediaquery

     1  # -*- coding: iso-8859-1 -*-
     2  """Testcases for cssutils.stylesheets.MediaList"""
     3  __version__ = '$Id: test_mediaquery.py 1116 2008-03-05 13:52:23Z cthedot $'
     4
     5  import xml.dom
     6  import basetest
     7  import cssutils.stylesheets
     8
     9 -class MediaQueryTestCase(basetest.BaseTestCase):
    10
    11 -    def setUp(self):
    12          super(MediaQueryTestCase, self).setUp()
    13          self.r = cssutils.stylesheets.MediaQuery()
    14
    15 -    def test_mediaText(self):
    16          "MediaQuery.mediaText"
    17          tests = {
    18              u'all': None,
    19              u'a\\ll': None,
    20              u'not tv': None,
    21              u'n\\ot t\\v': None,
    22              u'only tv': None,
    23              u'\\only \\tv': None,
    24              u'PRINT': None,
    25              u'NOT PRINT': None,
    26              u'ONLY PRINT': None,
    27              u'tv and (color)': None,
    28              u'not tv and (color)': None,
    29              u'only tv and (color)': None,
    30              }
    31          self.do_equal_r(tests, att='mediaText')
    32
    33          tests = {
    34              u'': xml.dom.SyntaxErr,
    35              u'two values': xml.dom.SyntaxErr,
    36              u'or even three': xml.dom.SyntaxErr,
    37              u'print and(color)': xml.dom.SyntaxErr, # a function
    38              u'3d': xml.dom.InvalidCharacterErr, # a dimension
    39              }
    40          self.do_raise_r(tests, att='_setMediaText')
    41
    42 -    def test_mediaType(self):
    43          "MediaQuery.mediaType"
    44          mq = cssutils.stylesheets.MediaQuery()
    45
    46          self.assertEqual(u'', mq.mediaText)
    47
    48          for mt in cssutils.stylesheets.MediaQuery.MEDIA_TYPES:
    49              mq.mediaType = mt
    50              self.assertEqual(mq.mediaType, mt)
    51              mq.mediaType = mt.upper()
    52              self.assertEqual(mq.mediaType, mt.upper())
    53
    54          mt = u'3D-UNKOwn-MEDIAtype0123'
    55          #mq.mediaType = mt
    56          self.assertRaises(xml.dom.InvalidCharacterErr, mq._setMediaType, mt)
    57
    58 -    def test_comments(self):
    59          "MediaQuery.mediaText comments"
    60          tests = {
    61              u'all': None,
    62              u'print': None,
    63              u'not print': None,
    64              u'only print': None,
    65              u'print and (color)': None,
    66              u'print and (color) and (width)': None,
    67              u'print and (color: 2)': None,
    68              u'print and (min-width: 100px)': None,
    69              u'print and (min-width: 100px) and (color: red)': None,
    70              u'not print and (min-width: 100px)': None,
    71              u'only print and (min-width: 100px)': None,
    72              u'/*1*/ tv /*2*/': None,
    73              u'/*0*/ only /*1*/ tv /*2*/': None,
    74              u'/*0* /not /*1*/ tv /*2*/': None,
    75              u'/*x*/ only /*x*/ print /*x*/ and /*x*/ (/*x*/min-width/*x*/: /*x*/100px/*x*/)': None,
    76              u'print and/*1*/(color)': u'print and /*1*/ (color)'
    77              }
    78          self.do_equal_r(tests, att='mediaText')
    79
    80 -    def test_reprANDstr(self):
    81          "MediaQuery.__repr__(), .__str__()"
    82          mediaText='tv and (color)'
    83          s = cssutils.stylesheets.MediaQuery(mediaText=mediaText)
    84          self.assert_(mediaText in str(s))
    85          s2 = eval(repr(s))
    86          self.assertEqual(mediaText, s2.mediaText)
    87          self.assert_(isinstance(s2, s.__class__))
    88
    89
    90  if __name__ == '__main__':
    91      import unittest
    92      unittest.main()
    93