Mercurial > python-cmd2
comparison cmd2.py @ 122:e62aa2f58b7b 0.4.1
now works Python 2.4 to Python 2.6
author | catherine@dellzilla |
---|---|
date | Wed, 29 Oct 2008 10:53:11 -0400 |
parents | fe432d010ecc |
children | fad4dde06be8 |
comparison
equal
deleted
inserted
replaced
121:fe432d010ecc | 122:e62aa2f58b7b |
---|---|
743 result = self.transcript[self.bookmark:self.bookmark+startpos] | 743 result = self.transcript[self.bookmark:self.bookmark+startpos] |
744 self.bookmark += startpos | 744 self.bookmark += startpos |
745 return result | 745 return result |
746 except StopIteration: | 746 except StopIteration: |
747 return self.transcript[self.bookmark:] | 747 return self.transcript[self.bookmark:] |
748 | 748 |
749 class Cmd2TestCase(unittest.TestCase): | 749 class Cmd2TestCase(unittest.TestCase): |
750 '''Subclass this, setting CmdApp and transcriptFileName, to make a unittest.TestCase class | 750 '''Subclass this, setting CmdApp and transcriptFileName, to make a unittest.TestCase class |
751 that will execute the commands in transcriptFileName and expect the results shown. | 751 that will execute the commands in transcriptFileName and expect the results shown. |
752 See example.py''' | 752 See example.py''' |
753 # problem: this (raw) case gets called by unittest.main - we don't want it to be. hmm | 753 # problem: this (raw) case gets called by unittest.main - we don't want it to be. hmm |
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 bareprompt = self.cmdapp.continuationPrompt.strip() | 771 bareprompt = self.cmdapp.continuationPrompt.strip() |
772 lines = (line.rstrip() for line in s.splitlines()) | 772 lines = [] |
773 lines = ( line.replace(bareprompt, '', 1) | 773 for line in s.splitlines(): |
774 if line.startswith(bareprompt) | 774 line = line.rstrip() |
775 else line | 775 if line.startswith(bareprompt): |
776 for line in lines) | 776 line = line.replace(bareprompt, '', 1) |
777 return '\n'.join(lines).strip() | 777 return '\n'.join(lines).strip() |
778 def tearDown(self): | 778 def tearDown(self): |
779 if self.CmdApp: | 779 if self.CmdApp: |
780 self.outputTrap.tearDown() | 780 self.outputTrap.tearDown() |
781 | 781 |