~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Merge integration and knit-index utf8 decoding fixes.

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
 
1260
1286
                self.__readonly_server = ReadonlyServer()
1261
1287
                self.__readonly_server.setUp(self.get_server())
1262
1288
            else:
1263
 
                self.__readonly_server = self.transport_readonly_server()
 
1289
                self.__readonly_server = self.create_transport_readonly_server()
1264
1290
                self.__readonly_server.setUp()
1265
1291
            self.addCleanup(self.__readonly_server.tearDown)
1266
1292
        return self.__readonly_server
1519
1545
    readwrite one must both define get_url() as resolving to os.getcwd().
1520
1546
    """
1521
1547
 
 
1548
    def create_transport_server(self):
 
1549
        """Create a transport server from class defined at init.
 
1550
 
 
1551
        This is mostly a hook for daughter classes.
 
1552
        """
 
1553
        return self.transport_server()
 
1554
 
1522
1555
    def get_server(self):
1523
1556
        """See TestCaseWithMemoryTransport.
1524
1557
 
1526
1559
        diagnostics.
1527
1560
        """
1528
1561
        if self.__server is None:
1529
 
            self.__server = self.transport_server()
 
1562
            self.__server = self.create_transport_server()
1530
1563
            self.__server.setUp()
1531
1564
            self.addCleanup(self.__server.tearDown)
1532
1565
        return self.__server
1597
1630
 
1598
1631
    def setUp(self):
1599
1632
        super(ChrootedTestCase, self).setUp()
1600
 
        if not self.transport_server == bzrlib.transport.memory.MemoryServer:
1601
 
            self.transport_readonly_server = bzrlib.transport.http.HttpServer
 
1633
        if not self.transport_server == MemoryServer:
 
1634
            self.transport_readonly_server = HttpServer
1602
1635
 
1603
1636
 
1604
1637
def filter_suite_by_re(suite, pattern):