~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-12-11 19:25:13 UTC
  • mfrom: (2172 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2173.
  • Revision ID: john@arbash-meinel.com-20061211192513-u9ivkqwkp8j3v2i5
[merge] bzr.dev 2172 and move NEWS to the correct location

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,
323
324
 
324
325
    def report_error(self, test, err):
325
326
        self.error_count += 1
326
 
        self.pb.note('ERROR: %s\n    %s\n' % (
 
327
        self.pb.note('ERROR: %s\n    %s\n', 
327
328
            self._shortened_test_description(test),
328
329
            err[1],
329
 
            ))
 
330
            )
330
331
 
331
332
    def report_failure(self, test, err):
332
333
        self.failure_count += 1
333
 
        self.pb.note('FAIL: %s\n    %s\n' % (
 
334
        self.pb.note('FAIL: %s\n    %s\n', 
334
335
            self._shortened_test_description(test),
335
336
            err[1],
336
 
            ))
 
337
            )
337
338
 
338
339
    def report_skip(self, test, skip_excinfo):
339
340
        self.skip_count += 1
343
344
            # to see them.
344
345
            if False:
345
346
                # show test and reason for skip
346
 
                self.pb.note('SKIP: %s\n    %s\n' % (
 
347
                self.pb.note('SKIP: %s\n    %s\n', 
347
348
                    self._shortened_test_description(test),
348
 
                    skip_excinfo[1]))
 
349
                    skip_excinfo[1])
349
350
            else:
350
351
                # since the class name was left behind in the still-visible
351
352
                # progress bar...
352
 
                self.pb.note('SKIP: %s' % (skip_excinfo[1]))
 
353
                self.pb.note('SKIP: %s', skip_excinfo[1])
353
354
 
354
355
    def report_cleaning_up(self):
355
356
        self.pb.update('cleaning up...')
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):
1757
1790
                   'bzrlib.tests.test_weave',
1758
1791
                   'bzrlib.tests.test_whitebox',
1759
1792
                   'bzrlib.tests.test_workingtree',
 
1793
                   'bzrlib.tests.test_wsgi',
1760
1794
                   'bzrlib.tests.test_xml',
1761
1795
                   ]
1762
1796
    test_transport_implementations = [