Changeset 126:386be867715c

Show
Ignore:
Timestamp:
04/16/09 04:06:50 (16 months ago)
Author:
Ga?tan de Menten <ged@…>
Branch:
default
Message:

- simplified test_directives test
- added column looping test
- added text_outside_p test (closes #10)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • relatorio/tests/test_odt.py

    r99 r126  
    3232from genshi.template.eval import UndefinedError 
    3333 
    34 from templates.opendocument import Template, GENSHI_EXPR 
     34from templates.opendocument import Template, GENSHI_EXPR, GENSHI_URI, \ 
     35                                   RELATORIO_URI 
     36 
     37OO_TABLE_NS = "urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
    3538 
    3639def pseudo_gettext(string): 
     
    7679    def test_directives(self): 
    7780        "Testing the directives interpolation" 
    78         xml = '''<b:a xmlns:b="urn:b" xmlns:text="%s" xmlns:draw="urn:draw" 
    79         xmlns:table="urn:table" xmlns:office="urn:office" 
    80         xmlns:xlink="urn:xlink"> 
    81         <text:a xlink:href="relatorio://foo">foo</text:a> 
    82         </b:a>''' % 'urn:text' 
     81        xml = '''<xml xmlns:text="urn:text" xmlns:xlink="urn:xlink"> 
     82                    <text:a xlink:href="relatorio://foo">foo</text:a> 
     83                 </xml>''' 
    8384        interpolated = self.oot.insert_directives(xml) 
    8485        root_interpolated = lxml.etree.parse(interpolated).getroot() 
    85         root_attrs = root_interpolated[0].attrib 
    86         eq_(root_attrs['{http://genshi.edgewall.org/}replace'], 'foo') 
     86        child = root_interpolated[0] 
     87        eq_(child.get('{http://genshi.edgewall.org/}replace'), 'foo') 
     88 
     89    def test_column_looping(self): 
     90        xml = ''' 
     91<table:table 
     92    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
     93    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
     94    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
     95    xmlns:xlink="http://www.w3.org/1999/xlink" 
     96    table:name="Tableau1" 
     97    table:style-name="Tableau1"> 
     98    <table:table-column table:style-name="Tableau1.A" 
     99                        table:number-columns-repeated="2"/> 
     100    <table:table-column table:style-name="Tableau1.C"/> 
     101    <table:table-column table:style-name="Tableau1.A"/> 
     102    <table:table-column table:style-name="Tableau1.E"/> 
     103    <table:table-header-rows> 
     104        <table:table-row table:style-name="Tableau1.1"> 
     105            <table:table-cell table:style-name="Tableau1.A1" 
     106                              office:value-type="string"> 
     107                <text:p text:style-name="Table_20_Heading">Brol</text:p> 
     108            </table:table-cell> 
     109            <table:table-cell table:style-name="Tableau1.A1" 
     110                              office:value-type="string"> 
     111                <text:p text:style-name="Table_20_Heading"> 
     112                    <text:a xlink:type="simple" 
     113                            xlink:href="relatorio://for each=&quot;title in titles&quot;">for each=&quot;title in titles&quot;</text:a> 
     114                </text:p> 
     115            </table:table-cell> 
     116            <table:table-cell table:style-name="Tableau1.A1" 
     117                              office:value-type="string"> 
     118                <text:p text:style-name="Table_20_Heading">${title}</text:p> 
     119                <text:p text:style-name="Table_20_Heading"/> 
     120            </table:table-cell> 
     121            <table:table-cell table:style-name="Tableau1.A1" 
     122                              office:value-type="string"> 
     123                <text:p text:style-name="Table_20_Heading"> 
     124                    <text:a xlink:type="simple" 
     125                            xlink:href="relatorio:///for">/for</text:a> 
     126                </text:p> 
     127            </table:table-cell> 
     128            <table:table-cell table:style-name="Tableau1.E1" 
     129                              office:value-type="string"> 
     130                <text:p text:style-name="Table_20_Heading">Truc</text:p> 
     131            </table:table-cell> 
     132        </table:table-row> 
     133    </table:table-header-rows> 
     134    <table:table-row> 
     135        <table:table-cell table:style-name="Tableau1.A2" 
     136                          table:number-columns-spanned="5" 
     137                          office:value-type="string"> 
     138            <text:p text:style-name="Table_20_Contents"> 
     139                <text:a xlink:type="simple" 
     140                        xlink:href="relatorio://for%20each=%22items%20in%20lst%22">for each=&quot;items in lst&quot;</text:a> 
     141            </text:p> 
     142        </table:table-cell> 
     143        <table:covered-table-cell/> 
     144        <table:covered-table-cell/> 
     145        <table:covered-table-cell/> 
     146        <table:covered-table-cell/> 
     147    </table:table-row> 
     148    <table:table-row> 
     149        <table:table-cell table:style-name="Tableau1.A3" 
     150                          office:value-type="string"> 
     151            <text:p text:style-name="Table_20_Contents">Brol</text:p> 
     152        </table:table-cell> 
     153        <table:table-cell table:style-name="Tableau1.A3" 
     154                          office:value-type="string"> 
     155            <text:p text:style-name="Table_20_Contents"> 
     156                <text:a xlink:type="simple" 
     157                        xlink:href="relatorio://for%20each=%22item%20in%20items%22">for each=&quot;item in items&quot;</text:a> 
     158            </text:p> 
     159        </table:table-cell> 
     160        <table:table-cell table:style-name="Tableau1.A3" 
     161                          office:value-type="string"> 
     162            <text:p text:style-name="Table_20_Contents">${item}</text:p> 
     163            <text:p text:style-name="Table_20_Contents"/> 
     164        </table:table-cell> 
     165        <table:table-cell table:style-name="Tableau1.A3" 
     166                          office:value-type="string"> 
     167            <text:p text:style-name="Table_20_Contents"> 
     168                <text:a xlink:type="simple" 
     169                        xlink:href="relatorio:///for">/for</text:a> 
     170            </text:p> 
     171        </table:table-cell> 
     172        <table:table-cell table:style-name="Tableau1.A2" 
     173                          office:value-type="string"> 
     174            <text:p text:style-name="Table_20_Contents">Truc</text:p> 
     175        </table:table-cell> 
     176    </table:table-row> 
     177    <table:table-row> 
     178        <table:table-cell table:style-name="Tableau1.A2" 
     179                          table:number-columns-spanned="5" 
     180                          office:value-type="string"> 
     181            <text:p text:style-name="Table_20_Contents"> 
     182                <text:a xlink:type="simple" 
     183                        xlink:href="relatorio:///for">/for</text:a> 
     184            </text:p> 
     185        </table:table-cell> 
     186        <table:covered-table-cell/> 
     187        <table:covered-table-cell/> 
     188        <table:covered-table-cell/> 
     189        <table:covered-table-cell/> 
     190    </table:table-row> 
     191</table:table>''' 
     192        interpolated = self.oot.insert_directives(xml) 
     193        root = lxml.etree.parse(interpolated).getroot() 
     194        child2 = root[1] 
     195        eq_(child2.tag, "{%s}repeat" % RELATORIO_URI) 
     196        eq_(child2.get("closing"), "3") 
     197        eq_(child2.get("opening"), "1") 
     198        eq_(len(child2), 1) 
     199        child4 = root[3] 
     200        eq_(child4.tag, "{%s}table-header-rows" % OO_TABLE_NS) 
     201        row1 = child4[0] 
     202        ok_(row1.get("{%s}attrs" % GENSHI_URI) 
     203                .startswith('__relatorio_reset_col_count')) 
     204        eq_(len(row1), 4) 
     205        loop = row1[1] 
     206        eq_(loop.tag, "{%s}for" % GENSHI_URI) 
     207        cell = loop[0] 
     208        ok_(cell.get("{%s}attrs" % GENSHI_URI) 
     209                .startswith('__relatorio_inc_col_count')) 
     210        last_row_node = row1[3] 
     211        eq_(last_row_node.tag, "{%s}replace" % GENSHI_URI) 
     212        ok_(last_row_node.get("value") 
     213                         .startswith('__relatorio_store_col_count')) 
     214 
     215    def test_text_outside_p(self): 
     216        "Testing that the tail text of a directive node is handled properly" 
     217        xml = '''<xml xmlns:text="urn:text" xmlns:xlink="urn:xlink"> 
     218                    <text:a xlink:href="relatorio://if%20test=%22True%22">if test=&quot;True&quot;</text:a> 
     219                    xxx 
     220                    <text:p text:style-name="other">yyy</text:p> 
     221                    zzz 
     222                    <text:a xlink:href="relatorio:///if">/if</text:a> 
     223                 </xml>''' 
     224        interpolated = self.oot.insert_directives(xml) 
     225        root_interpolated = lxml.etree.parse(interpolated).getroot() 
     226        child = root_interpolated[0] 
     227        eq_(child.tag, '{http://genshi.edgewall.org/}if') 
     228        eq_(child.text.strip(), 'xxx') 
    87229 
    88230    def test_styles(self): 
     
    128270        images = root.xpath('//draw:frame', namespaces=self.oot.namespaces) 
    129271        eq_(len(images), 3) 
    130         eq_(images[0].attrib['{%s}name' % self.oot.namespaces['draw']], 
     272        eq_(images[0].get('{%s}name' % self.oot.namespaces['draw']), 
    131273            "image: (oeuf, 'image/png')") 
    132         eq_(images[1].attrib['{%s}name' % self.oot.namespaces['draw']], 
     274        eq_(images[1].get('{%s}name' % self.oot.namespaces['draw']), 
    133275            'image: img') 
    134         eq_(images[1].attrib['{%s}width' % self.oot.namespaces['svg']], 
     276        eq_(images[1].get('{%s}width' % self.oot.namespaces['svg']), 
    135277            '1.732cm') 
    136         eq_(images[1].attrib['{%s}height' % self.oot.namespaces['svg']], 
     278        eq_(images[1].get('{%s}height' % self.oot.namespaces['svg']), 
    137279            '1.513cm') 
    138         eq_(images[2].attrib['{%s}width' % self.oot.namespaces['svg']], 
     280        eq_(images[2].get('{%s}width' % self.oot.namespaces['svg']), 
    139281            '1.732cm') 
    140         eq_(images[2].attrib['{%s}height' % self.oot.namespaces['svg']], 
     282        eq_(images[2].get('{%s}height' % self.oot.namespaces['svg']), 
    141283            '1.513cm') 
    142284