comparison cmd2.py @ 117:33cd0e1bebb8

stripping continuation prompts during testing
author catherine@dellzilla
date Tue, 28 Oct 2008 14:05:12 -0400
parents 7d215852f9a6
children fe47c5b269cc
comparison
equal deleted inserted replaced
116:06f5eba2f588 117:33cd0e1bebb8
759 self.cmdapp = self.CmdApp() 759 self.cmdapp = self.CmdApp()
760 self.transcriptReader = TranscriptReader(self.cmdapp, self.transcriptFileName) 760 self.transcriptReader = TranscriptReader(self.cmdapp, self.transcriptFileName)
761 def testall(self): 761 def testall(self):
762 if self.CmdApp: 762 if self.CmdApp:
763 for (cmdInput, lineNum) in self.transcriptReader.inputGenerator(): 763 for (cmdInput, lineNum) in self.transcriptReader.inputGenerator():
764 self.cmdapp.onecmd(cmdInput) 764 self.cmdapp.onecmd(cmdInput, assumeComplete=True)
765 result = self.outputTrap.read() 765 result = self.outputTrap.read()
766 expected = self.transcriptReader.nextExpected() 766 expected = self.transcriptReader.nextExpected()
767 self.assertEqual(self.stripByLine(result), self.stripByLine(expected), 767 self.assertEqual(self.stripByLine(result), self.stripByLine(expected),
768 '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n' % 768 '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n' %
769 (self.transcriptFileName, lineNum, cmdInput, expected, result)) 769 (self.transcriptFileName, lineNum, cmdInput, expected, result))
770 def stripByLine(self, s): 770 def stripByLine(self, s):
771 lines = s.splitlines() 771 bareprompt = self.cmdapp.continuationPrompt.strip()
772 return '\n'.join(line.rstrip() for line in lines).strip() 772 lines = (line.rstrip() for line in s.splitlines())
773 lines = ( line.replace(bareprompt, '', 1)
774 if line.startswith(bareprompt)
775 else line
776 for line in lines)
777 return '\n'.join(lines).strip()
773 def tearDown(self): 778 def tearDown(self):
774 if self.CmdApp: 779 if self.CmdApp:
775 self.outputTrap.tearDown() 780 self.outputTrap.tearDown()
776 781
777 if __name__ == '__main__': 782 if __name__ == '__main__':