diff options
author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2010-04-29 18:30:15 +0200 |
---|---|---|
committer | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2010-04-29 18:30:15 +0200 |
commit | d4f2cc807a3acb9a5ca5e70d123bd834c8134484 (patch) | |
tree | 9468794f4a0dab5de5dafd0702538fc861786e51 | |
parent | 9205d8cf43ef7191dcbed9bb7cab4e85a1c4b8ba (diff) | |
download | logilab-common-d4f2cc807a3acb9a5ca5e70d123bd834c8134484.tar.gz |
[testlib] add option splitlines to assertTextEquals
-rw-r--r-- | test/unittest_testlib.py | 4 | ||||
-rw-r--r-- | testlib.py | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py index 75b9219..6f25ea5 100644 --- a/test/unittest_testlib.py +++ b/test/unittest_testlib.py @@ -218,7 +218,9 @@ class TestlibTC(TestCase): self.assertRaises(AssertionError, self.tc.assertTextEqual, "toto", None) self.assertRaises(AssertionError, self.tc.assertTextEqual, 3.12, u"toto") self.assertRaises(AssertionError, self.tc.assertTextEqual, None, u"toto") - + self.tc.assertTextEqual('toto\ntiti', 'toto\ntiti') + self.tc.assertTextEqual('toto\ntiti', 'toto\n titi\n', striplines=True) + self.assertRaises(AssertionError, self.tc.assertTextEqual, 'toto\ntiti', 'toto\n titi\n') foo = join(dirname(__file__), 'data', 'foo.txt') spam = join(dirname(__file__), 'data', 'spam.txt') text1 = file(foo).read() @@ -1491,7 +1491,7 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART) self.fail('\n'.join(['%s\n'%msg_prefix]+read + list(result))) def assertTextEquals(self, text1, text2, junk=None, - msg_prefix='Text differ'): + msg_prefix='Text differ', striplines=False): """compare two multiline strings (using difflib and splitlines())""" msg = [] if not isinstance(text1, basestring): @@ -1500,8 +1500,12 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART) msg.append('text2 is not a string (%s)'%(type(text2))) if msg: self.fail('\n'.join(msg)) - self._difftext(text1.strip().splitlines(True), text2.strip().splitlines(True), - junk, msg_prefix) + lines1 = text1.strip().splitlines(True) + lines2 = text2.strip().splitlines(True) + if striplines: + lines1 = [line.strip() for line in lines1] + lines2 = [line.strip() for line in lines2] + self._difftext(lines1, lines2, junk, msg_prefix) assertTextEqual = assertTextEquals def assertStreamEquals(self, stream1, stream2, junk=None, |