~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: mbp at sourcefrog
  • Date: 2006-11-21 01:08:52 UTC
  • mfrom: (2004.1.42 bzr.urllib.keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: mbp@sourcefrog.net-20061121010852-838b560632acc36c
merge urllib keepalive etc

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
from bzrlib.transport.readonly import ReadonlyServer
80
80
from bzrlib.trace import mutter, note
81
81
from bzrlib.tests import TestUtil
 
82
from bzrlib.tests.HttpServer import HttpServer
82
83
from bzrlib.tests.TestUtil import (
83
84
                          TestSuite,
84
85
                          TestLoader,
637
638
            raise AssertionError("value(s) %r not present in container %r" % 
638
639
                                 (missing, superlist))
639
640
 
 
641
    def assertListRaises(self, excClass, func, *args, **kwargs):
 
642
        """Fail unless excClass is raised when the iterator from func is used.
 
643
        
 
644
        Many functions can return generators this makes sure
 
645
        to wrap them in a list() call to make sure the whole generator
 
646
        is run, and that the proper exception is raised.
 
647
        """
 
648
        try:
 
649
            list(func(*args, **kwargs))
 
650
        except excClass:
 
651
            return
 
652
        else:
 
653
            if getattr(excClass,'__name__', None) is not None:
 
654
                excName = excClass.__name__
 
655
            else:
 
656
                excName = str(excClass)
 
657
            raise self.failureException, "%s not raised" % excName
 
658
 
640
659
    def assertIs(self, left, right):
641
660
        if not (left is right):
642
661
            raise AssertionError("%r is not %r." % (left, right))
1248
1267
        self.assertTrue(t.is_readonly())
1249
1268
        return t
1250
1269
 
 
1270
    def create_transport_readonly_server(self):
 
1271
        """Create a transport server from class defined at init.
 
1272
 
 
1273
        This is mostly a hook for daughter classes.
 
1274
        """
 
1275
        return self.transport_readonly_server()
 
1276
 
1251
1277
    def get_readonly_server(self):
1252
1278
        """Get the server instance for the readonly transport
1253
1279
 
1261
1287
                self.__readonly_server = ReadonlyServer()
1262
1288
                self.__readonly_server.setUp(self.__server)
1263
1289
            else:
1264
 
                self.__readonly_server = self.transport_readonly_server()
 
1290
                self.__readonly_server = self.create_transport_readonly_server()
1265
1291
                self.__readonly_server.setUp()
1266
1292
            self.addCleanup(self.__readonly_server.tearDown)
1267
1293
        return self.__readonly_server
1520
1546
    readwrite one must both define get_url() as resolving to os.getcwd().
1521
1547
    """
1522
1548
 
 
1549
    def create_transport_server(self):
 
1550
        """Create a transport server from class defined at init.
 
1551
 
 
1552
        This is mostly a hook for daughter classes.
 
1553
        """
 
1554
        return self.transport_server()
 
1555
 
1523
1556
    def get_server(self):
1524
1557
        """See TestCaseWithMemoryTransport.
1525
1558
 
1527
1560
        diagnostics.
1528
1561
        """
1529
1562
        if self.__server is None:
1530
 
            self.__server = self.transport_server()
 
1563
            self.__server = self.create_transport_server()
1531
1564
            self.__server.setUp()
1532
1565
            self.addCleanup(self.__server.tearDown)
1533
1566
        return self.__server
1598
1631
 
1599
1632
    def setUp(self):
1600
1633
        super(ChrootedTestCase, self).setUp()
1601
 
        if not self.transport_server == bzrlib.transport.memory.MemoryServer:
1602
 
            self.transport_readonly_server = bzrlib.transport.http.HttpServer
 
1634
        if not self.transport_server == MemoryServer:
 
1635
            self.transport_readonly_server = HttpServer
1603
1636
 
1604
1637
 
1605
1638
def filter_suite_by_re(suite, pattern):