# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1230152626 18000 # Node ID 24eff658997b80cca9dc27491b048ba303b1af17 # Parent 951c124b04041f93531ffdbe49850f9cf0bc0451 accepts wildcards in tests, maybe? diff -r 951c124b0404 -r 24eff658997b cmd2.py --- a/cmd2.py Wed Dec 24 11:15:03 2008 -0500 +++ b/cmd2.py Wed Dec 24 16:03:46 2008 -0500 @@ -890,14 +890,14 @@ tfile.close() except IOError: self.transcript = [] - def assertEqualWithWildcards(self, got, expected, message): - got = got.strip() - expected = expected.strip() - try: - self.assertEqual(got, expected, message) - except AssertionError: - print 'ooh, this is bad' - raise + 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: lineNum = 0 @@ -915,7 +915,7 @@ self.cmdapp.onecmd(command) result = self.outputTrap.read() if line.startswith(self.cmdapp.prompt): - self.assertEqual(result.strip(), '', + self.assertEqualEnough(result.strip(), '', '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing) \nGot:\n%s\n' % (self.transcriptFileName, lineNum, command, result)) continue @@ -924,7 +924,7 @@ expected.append(line) line = self.transcript.next() expected = ''.join(expected) - self.assertEqual(expected.strip(), result.strip(), + self.assertEqualEnough(expected.strip(), result.strip(), '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n' % (self.transcriptFileName, lineNum, command, expected, result)) # this needs to account for a line-by-line strip()ping @@ -933,7 +933,6 @@ # catch the final output? def tearDown(self): if self.CmdApp: - self.tfile.close() self.outputTrap.tearDown() if __name__ == '__main__':