~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-13 15:53:16 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061013155316-163e2bef7fa42490
New tests for http range requests handling.

* bzrlib/tests/test_http.py:
(TestRangeRequestServer): New class implementing tests involving
range requests.
(TestSingleRangeRequestServer,
TestSingleRangeRequestServer_urllib,
TestSingleRangeRequestServer_pycurl, TestNoRangeRequestServer,
TestNoRangeRequestServer_urllib,
TestNoRangeRequestServer_pycurl):New classes testing http
transports behavior against bogus range request handling servers.

* bzrlib/tests/__init__.py:
(TestCase.assertListRaises): Gratefully accepted from
bzrlib/tests/test_transport_implementations.py

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_has.assertListRaises): Generously given to
bzrlib/tests/__init__.py.

* bzrlib/tests/HTTPTestUtil.py:
(SingleRangeRequestHandler): New class implementing a server that
handle only range requests by bogusly returning only the first
requested range.
(NoRangeRequestHandler): New class implementing a server that
silently ignores range requests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
572
572
            raise AssertionError("value(s) %r not present in container %r" % 
573
573
                                 (missing, superlist))
574
574
 
 
575
    def assertListRaises(self, excClass, func, *args, **kwargs):
 
576
        """Fail unless excClass is raised when the iterator from func is used.
 
577
        
 
578
        Many functions can return generators this makes sure
 
579
        to wrap them in a list() call to make sure the whole generator
 
580
        is run, and that the proper exception is raised.
 
581
        """
 
582
        try:
 
583
            list(func(*args, **kwargs))
 
584
        except excClass:
 
585
            return
 
586
        else:
 
587
            if getattr(excClass,'__name__', None) is not None:
 
588
                excName = excClass.__name__
 
589
            else:
 
590
                excName = str(excClass)
 
591
            raise self.failureException, "%s not raised" % excName
 
592
 
575
593
    def assertIs(self, left, right):
576
594
        if not (left is right):
577
595
            raise AssertionError("%r is not %r." % (left, right))