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 1175 2008-03-20 17:43:26Z 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          # only possible to set @... similar name
     30          self.assertRaises(xml.dom.InvalidModificationErr, self.r._setAtkeyword, 'x')
     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 :right { margin: 0 }': EXP % u'right',
     61              u'@page :first { margin: 0 }': EXP % u'first',
     62              u'@page :UNKNOWNIDENT { margin: 0 }': EXP % u'UNKNOWNIDENT',
     63
     64              u'@PAGE:left{margin:0;}': u'@page :left {\n    margin: 0\n    }',
     65              u'@\\page:left{margin:0;}': u'@page :left {\n    margin: 0\n    }',
     66
     67              # comments
     68              u'@page/*1*//*2*/:left/*3*//*4*/{margin:0;}':
     69                  u'@page /*1*/ /*2*/ :left /*3*/ /*4*/ {\n    margin: 0\n    }',
     70              # WS
     71              u'@page:left{margin:0;}':
     72                  u'@page :left {\n    margin: 0\n    }',
     73              u'@page\n\r\f\t :left\n\r\f\t {margin:0;}':
     74                  u'@page :left {\n    margin: 0\n    }',
     75              }
     76          self.do_equal_r(tests)
     77          self.do_equal_p(tests)
     78
     79          tests = {
     80              u'@page : {}': xml.dom.SyntaxErr,
     81              u'@page :/*1*/left {}': xml.dom.SyntaxErr,
     82              u'@page : left {}': xml.dom.SyntaxErr,
     83              u'@page :left :right {}': xml.dom.SyntaxErr,
     84              u'@page :left a {}': xml.dom.SyntaxErr,
     85
     86              u'@page :left;': xml.dom.SyntaxErr,
     87              u'@page :left }': xml.dom.SyntaxErr,
     88              }
     89          self.do_raise_p(tests) # parse
     90          tests.update({
     91              u'@page :left {': xml.dom.SyntaxErr, # no }
     92              # trailing
     93              u'@page :left {}1': xml.dom.SyntaxErr, # no }
     94              u'@page :left {}/**/': xml.dom.SyntaxErr, # no }
     95              u'@page :left {} ': xml.dom.SyntaxErr, # no }
     96              })
     97          self.do_raise_r(tests) # set cssText
     98
     99 -    def test_selectorText(self):
    100          "CSSPageRule.selectorText"
    101          tests = {
    102              u'': u'',
    103              u':left': None,
    104              u':right': None,
    105              u':first': None,
    106              u':UNKNOWNIDENT': None,
    107
    108              u' :left': u':left',
    109              u':left': u':left',
    110              u'/*1*/:left/*a*/': u':left',
    111              u'/*1*/ :left /*a*/ /*b*/': u':left',
    112              u':left/*a*/': u':left',
    113              u'/*1*/:left': u':left',
    114              }
    115          self.do_equal_r(tests, att='selectorText')
    116
    117          tests = {
    118              u':': xml.dom.SyntaxErr,
    119              u':/*1*/left': xml.dom.SyntaxErr,
    120              u': left': xml.dom.SyntaxErr,
    121              u':left :right': xml.dom.SyntaxErr,
    122              u':left a': xml.dom.SyntaxErr,
    123              }
    124          self.do_raise_r(tests, att='_setSelectorText')
    125
    126 -    def test_style(self):
    127          "CSSPageRule.style"
    128          d = cssutils.css.CSSStyleDeclaration()
    129          self.r.style = d
    130          self.assertEqual(d.cssText, self.r.style.cssText)
    131          self.assertEqual(None, d.parentRule)
    132
    133 -    def test_properties(self):
    134          "CSSPageRule.style properties"
    135          r = cssutils.css.CSSPageRule()
    136          r.style.cssText = '''
    137          margin-top: 0;
    138          margin-right: 0;
    139          margin-bottom: 0;
    140          margin-left: 0;
    141          margin: 0;
    142
    143          page-break-before: auto;
    144          page-break-after: auto;
    145          page-break-inside: auto;
    146
    147          orphans: 3;
    148          widows: 3;
    149          '''
    150          exp = u'''@page {
    151      margin-top: 0;
    152      margin-right: 0;
    153      margin-bottom: 0;
    154      margin-left: 0;
    155      margin: 0;
    156      page-break-before: auto;
    157      page-break-after: auto;
    158      page-break-inside: auto;
    159      orphans: 3;
    160      widows: 3
    161      }'''
    162          self.assertEqual(exp, r.cssText)
    163
    164 -    def test_reprANDstr(self):
    165          "CSSPageRule.__repr__(), .__str__()"
    166          sel=u':left'
    167
    168          s = cssutils.css.CSSPageRule(selectorText=sel)
    169
    170          self.assert_(sel in str(s))
    171
    172          s2 = eval(repr(s))
    173          self.assert_(isinstance(s2, s.__class__))
    174          self.assert_(sel == s2.selectorText)
    175
    176
    177  if __name__ == '__main__':
    178      import unittest
    179      unittest.main()
    180