summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Douard <david.douard@logilab.fr>2008-05-16 12:43:45 +0200
committerDavid Douard <david.douard@logilab.fr>2008-05-16 12:43:45 +0200
commit75ae05dbbd6d348fa5160160c0369e89f8ffb8c5 (patch)
tree67bfffb7c3a55dbb800f6db945f0f6173a536808
parentfdfda1ab165bbbd9e1d5c84bfca0271b7ce442e7 (diff)
downloadlogilab-common-75ae05dbbd6d348fa5160160c0369e89f8ffb8c5.tar.gz
make 'assertTextEquals' method check that given parameter are strings
-rw-r--r--test/unittest_testlib.py5
-rw-r--r--testlib.py9
2 files changed, 13 insertions, 1 deletions
diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py
index d53c239..2349001 100644
--- a/test/unittest_testlib.py
+++ b/test/unittest_testlib.py
@@ -156,6 +156,11 @@ class TestlibTC(TestCase):
self.assertRaises(AssertionError, self.tc.assertStreamEqual, stream1, stream2)
def test_text_equality(self):
+ self.assertRaises(AssertionError, self.tc.assertTextEqual, "toto", 12)
+ 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")
+
foo = join(dirname(__file__), 'data', 'foo.txt')
spam = join(dirname(__file__), 'data', 'spam.txt')
text1 = file(foo).read()
diff --git a/testlib.py b/testlib.py
index a9acdad..023912c 100644
--- a/testlib.py
+++ b/testlib.py
@@ -1097,7 +1097,7 @@ class TestCase(unittest.TestCase):
if d1:
msgs.append('d2 is lacking %r' % d1)
if msgs:
- self.fail('\n'.join(msgs))
+ self.fail(''.join(msgs))
assertDictEqual = assertDictEquals
def assertSetEquals(self, got, expected, msg=None):
@@ -1183,6 +1183,13 @@ class TestCase(unittest.TestCase):
def assertTextEquals(self, text1, text2, junk=None):
"""compare two multiline strings (using difflib and splitlines())"""
+ msg = []
+ if not isinstance(text1, basestring):
+ msg.append('text1 is not a string (%s)'%(type(text1)))
+ if not isinstance(text2, basestring):
+ msg.append('text2 is not a string (%s)'%(type(text2)))
+ if msg:
+ self.fail('\n'.join(msg))
self._difftext(text1.splitlines(True), text2.splitlines(True), junk)
assertTextEqual = assertTextEquals