Show
Ignore:
Timestamp:
01/15/09 07:38:25 (19 months ago)
Author:
Ga?tan de Menten <ged@…>
Branch:
default
Message:

- simplified and optimized opening/closing tags matching code, and moved it

into the _relatorio_statements method

- optimized genshi tags replacement loop (common ancestor block)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • relatorio/tests/test_odt.py

    r81 r89  
    1212# This program is distributed in the hope that it will be useful, but WITHOUT 
    1313# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    14 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more  
     14# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
    1515# details. 
    1616# 
     
    3737    catalog = {'Mes collègues sont:': 'My collegues are:', 
    3838               'Bonjour,': 'Hello,', 
    39                'Je suis un test de templating en odt.':  
     39               'Je suis un test de templating en odt.': 
    4040                'I am an odt templating test', 
    4141               'Felix da housecat': unicode('Félix le chat de la maison', 
     
    5555                     'last_name': unicode('Møller', 'utf8'), 
    5656                     'ville': unicode('Liège', 'utf8'), 
    57                      'friends': [{'first_name': u'Camille',  
     57                     'friends': [{'first_name': u'Camille', 
    5858                                  'last_name': u'Salauhpe'}, 
    5959                                 {'first_name': u'Mathias', 
     
    8181        <text:a xlink:href="relatorio://foo">foo</text:a> 
    8282        </b:a>''' % 'urn:text' 
    83         parsed = self.oot.insert_directives(xml)  
     83        parsed = self.oot.insert_directives(xml) 
    8484        root = lxml.etree.parse(StringIO(xml)).getroot() 
    8585        root_parsed = lxml.etree.parse(parsed).getroot() 
    86         eq_(root_parsed[0].attrib['{http://genshi.edgewall.org/}replace'],  
     86        eq_(root_parsed[0].attrib['{http://genshi.edgewall.org/}replace'], 
    8787            'foo') 
    8888 
     
    144144    def test_regexp(self): 
    145145        "Testing the regexp used to find relatorio tags" 
    146         regexp = re.compile(GENSHI_EXPR) 
    147         group = regexp.match('for each="foo in bar"').groups() 
    148         eq_(group, ('for each="foo in bar"', None, 'for', ' each="foo in bar"', 
    149                     'each', 'foo in bar')) 
    150         group = regexp.match('foreach="foo in bar"').groups() 
    151         eq_(group, ('foreach="foo in bar"', None, None, None, None, None)) 
    152         group = regexp.match('/for').groups() 
    153         eq_(group, ('/for', '/', 'for', '', None, None)) 
    154         group = regexp.match('/for ').groups() 
    155         eq_(group, ('/for ', '/', 'for', '', None, None)) 
    156         group = regexp.match('formatLang("en")').groups() 
    157         eq_(group, ('formatLang("en")', None, None, None, None, None)) 
     146        # a valid expression 
     147        group = GENSHI_EXPR.match('for each="foo in bar"').groups() 
     148        eq_(group, (None, 'for', 'each', 'foo in bar')) 
     149 
     150        # invalid expr 
     151        group = GENSHI_EXPR.match('foreach="foo in bar"').groups() 
     152        eq_(group, (None, None, None, None)) 
     153 
     154        # valid closing tags 
     155        group = GENSHI_EXPR.match('/for').groups() 
     156        eq_(group, ('/', 'for', None, None)) 
     157        group = GENSHI_EXPR.match('/for ').groups() 
     158        eq_(group, ('/', 'for', None, None)) 
     159 
     160        # another non matching expr 
     161        group = GENSHI_EXPR.match('formatLang("en")').groups() 
     162        eq_(group, (None, None, None, None)) 
    158163 
    159164    def test_str(self):