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: 2007-08-20 22:09:16 +0200 (Mo, 20 Aug 2007) $'
      5  __version__ = '$LastChangedRevision: 258 $'
      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\e {}': 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 {margin:0;}': u'@page {\n    margin: 0\n    }',
     55
     56              u'@page:left{margin:0;}': EXP % u'left',
     57              u'@page :left { margin: 0 }': EXP % u'left',
     58              u'@page :right { margin: 0 }': EXP % u'right',
     59              u'@page :first { margin: 0 }': EXP % u'first',
     60              u'@page :UNKNOWNIDENT { margin: 0 }': EXP % u'UNKNOWNIDENT',
     61
     62              u'@PAGE:left{margin:0;}': u'@page :left {\n    margin: 0\n    }',
     63              u'@\\page:left{margin:0;}': u'@page :left {\n    margin: 0\n    }',
     64
     65              u'@page/*1*/:left/*2*/{margin:0;}':
     66                  u'@page /*1*/:left/*2*/ {\n    margin: 0\n    }',
     67              }
     68          self.do_equal_r(tests)
     69          self.do_equal_p(tests)
     70
     71          tests = {
     72              u'@page : {}': xml.dom.SyntaxErr,
     73              u'@page :/*1*/left {}': xml.dom.SyntaxErr,
     74              u'@page : left {}': xml.dom.SyntaxErr,
     75              u'@page :left :right {}': xml.dom.SyntaxErr,
     76              u'@page :left a {}': xml.dom.SyntaxErr,
     77
     78              u'@page :left;': xml.dom.SyntaxErr,
     79              u'@page :left }': xml.dom.SyntaxErr,
     80              }
     81          self.do_raise_p(tests) # parse
     82          tests.update({
     83              u'@page :left {': xml.dom.SyntaxErr, # no }
     84              })
     85          self.do_raise_r(tests) # set cssText
     86
     87 -    def test_selectorText(self):
     88          "CSSPageRule.selectorText"
     89          tests = {
     90              u'': u'',
     91              u':left': None,
     92              u':right': None,
     93              u':first': None,
     94              u':UNKNOWNIDENT': None,
     95
     96              u' :left': u':left',
     97              u':left': u':left',
     98              u'/*1*/:left/*a*/': u':left',
     99              u'/*1*/ :left /*a*/ /*b*/': u':left',
    100              u':left/*a*/': u':left',
    101              u'/*1*/:left': u':left',
    102              }
    103          self.do_equal_r(tests, att='selectorText')
    104
    105          tests = {
    106              u':': xml.dom.SyntaxErr,
    107              u':/*1*/left': xml.dom.SyntaxErr,
    108              u': left': xml.dom.SyntaxErr,
    109              u':left :right': xml.dom.SyntaxErr,
    110              u':left a': xml.dom.SyntaxErr,
    111              }
    112          self.do_raise_r(tests, att='_setSelectorText')
    113
    114 -    def test_style(self):
    115          "CSSPageRule.style"
    116          d = cssutils.css.CSSStyleDeclaration()
    117          self.r.style = d
    118          self.assertEqual(d, self.r.style)
    119          self.assertEqual(self.r, d.parentRule)
    120
    121 -    def test_properties(self):
    122          "CSSPageRule.style properties"
    123          r = cssutils.css.CSSPageRule()
    124          r.style.cssText = '''
    125          margin-top: 0;
    126          margin-right: 0;
    127          margin-bottom: 0;
    128          margin-left: 0;
    129          margin: 0;
    130
    131          page-break-before: auto;
    132          page-break-after: auto;
    133          page-break-inside: auto;
    134
    135          orphans: 3;
    136          widows: 3;
    137          '''
    138          exp = u'''@page {
    139      margin-top: 0;
    140      margin-right: 0;
    141      margin-bottom: 0;
    142      margin-left: 0;
    143      margin: 0;
    144      page-break-before: auto;
    145      page-break-after: auto;
    146      page-break-inside: auto;
    147      orphans: 3;
    148      widows: 3
    149      }'''
    150          self.assertEqual(exp, r.cssText)
    151
    152 -    def test_reprANDstr(self):
    153          "CSSPageRule.__repr__(), .__str__()"
    154          sel=u':left'
    155
    156          s = cssutils.css.CSSPageRule(selectorText=sel)
    157
    158          self.assert_(sel in str(s))
    159
    160          s2 = eval(repr(s))
    161          self.assert_(isinstance(s2, s.__class__))
    162          self.assert_(sel == s2.selectorText)
    163
    164
    165  if __name__ == '__main__':
    166      import unittest
    167      unittest.main()
    168