def _test_execute( self, type, testcontent, count, ref='', cfunc=None ) : # Initialising the parser etparser = ETParser( lex_optimize=True, yacc_optimize=False ) # The first character is forced to be a `A` to avoid having `@` as the # first character testcontent = 'A' + testcontent # Characterize the generated testcontent set the wikiproperties wikiprops = {} testcontent = ( "@ %s " % wikiprops ) + '\n' + testcontent # Test by comparing the dumps try : tu = etparser.parse( testcontent, debuglevel=0 ) result = tu.dump()[:-1] except : tu = etparser.parse( testcontent, debuglevel=2 ) result = tu.dump()[:-1] # The reference is computed if no compare function (cfunc) is passed. if cfunc : cfunc( ref, tu ) else : ref = ref or testcontent ref = etparser._wiki_preprocess( ref ) props, ref = wiki_properties( ref ) if result != ref : print ''.join(diff.ndiff( result.splitlines(1), ref.splitlines(1) )) assert result == ref, type+'... testcount %s'%count
def _test_execute(self, type, testcontent, count, ref=''): # Initialising the parser etparser = ETParser(lex_optimize=True, yacc_optimize=False) # The first character is forced to be a `A` to avoid having `@` as the # first character testcontent = 'A' + testcontent # Prepare the reference. ref = ref or testcontent ref = etparser._wiki_preprocess(ref) props, ref = wiki_properties(ref) # Characterize the generated testcontent set the wikiproperties wikiprops = {} testcontent = ("@ %s " % wikiprops) + '\n' + testcontent # Test by comparing the dumps try: tu = etparser.parse(testcontent, debuglevel=0) result = tu.dump()[:-1] except: # open( 'testcontent', 'w' ).write( testcontent ) tu = etparser.parse(testcontent, debuglevel=2) result = tu.dump()[:-1] if result != ref: # open( 'result', 'w' ).write( result ) # open( 'ref', 'w' ).write( ref ) print ''.join(diff.ndiff(result.splitlines(1), ref.splitlines(1))) assert result == ref, type + '... testcount %s' % count
def _test_execute(self, type, testcontent, count, ref="", cfunc=None): # Initialising the parser etparser = ETParser(lex_optimize=True, yacc_optimize=False) # The first character is forced to be a `A` to avoid having `@` as the # first character testcontent = "A" + testcontent # Characterize the generated testcontent set the wikiproperties wikiprops = {} testcontent = ("@ %s " % wikiprops) + "\n" + testcontent # Test by comparing the dumps try: tu = etparser.parse(testcontent, debuglevel=0) result = tu.dump()[:-1] except: tu = etparser.parse(testcontent, debuglevel=2) result = tu.dump()[:-1] # The reference is computed if no compare function (cfunc) is passed. if cfunc: cfunc(ref, tu) else: ref = ref or testcontent ref = etparser._wiki_preprocess(ref) props, ref = wiki_properties(ref) if result != ref: print "".join(diff.ndiff(result.splitlines(1), ref.splitlines(1))) assert result == ref, type + "... testcount %s" % count
def _test_execute( self, type, testcontent, count, ref='' ) : # Initialising the parser etparser = ETParser( lex_optimize=True, yacc_optimize=False ) # The first character is forced to be a `A` to avoid having `@` as the # first character testcontent = 'A' + testcontent # Prepare the reference. ref = ref or testcontent ref = etparser._wiki_preprocess( ref ) props, ref = wiki_properties( ref ) # Characterize the generated testcontent set the wikiproperties wikiprops = {} testcontent = ( "@ %s " % wikiprops ) + '\n' + testcontent # Test by comparing the dumps try : tu = etparser.parse( testcontent, debuglevel=0 ) result = tu.dump()[:-1] except : # open( 'testcontent', 'w' ).write( testcontent ) tu = etparser.parse( testcontent, debuglevel=2 ) result = tu.dump()[:-1] if result != ref : # open( 'result', 'w' ).write( result ) # open( 'ref', 'w' ).write( ref ) print ''.join(diff.ndiff( result.splitlines(1), ref.splitlines(1) )) assert result == ref, type+'... testcount %s'%count
def test_2_parsermethods( self ) : """Testing methods provided by parsers""" log.info( "Testing methods provided by parsers" ) # wiki_properties() refprop = { 'a': 1, 'b': 2 } etp = ETParser(lex_optimize=True, yacc_optimize=False, yacc_debug=False) prop, text = wiki_properties( wikiproptext1 ) assert_equal( prop, {}, 'Mismatch in `prop` for `wikiproptext1`' ) assert_equal( text, 'hello world\n', 'Mismatch in `text` for `wikiproptext1`' ) prop, text = wiki_properties( wikiproptext2 ) assert_equal( prop, refprop, 'Mismatch in `prop` for `wikiproptext2`' ) assert_equal( text, '\nhello world\n', 'Mismatch in `text` for `wikiproptext1`' ) prop, text = wiki_properties( wikiproptext3 ) assert_equal( prop, refprop, 'Mismatch in `prop` for `wikiproptext3`' ) assert_equal( text, 'hello world\n', 'Mismatch in `text` for `wikiproptext3`' ) # Check style agreegation etp = ETParser( style={ 'border' : '1px solid gray', 'margin-top' : '10px', 'style' : { 'display' : 'block', 'style' : 'margin-left : 10px' }, }, lex_optimize=True, yacc_optimize=False, yacc_debug=False ) etp.parse( aggr_wikiprop ) refstyle = 'border : 1px solid gray; display : block; ' + \ 'margin-left : 10px; color : brown; font-style : italic; ' +\ 'margin-top : 5px' assert_equal( sorted(etp.styleattr), sorted(refstyle), 'Mismatch in style aggregation' )
def html( self, node, igen, *args, **kwargs ) : from eazytext.parser import ETParser fn = lambda (k, v) : '%s : %s' % (k,v) boxstyle = '; '.join(map( fn, self.css.items() )) if self.style : boxstyle += '; %s ;' % self.style titlestyle = '; '.join(map( fn, self.title_css.items() )) if self.titlestyle : titlestyle += '; %s ;' % self.titlestyle contstyle = '; '.join(map( fn, self.cont_css.items() )) if self.contentstyle : contstyle += '; %s ;' % self.contentstyle self.nowiki_h = '' if self.nowiki : etparser = ETParser( skin=None, nested=True, lex_optimize=False, yacc_optimize=False, ) tu = etparser.parse( self.nowiki, debuglevel=0 ) self.nowiki_h = tu.tohtml() if self.title : html = tmpl % ( boxstyle, titlestyle, self.title, spantmpl, contstyle, self.nowiki_h ) else : html = tmpl % ( boxstyle, titlestyle, self.title, '', contstyle, self.nowiki_h ) return html
def html(self, node, igen, *args, **kwargs): from eazytext.parser import ETParser fn = lambda (k, v): '%s : %s' % (k, v) boxstyle = '; '.join(map(fn, self.css.items())) if self.style: boxstyle += '; %s ;' % self.style titlestyle = '; '.join(map(fn, self.title_css.items())) if self.titlestyle: titlestyle += '; %s ;' % self.titlestyle contstyle = '; '.join(map(fn, self.cont_css.items())) if self.contentstyle: contstyle += '; %s ;' % self.contentstyle self.nowiki_h = '' if self.nowiki: etparser = ETParser( skin=None, nested=True, lex_optimize=False, yacc_optimize=False, ) tu = etparser.parse(self.nowiki, debuglevel=0) self.nowiki_h = tu.tohtml() if self.title: html = tmpl % (boxstyle, titlestyle, self.title, spantmpl, contstyle, self.nowiki_h) else: html = tmpl % (boxstyle, titlestyle, self.title, '', contstyle, self.nowiki_h) return html
def test_2_parsermethods(self): """Testing methods provided by parsers""" log.info("Testing methods provided by parsers") # wiki_properties() refprop = {'a': 1, 'b': 2} etp = ETParser(lex_optimize=True, yacc_optimize=False, yacc_debug=False) prop, text = wiki_properties(wikiproptext1) assert_equal(prop, {}, 'Mismatch in `prop` for `wikiproptext1`') assert_equal(text, 'hello world\n', 'Mismatch in `text` for `wikiproptext1`') prop, text = wiki_properties(wikiproptext2) assert_equal(prop, refprop, 'Mismatch in `prop` for `wikiproptext2`') assert_equal(text, '\nhello world\n', 'Mismatch in `text` for `wikiproptext1`') prop, text = wiki_properties(wikiproptext3) assert_equal(prop, refprop, 'Mismatch in `prop` for `wikiproptext3`') assert_equal(text, 'hello world\n', 'Mismatch in `text` for `wikiproptext3`') # Check style agreegation etp = ETParser(style={ 'border': '1px solid gray', 'margin-top': '10px', 'style': { 'display': 'block', 'style': 'margin-left : 10px' }, }, lex_optimize=True, yacc_optimize=False, yacc_debug=False) etp.parse(aggr_wikiprop) refstyle = 'border : 1px solid gray; display : block; ' + \ 'margin-left : 10px; color : brown; font-style : italic; ' +\ 'margin-top : 5px' assert_equal(sorted(etp.styleattr), sorted(refstyle), 'Mismatch in style aggregation')