1import os 2import sys 3import antlr3 4import testbase 5import unittest 6from io import StringIO 7 8class t020fuzzy(testbase.ANTLRTest): 9 def setUp(self): 10 self.compileGrammar('t020fuzzyLexer.g') 11 12 13 def testValid(self): 14 inputPath = os.path.splitext(__file__)[0] + '.input' 15 with open(inputPath) as f: 16 stream = antlr3.StringStream(f.read()) 17 lexer = self.getLexer(stream) 18 19 while True: 20 token = lexer.nextToken() 21 if token.type == antlr3.EOF: 22 break 23 24 25 output = lexer.output.getvalue() 26 27 outputPath = os.path.splitext(__file__)[0] + '.output' 28 with open(outputPath) as f: 29 testOutput = f.read() 30 31 self.assertEqual(output, testOutput) 32 33 34if __name__ == '__main__': 35 unittest.main() 36