Mercurial > python-cmd2
comparison cmd2.py @ 409:130889170679
before changing StopIteration catch
author | Catherine Devlin <catherine.devlin@gmail.com> |
---|---|
date | Mon, 08 Nov 2010 04:27:13 -0500 |
parents | a53ba40b9848 |
children | 48ebbdfe9dd4 |
comparison
equal
deleted
inserted
replaced
408:a53ba40b9848 | 409:130889170679 |
---|---|
1482 lineNum = 0 | 1482 lineNum = 0 |
1483 try: | 1483 try: |
1484 line = transcript.next() | 1484 line = transcript.next() |
1485 lineNum += 1 | 1485 lineNum += 1 |
1486 while True: | 1486 while True: |
1487 # Scroll forward to where actual commands begin | |
1487 while not line.startswith(self.cmdapp.prompt): | 1488 while not line.startswith(self.cmdapp.prompt): |
1488 line = transcript.next() | 1489 line = transcript.next() |
1489 lineNum += 1 | 1490 lineNum += 1 |
1490 command = [line[len(self.cmdapp.prompt):]] | 1491 command = [line[len(self.cmdapp.prompt):]] |
1491 line = transcript.next() | 1492 line = transcript.next() |
1493 # Read the entirety of a multi-line command | |
1492 while line.startswith(self.cmdapp.continuation_prompt): | 1494 while line.startswith(self.cmdapp.continuation_prompt): |
1493 command.append(line[len(self.cmdapp.continuation_prompt):]) | 1495 command.append(line[len(self.cmdapp.continuation_prompt):]) |
1494 line = transcript.next() | 1496 line = transcript.next() |
1495 lineNum += 1 | 1497 lineNum += 1 |
1496 command = ''.join(command) | 1498 command = ''.join(command) |
1499 # Send the command into the application and capture the resulting output | |
1497 stop = self.cmdapp.onecmd_plus_hooks(command) | 1500 stop = self.cmdapp.onecmd_plus_hooks(command) |
1498 #TODO: should act on ``stop`` | 1501 #TODO: should act on ``stop`` |
1499 result = self.outputTrap.read() | 1502 result = self.outputTrap.read() |
1503 # Read the expected result from transcript | |
1500 if line.startswith(self.cmdapp.prompt): | 1504 if line.startswith(self.cmdapp.prompt): |
1501 message = '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing)\nGot:\n%s\n'%\ | 1505 message = '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing)\nGot:\n%s\n'%\ |
1502 (fname, lineNum, command, result) | 1506 (fname, lineNum, command, result) |
1503 self.assert_(not(result.strip()), message) | 1507 self.assert_(not(result.strip()), message) |
1504 continue | 1508 continue |
1506 while not line.startswith(self.cmdapp.prompt): | 1510 while not line.startswith(self.cmdapp.prompt): |
1507 expected.append(line) | 1511 expected.append(line) |
1508 line = transcript.next() | 1512 line = transcript.next() |
1509 lineNum += 1 | 1513 lineNum += 1 |
1510 expected = ''.join(expected) | 1514 expected = ''.join(expected) |
1515 # Compare actual result to expected | |
1511 message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\ | 1516 message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\ |
1512 (fname, lineNum, command, expected, result) | 1517 (fname, lineNum, command, expected, result) |
1513 expected = self.expectationParser.transformString(expected) | 1518 expected = self.expectationParser.transformString(expected) |
1514 # checking whitespace is a pain - let's skip it | 1519 # checking whitespace is a pain - let's skip it |
1515 expected = self.anyWhitespace.sub('', expected) | 1520 expected = self.anyWhitespace.sub('', expected) |