summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatherine Devlin <catherine.devlin@gmail.com>2009-04-03 13:02:36 -0400
committerCatherine Devlin <catherine.devlin@gmail.com>2009-04-03 13:02:36 -0400
commitb3af6b81c94457182202558c09f34088693485e4 (patch)
treee2354f13af177357153e515d88f1057a7546ae7a
parent8ff906d6eb94661a633b25a1bb83afcebedbb2d0 (diff)
downloadcmd2-hg-0.5.2.tar.gz
transcript tests with regex now work smoothly0.5.2
-rwxr-xr-xcmd2.py16
1 files changed, 3 insertions, 13 deletions
diff --git a/cmd2.py b/cmd2.py
index e633fd2..a6b5f18 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1122,20 +1122,11 @@ class Cmd2TestCase(unittest.TestCase):
tfile.close()
if not len(self.transcripts):
raise StandardError, "No test files found - nothing to test."
-
def setUp(self):
if self.CmdApp:
self.outputTrap = OutputTrap()
self.cmdapp = self.CmdApp()
self.fetchTranscripts()
- def assertEqualEnough(self, got, expected, message):
- got = got.strip().splitlines()
- expected = expected.strip().splitlines()
- self.assertEqual(len(got), len(expected), message)
- for (linegot, lineexpected) in zip(got, expected):
- matchme = re.escape(lineexpected.strip()).replace('\\*', '.*'). \
- replace('\\ ', ' ')
- self.assert_(re.match(matchme, linegot.strip()), message)
def testall(self):
if self.CmdApp:
its = sorted(self.transcripts.items())
@@ -1163,9 +1154,9 @@ class Cmd2TestCase(unittest.TestCase):
self.cmdapp.onecmd(command)
result = self.outputTrap.read().strip()
if line.startswith(self.cmdapp.prompt):
- self.assertEqualEnough(result, '',
- '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing) \nGot:\n%s\n' %
- (fname, lineNum, command, result))
+ message = '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing)\nGot:\n%s\n'%\
+ (fname, lineNum, command, result)
+ self.assert_(not(result.strip()), message)
continue
expected = []
while not line.startswith(self.cmdapp.prompt):
@@ -1177,7 +1168,6 @@ class Cmd2TestCase(unittest.TestCase):
expected = self.expectationParser.transformString(expected)
expected = self.endStrippingRegex.sub('\s*\n', expected)
self.assert_(re.match(expected, result, re.MULTILINE | re.DOTALL), message)
- # this needs to account for a line-by-line strip()ping
except StopIteration:
pass
def tearDown(self):