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