Mercurial > python-cmd2
comparison cmd2.py @ 176:645467c0d3f9
cleanup unused code
author | catherine@dellzilla |
---|---|
date | Fri, 12 Dec 2008 15:29:28 -0500 |
parents | 72de7d8566e2 |
children | f2b1643b5173 |
comparison
equal
deleted
inserted
replaced
175:72de7d8566e2 | 176:645467c0d3f9 |
---|---|
872 self.trap.truncate(0) | 872 self.trap.truncate(0) |
873 return result.strip('\x00') | 873 return result.strip('\x00') |
874 def tearDown(self): | 874 def tearDown(self): |
875 sys.stdout = self.old_stdout | 875 sys.stdout = self.old_stdout |
876 | 876 |
877 class Transcript(object): | |
878 def __init__(self, cmdapp, filename='test_cmd2.txt'): | |
879 self.cmdapp = cmdapp | |
880 try: | |
881 tfile = open(filename) | |
882 self.transcript = tfile.readlines() | |
883 tfile.close() | |
884 except IOError: | |
885 self.transcript = [] | |
886 | |
887 class Cmd2TestCase(unittest.TestCase): | 877 class Cmd2TestCase(unittest.TestCase): |
888 '''Subclass this, setting CmdApp and transcriptFileName, to make a unittest.TestCase class | 878 '''Subclass this, setting CmdApp and transcriptFileName, to make a unittest.TestCase class |
889 that will execute the commands in transcriptFileName and expect the results shown. | 879 that will execute the commands in transcriptFileName and expect the results shown. |
890 See example.py''' | 880 See example.py''' |
891 CmdApp = None | 881 CmdApp = None |
898 tfile = open(self.transcriptFileName) | 888 tfile = open(self.transcriptFileName) |
899 self.transcript = tfile.readlines() | 889 self.transcript = tfile.readlines() |
900 tfile.close() | 890 tfile.close() |
901 except IOError: | 891 except IOError: |
902 self.transcript = [] | 892 self.transcript = [] |
903 def divideTranscript(self): | |
904 self.dialogue = [] | |
905 commandStart = None | |
906 responseStart = None | |
907 prompt = self.cmdapp.prompt.rstrip() | |
908 continuationPrompt = self.cmdapp.continuationPrompt.rstrip() | |
909 for (lineNum, line) in enumerate(self.transcript): | |
910 if line.startswith(prompt): | |
911 if commandStart == lineNum - 1: | |
912 responseStart = lineNum | |
913 if responseStart is not None: | |
914 self.dialogue.append((commandStart, ''.join(command), ''.join(self.transcript[responseStart:lineNum]))) | |
915 command = [line[len(prompt)+1:]] | |
916 commandStart = lineNum | |
917 elif line.startswith(continuationPrompt): | |
918 command.append(line[len(continuationPrompt)+1:]) | |
919 else: | |
920 if responseStart < commandStart: | |
921 responseStart = lineNum | |
922 def divideTranscript(self): | 893 def divideTranscript(self): |
923 self.dialogue = [] | 894 self.dialogue = [] |
924 commandStart = None | 895 commandStart = None |
925 response = [] | 896 response = [] |
926 command = [] | 897 command = [] |