~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1000
1000
        for key, (parent, name) in known_hooks.iter_parent_objects():
1001
1001
            current_hooks = getattr(parent, name)
1002
1002
            self._preserved_hooks[parent] = (name, current_hooks)
 
1003
        self._preserved_lazy_hooks = hooks._lazy_hooks
 
1004
        hooks._lazy_hooks = {}
1003
1005
        self.addCleanup(self._restoreHooks)
1004
1006
        for key, (parent, name) in known_hooks.iter_parent_objects():
1005
1007
            factory = known_hooks.get(key)
1265
1267
                         'st_mtime did not match')
1266
1268
        self.assertEqual(expected.st_ctime, actual.st_ctime,
1267
1269
                         'st_ctime did not match')
1268
 
        if sys.platform != 'win32':
 
1270
        if sys.platform == 'win32':
1269
1271
            # On Win32 both 'dev' and 'ino' cannot be trusted. In python2.4 it
1270
1272
            # is 'dev' that varies, in python 2.5 (6?) it is st_ino that is
1271
 
            # odd. Regardless we shouldn't actually try to assert anything
1272
 
            # about their values
 
1273
            # odd. We just force it to always be 0 to avoid any problems.
 
1274
            self.assertEqual(0, expected.st_dev)
 
1275
            self.assertEqual(0, actual.st_dev)
 
1276
            self.assertEqual(0, expected.st_ino)
 
1277
            self.assertEqual(0, actual.st_ino)
 
1278
        else:
1273
1279
            self.assertEqual(expected.st_dev, actual.st_dev,
1274
1280
                             'st_dev did not match')
1275
1281
            self.assertEqual(expected.st_ino, actual.st_ino,
1438
1444
 
1439
1445
    def assertFileEqual(self, content, path):
1440
1446
        """Fail if path does not contain 'content'."""
1441
 
        self.failUnlessExists(path)
 
1447
        self.assertPathExists(path)
1442
1448
        f = file(path, 'rb')
1443
1449
        try:
1444
1450
            s = f.read()
1454
1460
        else:
1455
1461
            self.assertEqual(expected_docstring, obj.__doc__)
1456
1462
 
 
1463
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4)))
1457
1464
    def failUnlessExists(self, path):
 
1465
        return self.assertPathExists(path)
 
1466
 
 
1467
    def assertPathExists(self, path):
1458
1468
        """Fail unless path or paths, which may be abs or relative, exist."""
1459
1469
        if not isinstance(path, basestring):
1460
1470
            for p in path:
1461
 
                self.failUnlessExists(p)
 
1471
                self.assertPathExists(p)
1462
1472
        else:
1463
 
            self.failUnless(osutils.lexists(path),path+" does not exist")
 
1473
            self.assertTrue(osutils.lexists(path),
 
1474
                path + " does not exist")
1464
1475
 
 
1476
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4)))
1465
1477
    def failIfExists(self, path):
 
1478
        return self.assertPathDoesNotExist(path)
 
1479
 
 
1480
    def assertPathDoesNotExist(self, path):
1466
1481
        """Fail if path or paths, which may be abs or relative, exist."""
1467
1482
        if not isinstance(path, basestring):
1468
1483
            for p in path:
1469
 
                self.failIfExists(p)
 
1484
                self.assertPathDoesNotExist(p)
1470
1485
        else:
1471
 
            self.failIf(osutils.lexists(path),path+" exists")
 
1486
            self.assertFalse(osutils.lexists(path),
 
1487
                path + " exists")
1472
1488
 
1473
1489
    def _capture_deprecation_warnings(self, a_callable, *args, **kwargs):
1474
1490
        """A helper for callDeprecated and applyDeprecated.
1657
1673
    def _restoreHooks(self):
1658
1674
        for klass, (name, hooks) in self._preserved_hooks.items():
1659
1675
            setattr(klass, name, hooks)
 
1676
        hooks._lazy_hooks = self._preserved_lazy_hooks
1660
1677
 
1661
1678
    def knownFailure(self, reason):
1662
1679
        """This test has failed for some known reason."""
2108
2125
                      % (process_args, retcode, process.returncode))
2109
2126
        return [out, err]
2110
2127
 
2111
 
    def check_inventory_shape(self, inv, shape):
2112
 
        """Compare an inventory to a list of expected names.
 
2128
    def check_tree_shape(self, tree, shape):
 
2129
        """Compare a tree to a list of expected names.
2113
2130
 
2114
2131
        Fail if they are not precisely equal.
2115
2132
        """
2116
2133
        extras = []
2117
2134
        shape = list(shape)             # copy
2118
 
        for path, ie in inv.entries():
 
2135
        for path, ie in tree.iter_entries_by_dir():
2119
2136
            name = path.replace('\\', '/')
2120
2137
            if ie.kind == 'directory':
2121
2138
                name = name + '/'
2122
 
            if name in shape:
 
2139
            if name == "/":
 
2140
                pass # ignore root entry
 
2141
            elif name in shape:
2123
2142
                shape.remove(name)
2124
2143
            else:
2125
2144
                extras.append(name)
3902
3921
        'bzrlib',
3903
3922
        'bzrlib.branchbuilder',
3904
3923
        'bzrlib.decorators',
3905
 
        'bzrlib.export',
3906
3924
        'bzrlib.inventory',
3907
3925
        'bzrlib.iterablefile',
3908
3926
        'bzrlib.lockdir',