Mercurial > python-cmd2
comparison cmd2.py @ 174:471318e59e51
still small glitch breaking up tests
author | catherine@dellzilla |
---|---|
date | Fri, 12 Dec 2008 15:12:37 -0500 |
parents | 10a45c030364 |
children | 72de7d8566e2 |
comparison
equal
deleted
inserted
replaced
173:10a45c030364 | 174:471318e59e51 |
---|---|
388 multilineCommand.setParseAction(lambda x: x[0].lower()) | 388 multilineCommand.setParseAction(lambda x: x[0].lower()) |
389 oneLineCommand.setParseAction(lambda x: x[0].lower()) | 389 oneLineCommand.setParseAction(lambda x: x[0].lower()) |
390 if self.blankLinesAllowed: | 390 if self.blankLinesAllowed: |
391 blankLineTerminationParser = pyparsing.NoMatch | 391 blankLineTerminationParser = pyparsing.NoMatch |
392 else: | 392 else: |
393 blankLineTerminator = (pyparsing.Literal('\n') + stringEnd)('terminator') | 393 blankLineTerminator = (pyparsing.Literal('\n')('terminator') + stringEnd) |
394 blankLineTerminationParser = ((multilineCommand ^ oneLineCommand) + pyparsing.SkipTo(blankLineTerminator).setParseAction(lambda x: x[0].strip())('args') + blankLineTerminator)('statement') | 394 blankLineTerminationParser = ((multilineCommand ^ oneLineCommand) + pyparsing.SkipTo(blankLineTerminator).setParseAction(lambda x: x[0].strip())('args') + blankLineTerminator)('statement') |
395 multilineParser = (((multilineCommand ^ oneLineCommand) + pyparsing.SkipTo(terminatorParser).setParseAction(lambda x: x[0].strip())('args') + terminatorParser)('statement') + | 395 multilineParser = (((multilineCommand ^ oneLineCommand) + pyparsing.SkipTo(terminatorParser).setParseAction(lambda x: x[0].strip())('args') + terminatorParser)('statement') + |
396 pyparsing.SkipTo(outputParser ^ pipe ^ stringEnd).setParseAction(lambda x: x[0].strip())('suffix') + afterElements) | 396 pyparsing.SkipTo(outputParser ^ pipe ^ stringEnd).setParseAction(lambda x: x[0].strip())('suffix') + afterElements) |
397 singleLineParser = ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') + | 397 singleLineParser = ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') + |
398 pyparsing.Optional(terminatorParser) + afterElements) | 398 pyparsing.Optional(terminatorParser) + afterElements) |
399 self.parser = ( | 399 self.parser = ( |
400 stringEnd | | 400 stringEnd | |
401 blankLineTerminationParser | | |
402 multilineParser | | 401 multilineParser | |
403 multilineCommand + pyparsing.SkipTo(stringEnd) | | 402 multilineCommand + pyparsing.SkipTo(stringEnd) | |
404 singleLineParser | 403 singleLineParser | |
404 blankLineTerminationParser | |
405 ) | 405 ) |
406 self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) | 406 self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) |
407 | 407 |
408 inputMark = pyparsing.Literal('<') | 408 inputMark = pyparsing.Literal('<') |
409 inputMark.setParseAction(lambda x: '') | 409 inputMark.setParseAction(lambda x: '') |
903 responseStart = None | 903 responseStart = None |
904 prompt = self.cmdapp.prompt.rstrip() | 904 prompt = self.cmdapp.prompt.rstrip() |
905 continuationPrompt = self.cmdapp.continuationPrompt.rstrip() | 905 continuationPrompt = self.cmdapp.continuationPrompt.rstrip() |
906 for (lineNum, line) in enumerate(self.transcript): | 906 for (lineNum, line) in enumerate(self.transcript): |
907 if line.startswith(prompt): | 907 if line.startswith(prompt): |
908 if commandStart == lineNum - 1: | |
909 responseStart = lineNum | |
908 if responseStart is not None: | 910 if responseStart is not None: |
909 self.dialogue.append(commandStart, ''.join(command), ''.join(self.transcript[responseStart:lineNum])) | 911 self.dialogue.append((commandStart, ''.join(command), ''.join(self.transcript[responseStart:lineNum]))) |
910 command = [line[len(prompt):]] | 912 command = [line[len(prompt)+1:]] |
911 commandStart = lineNum | 913 commandStart = lineNum |
912 elif line.startswith(continuationPrompt): | 914 elif line.startswith(continuationPrompt): |
913 command.append(line[len(continuationPrompt):]) | 915 command.append(line[len(continuationPrompt)+1:]) |
914 else: | 916 else: |
915 if responseStart < commandStart: | 917 if responseStart < commandStart: |
916 responseStart = lineNum | 918 responseStart = lineNum |
917 def testall(self): | 919 def testall(self): |
918 if self.CmdApp: | 920 if self.CmdApp: |
919 self.divideTranscript() | 921 self.divideTranscript() |
920 for (lineNum, command, expected) in self.dialogue: | 922 for (lineNum, command, expected) in self.dialogue: |
921 self.cmdapp.onecmd(commandSlice) | 923 self.cmdapp.onecmd(command) |
922 result = self.outputTrap.read() | 924 result = self.outputTrap.read() |
923 self.assertEqual(result, expected, | 925 self.assertEqual(result.strip(), expected.strip(), |
924 '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n' % | 926 '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n' % |
925 (self.transcriptFileName, lineNum, command, expected, result)) | 927 (self.transcriptFileName, lineNum, command, expected, result)) |
926 def tearDown(self): | 928 def tearDown(self): |
927 if self.CmdApp: | 929 if self.CmdApp: |
928 self.outputTrap.tearDown() | 930 self.outputTrap.tearDown() |