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

# Source Code for Module cssutils.tests.test_csspagerule

      1  """testcases for cssutils.css.CSSPageRule
      2  """
      3  __author__ = '$LastChangedBy: cthedot $'
      4  __date__ = '$LastChangedDate: 2008-02-18 23:25:11 +0100 (Mo, 18 Feb 2008) $'
      5  __version__ = '$LastChangedRevision: 1063 $'
      6
      7  import xml.dom
      8  import test_cssrule
      9  import cssutils
     10
     11 -class CSSPageRuleTestCase(test_cssrule.CSSRuleTestCase):
     12
     13 -    def setUp(self):
     14          super(CSSPageRuleTestCase, self).setUp()
     15          self.r = cssutils.css.CSSPageRule()
     16          self.rRO = cssutils.css.CSSPageRule(readonly=True)
     17          self.r_type = cssutils.css.CSSPageRule.PAGE_RULE#
     18          self.r_typeString = 'PAGE_RULE'
     19
     20 -    def test_init(self):
     21          "CSSPageRule.__init__()"
     22          super(CSSPageRuleTestCase, self).test_init()
     23
     24          r = cssutils.css.CSSPageRule()
     25          self.assertEqual(u'', r.selectorText)
     26          self.assertEqual(cssutils.css.CSSStyleDeclaration, type(r.style))
     27          self.assertEqual(r, r.style.parentRule)
     28
     29          # until any properties
     30          self.assertEqual(u'', r.cssText)
     31
     32 -    def test_InvalidModificationErr(self):
     33          "CSSPageRule.cssText InvalidModificationErr"
     34          self._test_InvalidModificationErr(u'@page')
     35          tests = {
     36              u'@pag {}': xml.dom.InvalidModificationErr,
     37              }
     38          self.do_raise_r(tests)
     39
     40 -    def test_incomplete(self):
     41          "CSSPageRule (incomplete)"
     42          tests = {
     43              u'@page :left { ':
     44                  u'', # no } and no content
     45              u'@page :left { color: red':
     46                  u'@page :left {\n    color: red\n    }', # no }
     47          }
     48          self.do_equal_p(tests) # parse
     49
     50 -    def test_cssText(self):
     51          "CSSPageRule.cssText"
     52          EXP = u'@page :%s {\n    margin: 0\n    }'
     53          tests = {
     54              u'@page {}': u'',
     55              u'@page:left{}': u'',
     56              u'@page :right {}': u'',
     57              u'@page {margin:0;}': u'@page {\n    margin: 0\n    }',
     58
     59              u'@page:left{margin:0;}': EXP % u'left',
     60              u'@page :left { margin: 0 }': EXP % u'left',
     61              u'@page :right { margin: 0 }': EXP % u'right',
     62              u'@page :first { margin: 0 }': EXP % u'first',
     63              u'@page :UNKNOWNIDENT { margin: 0 }': EXP % u'UNKNOWNIDENT',
     64
     65              u'@PAGE:left{margin:0;}': u'@page :left {\n    margin: 0\n    }',
     66              u'@\\page:left{margin:0;}': u'@page :left {\n    margin: 0\n    }',
     67
     68              u'@page/*1*/:left/*2*/{margin:0;}':
     69                  u'@page /*1*/ :left /*2*/ {\n    margin: 0\n    }',
     70              }
     71          self.do_equal_r(tests)
     72          self.do_equal_p(tests)
     73
     74          tests = {
     75              u'@page : {}': xml.dom.SyntaxErr,
     76              u'@page :/*1*/left {}': xml.dom.SyntaxErr,
     77              u'@page : left {}': xml.dom.SyntaxErr,
     78              u'@page :left :right {}': xml.dom.SyntaxErr,
     79              u'@page :left a {}': xml.dom.SyntaxErr,
     80
     81              u'@page :left;': xml.dom.SyntaxErr,
     82              u'@page :left }': xml.dom.SyntaxErr,
     83              }
     84          self.do_raise_p(tests) # parse
     85          tests.update({
     86              u'@page :left {': xml.dom.SyntaxErr, # no }
     87              })
     88          self.do_raise_r(tests) # set cssText
     89
     90 -    def test_selectorText(self):
     91          "CSSPageRule.selectorText"
     92          tests = {
     93              u'': u'',
     94              u':left': None,
     95              u':right': None,
     96              u':first': None,
     97              u':UNKNOWNIDENT': None,
     98
     99              u' :left': u':left',
    100              u':left': u':left',
    101              u'/*1*/:left/*a*/': u':left',
    102              u'/*1*/ :left /*a*/ /*b*/': u':left',
    103              u':left/*a*/': u':left',
    104              u'/*1*/:left': u':left',
    105              }
    106          self.do_equal_r(tests, att='selectorText')
    107
    108          tests = {
    109              u':': xml.dom.SyntaxErr,
    110              u':/*1*/left': xml.dom.SyntaxErr,
    111              u': left': xml.dom.SyntaxErr,
    112              u':left :right': xml.dom.SyntaxErr,
    113              u':left a': xml.dom.SyntaxErr,
    114              }
    115          self.do_raise_r(tests, att='_setSelectorText')
    116
    117 -    def test_style(self):
    118          "CSSPageRule.style"
    119          d = cssutils.css.CSSStyleDeclaration()
    120          self.r.style = d
    121          self.assertEqual(d.cssText, self.r.style.cssText)
    122          self.assertEqual(None, d.parentRule)
    123
    124 -    def test_properties(self):
    125          "CSSPageRule.style properties"
    126          r = cssutils.css.CSSPageRule()
    127          r.style.cssText = '''
    128          margin-top: 0;
    129          margin-right: 0;
    130          margin-bottom: 0;
    131          margin-left: 0;
    132          margin: 0;
    133
    134          page-break-before: auto;
    135          page-break-after: auto;
    136          page-break-inside: auto;
    137
    138          orphans: 3;
    139          widows: 3;
    140          '''
    141          exp = u'''@page {
    142      margin-top: 0;
    143      margin-right: 0;
    144      margin-bottom: 0;
    145      margin-left: 0;
    146      margin: 0;
    147      page-break-before: auto;
    148      page-break-after: auto;
    149      page-break-inside: auto;
    150      orphans: 3;
    151      widows: 3
    152      }'''
    153          self.assertEqual(exp, r.cssText)
    154
    155 -    def test_reprANDstr(self):
    156          "CSSPageRule.__repr__(), .__str__()"
    157          sel=u':left'
    158
    159          s = cssutils.css.CSSPageRule(selectorText=sel)
    160
    161          self.assert_(sel in str(s))
    162
    163          s2 = eval(repr(s))
    164          self.assert_(isinstance(s2, s.__class__))
    165          self.assert_(sel == s2.selectorText)
    166
    167
    168  if __name__ == '__main__':
    169      import unittest
    170      unittest.main()
    171