diff --git a/linkcheck/tests/__init__.py b/linkcheck/tests/__init__.py index 1ba57acc..5149e17f 100644 --- a/linkcheck/tests/__init__.py +++ b/linkcheck/tests/__init__.py @@ -15,7 +15,23 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ -Unit tests for the linkcheck module. +Unit test utilities. """ -import linkcheck +import unittest + +class MsgTestCase (unittest.TestCase): + """ + A test case with improved inequality test. + """ + def failUnlessEqual (self, first, second, msg=None): + """ + Define the first argument as the test value, and the second + one as the excpected value. Adjust the default error message + accordingly. + """ + if msg is None: + msg = "got %r, expected %r" % (first, second) + super(MsgTestCase, self).failUnlessEqual(first, second, msg=msg) + + assertEqual = assertEquals = failUnlessEqual diff --git a/linkcheck/tests/test_containers.py b/linkcheck/tests/test_containers.py index 6bc7ca58..ee4118f0 100644 --- a/linkcheck/tests/test_containers.py +++ b/linkcheck/tests/test_containers.py @@ -21,9 +21,9 @@ Test container routines. import unittest import random import linkcheck.containers +from linkcheck.tests import MsgTestCase - -class TestListDict (unittest.TestCase): +class TestListDict (MsgTestCase): """ Test list dictionary routines. """ @@ -77,7 +77,7 @@ class TestListDict (unittest.TestCase): self.assertEqual(self.d[k], toinsert[i]) -class TestSetList (unittest.TestCase): +class TestSetList (MsgTestCase): """ Test set list routines. """ @@ -129,7 +129,7 @@ class TestSetList (unittest.TestCase): self.assertEqual(self.l[1], 3) -class TestLRU (unittest.TestCase): +class TestLRU (MsgTestCase): """ Test routines of LRU queue. """ diff --git a/linkcheck/tests/test_parser.py b/linkcheck/tests/test_parser.py index 0f3039f3..6d38d5fe 100644 --- a/linkcheck/tests/test_parser.py +++ b/linkcheck/tests/test_parser.py @@ -23,6 +23,7 @@ import linkcheck.HtmlParser.htmlsax import linkcheck.HtmlParser.htmllib import cStringIO as StringIO import unittest +from linkcheck.tests import MsgTestCase # list of tuples (, ) @@ -138,7 +139,7 @@ flushtests = [ ] -class TestParser (unittest.TestCase): +class TestParser (MsgTestCase): """ Test html parser. """ diff --git a/linkcheck/tests/test_strformat.py b/linkcheck/tests/test_strformat.py index b843e8ca..aa92b85b 100644 --- a/linkcheck/tests/test_strformat.py +++ b/linkcheck/tests/test_strformat.py @@ -22,9 +22,10 @@ import unittest import os import linkcheck.strformat +from linkcheck.tests import MsgTestCase -class TestStrFormat (unittest.TestCase): +class TestStrFormat (MsgTestCase): """ Test string formatting routines. """ diff --git a/linkcheck/tests/test_url.py b/linkcheck/tests/test_url.py index 9aed0c7b..596dfdf5 100644 --- a/linkcheck/tests/test_url.py +++ b/linkcheck/tests/test_url.py @@ -21,6 +21,7 @@ Test url routines. import unittest import os import linkcheck.url +from linkcheck.tests import MsgTestCase # 'ftp://user:pass@ftp.foo.net/foo/bar': # 'ftp://user:pass@ftp.foo.net/foo/bar', @@ -40,7 +41,7 @@ def url_norm (url): return linkcheck.url.url_norm(url)[0] -class TestUrl (unittest.TestCase): +class TestUrl (MsgTestCase): """ Test url norming and quoting. """