# HG changeset patch # User Catherine Devlin # Date 1238778156 14400 # Node ID e81378f82c7cb063dd1b3c6f2ff377a753c55ff1 # Parent 57070e181cf7fd227ae7f0e030d8a893a4bbb6ab transcript tests with regex now work smoothly diff -r 57070e181cf7 -r e81378f82c7c cmd2.py --- a/cmd2.py Fri Apr 03 12:47:13 2009 -0400 +++ b/cmd2.py Fri Apr 03 13:02:36 2009 -0400 @@ -1122,20 +1122,11 @@ 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 @@ 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 @@ 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):