<s> """<STR_LIT>""" <EOL> __author__ = ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> import re <EOL> import gflags as flags <EOL> import unittest as googletest <EOL> from closure_linter . common import erroraccumulator <EOL> class AnnotatedFileTestCase ( googletest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> _MESSAGE = { '<STR_LIT>' : '<STR_LIT>' } <EOL> _EXPECTED_RE = re . compile ( r'<STR_LIT>' <EOL> r'<STR_LIT>' % _MESSAGE ) <EOL> def __init__ ( self , filename , lint_callable , converter ) : <EOL> """<STR_LIT>""" <EOL> googletest . TestCase . __init__ ( self , '<STR_LIT>' ) <EOL> self . _filename = filename <EOL> self . _messages = [ ] <EOL> self . _lint_callable = lint_callable <EOL> self . _converter = converter <EOL> def setUp ( self ) : <EOL> flags . FLAGS . dot_on_next_line = True <EOL> def tearDown ( self ) : <EOL> flags . FLAGS . dot_on_next_line = False <EOL> def shortDescription ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % self . _filename <EOL> def runTest ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> filename = self . _filename <EOL> stream = open ( filename ) <EOL> except IOError as ex : <EOL> raise IOError ( '<STR_LIT>' % <EOL> ( self . _filename , ex ) ) <EOL> expected = self . _GetExpectedMessages ( stream ) <EOL> got = self . _ProcessFileAndGetMessages ( filename ) <EOL> self . assertEqual ( expected , got ) <EOL> def _GetExpectedMessages ( self , stream ) : <EOL> """<STR_LIT>""" <EOL> messages = [ ] <EOL> for i , line in enumerate ( stream ) : <EOL> match = self . _EXPECTED_RE . search ( line ) <EOL> if match : <EOL> line = match . group ( '<STR_LIT>' ) <EOL> msg_ids = match . group ( '<STR_LIT>' ) <EOL> if line is None : <EOL> line = i + <NUM_LIT:1> <EOL> elif line . startswith ( '<STR_LIT:+>' ) or line . startswith ( '<STR_LIT:->' ) : <EOL> line = i + <NUM_LIT:1> + int ( line ) <EOL> else : <EOL> line = int ( line ) <EOL> for msg_id in msg_ids . split ( '<STR_LIT:U+002C>' ) : <EOL> if msg_id != '<STR_LIT>' : <EOL> messages . append ( ( line , self . _converter ( msg_id . strip ( ) ) ) ) <EOL> stream . seek ( <NUM_LIT:0> ) <EOL> messages . sort ( ) <EOL> return messages <EOL> def _ProcessFileAndGetMessages ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> error_accumulator = erroraccumulator . ErrorAccumulator ( ) <EOL> self . _lint_callable ( filename , error_accumulator ) <EOL> errors = error_accumulator . GetErrors ( ) <EOL> error_msgs = [ ( error . token . line_number , error . code ) for error in errors ] <EOL> error_msgs . sort ( ) <EOL> return error_msgs </s>
