#NEWLINE# def testParseIndex( self ) : #NEWLINE# #INDENT# 'Test reading and index and parsing to index and compiled tables.' #NEWLINE# file_path = os . path . join ( 'testdata' , 'parseindex_index' ) #NEWLINE# indx = clitable . IndexTable ( file_path = file_path ) #NEWLINE# self . failUnlessEqual ( indx . index . size , 3 ) #NEWLINE# self . failUnlessEqual ( indx . index [ 2 ] [ 'Template' ] , 'clitable_templateC' ) #NEWLINE# self . failUnlessEqual ( indx . index [ 3 ] [ 'Template' ] , 'clitable_templateD' ) #NEWLINE# self . failUnlessEqual ( indx . index [ 1 ] [ 'Command' ] , 'sh[[ow]] ve[[rsion]]' ) #NEWLINE# self . failUnlessEqual ( indx . index [ 1 ] [ 'Hostname' ] , '.*' ) #NEWLINE# self . failUnlessEqual ( indx . compiled . size , 3 ) #NEWLINE# for col in ( 'Command' , 'Vendor' , 'Template' , 'Hostname' ) : #NEWLINE# #INDENT# self . failUnless ( isinstance ( indx . compiled [ 1 ] [ col ] , copyable_regex_object . CopyableRegexObject ) ) #NEWLINE# #UNINDENT# self . failUnless ( indx . compiled [ 1 ] [ 'Hostname' ] . match ( 'random string' ) ) #NEWLINE# def _PreParse( key , value ) : #NEWLINE# #INDENT# if ( key == 'Template' ) : #NEWLINE# #INDENT# return value . upper ( ) #NEWLINE# #UNINDENT# return value #NEWLINE# #UNINDENT# def _PreCompile( key , value ) : #NEWLINE# #INDENT# if ( key in ( 'Template' , 'Command' ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# return value #NEWLINE# #UNINDENT# self . failUnlessEqual ( indx . compiled . size , 3 ) #NEWLINE# indx = clitable . IndexTable ( _PreParse , _PreCompile , file_path ) #NEWLINE# self . failUnlessEqual ( indx . index [ 2 ] [ 'Template' ] , 'CLITABLE_TEMPLATEC' ) #NEWLINE# self . failUnlessEqual ( indx . index [ 1 ] [ 'Command' ] , 'sh[[ow]] ve[[rsion]]' ) #NEWLINE# self . failUnless ( isinstance ( indx . compiled [ 1 ] [ 'Hostname' ] , copyable_regex_object . CopyableRegexObject ) ) #NEWLINE# self . failIf ( indx . compiled [ 1 ] [ 'Command' ] )