Mercurial > python-cmd2
comparison cmd2.py @ 402:be18c88a0fc8
report when end of transcript never seen
author | catherine.devlin@gmail.com |
---|---|
date | Sun, 07 Nov 2010 06:48:15 -0500 |
parents | 3397b9c199f5 |
children | cc5c68e15a83 |
comparison
equal
deleted
inserted
replaced
401:3397b9c199f5 | 402:be18c88a0fc8 |
---|---|
1480 anyWhitespace = re.compile(r'\s', re.DOTALL | re.MULTILINE) | 1480 anyWhitespace = re.compile(r'\s', re.DOTALL | re.MULTILINE) |
1481 def _test_transcript(self, fname, transcript): | 1481 def _test_transcript(self, fname, transcript): |
1482 lineNum = 0 | 1482 lineNum = 0 |
1483 try: | 1483 try: |
1484 line = transcript.next() | 1484 line = transcript.next() |
1485 lineNum += 1 | |
1485 while True: | 1486 while True: |
1486 while not line.startswith(self.cmdapp.prompt): | 1487 while not line.startswith(self.cmdapp.prompt): |
1487 line = transcript.next() | 1488 line = transcript.next() |
1489 lineNum += 1 | |
1488 command = [line[len(self.cmdapp.prompt):]] | 1490 command = [line[len(self.cmdapp.prompt):]] |
1489 line = transcript.next() | 1491 line = transcript.next() |
1490 while line.startswith(self.cmdapp.continuation_prompt): | 1492 while line.startswith(self.cmdapp.continuation_prompt): |
1491 command.append(line[len(self.cmdapp.continuation_prompt):]) | 1493 command.append(line[len(self.cmdapp.continuation_prompt):]) |
1492 line = transcript.next() | 1494 line = transcript.next() |
1495 lineNum += 1 | |
1493 command = ''.join(command) | 1496 command = ''.join(command) |
1494 stop = self.cmdapp.onecmd_plus_hooks(command) | 1497 stop = self.cmdapp.onecmd_plus_hooks(command) |
1495 #TODO: should act on ``stop`` | 1498 #TODO: should act on ``stop`` |
1496 result = self.outputTrap.read() | 1499 result = self.outputTrap.read() |
1497 if line.startswith(self.cmdapp.prompt): | 1500 if line.startswith(self.cmdapp.prompt): |
1501 continue | 1504 continue |
1502 expected = [] | 1505 expected = [] |
1503 while not line.startswith(self.cmdapp.prompt): | 1506 while not line.startswith(self.cmdapp.prompt): |
1504 expected.append(line) | 1507 expected.append(line) |
1505 line = transcript.next() | 1508 line = transcript.next() |
1509 lineNum += 1 | |
1506 expected = ''.join(expected) | 1510 expected = ''.join(expected) |
1507 message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\ | 1511 message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\ |
1508 (fname, lineNum, command, expected, result) | 1512 (fname, lineNum, command, expected, result) |
1509 expected = self.expectationParser.transformString(expected) | 1513 expected = self.expectationParser.transformString(expected) |
1510 # checking whitespace is a pain - let's skip it | 1514 # checking whitespace is a pain - let's skip it |
1511 expected = self.anyWhitespace.sub('', expected) | 1515 expected = self.anyWhitespace.sub('', expected) |
1512 result = self.anyWhitespace.sub('', result) | 1516 result = self.anyWhitespace.sub('', result) |
1513 self.assert_(re.match(expected, result, re.MULTILINE | re.DOTALL), message) | 1517 self.assert_(re.match(expected, result, re.MULTILINE | re.DOTALL), message) |
1514 except StopIteration: | 1518 except StopIteration: |
1515 pass | 1519 message = 'Last %d lines never seen, beginning with\n%s' % (len(expected), expected[0]) |
1520 self.assert_(len(expected) < 3, message) | |
1516 def tearDown(self): | 1521 def tearDown(self): |
1517 if self.CmdApp: | 1522 if self.CmdApp: |
1518 self.outputTrap.tearDown() | 1523 self.outputTrap.tearDown() |
1519 | 1524 |
1520 if __name__ == '__main__': | 1525 if __name__ == '__main__': |