Esempio n. 1
0
    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' )
Esempio n. 2
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
    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
Esempio n. 6
0
    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')