~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-14 15:22:39 UTC
  • mfrom: (4523.4.21 1.18-lock-warnings)
  • Revision ID: pqm@pqm.ubuntu.com-20090814152239-m0ybwy7vfs32exeh
(jam) Update the test suite to cause failures when we take out
        multiple locks on the same file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
595
595
                l.attempt_lock()
596
596
        test = TestDanglingLock('test_function')
597
597
        result = test.run()
598
 
        self.assertEqual(1, len(result.errors))
 
598
        if self._lock_check_thorough:
 
599
            self.assertEqual(1, len(result.errors))
 
600
        else:
 
601
            # When _lock_check_thorough is disabled, then we don't trigger a
 
602
            # failure
 
603
            self.assertEqual(0, len(result.errors))
599
604
 
600
605
 
601
606
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
1261
1266
class _TestException(Exception):
1262
1267
    pass
1263
1268
 
 
1269
 
1264
1270
class TestTestCase(tests.TestCase):
1265
1271
    """Tests that test the core bzrlib TestCase."""
1266
1272
 
1315
1321
        # we could set something and run a test that will check
1316
1322
        # it gets santised, but this is probably sufficient for now:
1317
1323
        # if someone runs the test with -Dsomething it will error.
1318
 
        self.assertEqual(set(), bzrlib.debug.debug_flags)
 
1324
        flags = set()
 
1325
        if self._lock_check_thorough:
 
1326
            flags.add('strict_locks')
 
1327
        self.assertEqual(flags, bzrlib.debug.debug_flags)
1319
1328
 
1320
1329
    def change_selftest_debug_flags(self, new_flags):
1321
1330
        orig_selftest_flags = tests.selftest_debug_flags
1336
1345
                self.flags = set(bzrlib.debug.debug_flags)
1337
1346
        test = TestThatRecordsFlags('test_foo')
1338
1347
        test.run(self.make_test_result())
1339
 
        self.assertEqual(set(['a-flag']), self.flags)
 
1348
        flags = set(['a-flag'])
 
1349
        if 'disable_lock_checks' not in tests.selftest_debug_flags:
 
1350
            flags.add('strict_locks')
 
1351
        self.assertEqual(flags, self.flags)
 
1352
 
 
1353
    def test_disable_lock_checks(self):
 
1354
        """The -Edisable_lock_checks flag disables thorough checks."""
 
1355
        class TestThatRecordsFlags(tests.TestCase):
 
1356
            def test_foo(nested_self):
 
1357
                self.flags = set(bzrlib.debug.debug_flags)
 
1358
                self.test_lock_check_thorough = nested_self._lock_check_thorough
 
1359
        self.change_selftest_debug_flags(set())
 
1360
        test = TestThatRecordsFlags('test_foo')
 
1361
        test.run(self.make_test_result())
 
1362
        # By default we do strict lock checking and thorough lock/unlock
 
1363
        # tracking.
 
1364
        self.assertTrue(self.test_lock_check_thorough)
 
1365
        self.assertEqual(set(['strict_locks']), self.flags)
 
1366
        # Now set the disable_lock_checks flag, and show that this changed.
 
1367
        self.change_selftest_debug_flags(set(['disable_lock_checks']))
 
1368
        test = TestThatRecordsFlags('test_foo')
 
1369
        test.run(self.make_test_result())
 
1370
        self.assertFalse(self.test_lock_check_thorough)
 
1371
        self.assertEqual(set(), self.flags)
 
1372
 
 
1373
    def test_this_fails_strict_lock_check(self):
 
1374
        class TestThatRecordsFlags(tests.TestCase):
 
1375
            def test_foo(nested_self):
 
1376
                self.flags1 = set(bzrlib.debug.debug_flags)
 
1377
                self.thisFailsStrictLockCheck()
 
1378
                self.flags2 = set(bzrlib.debug.debug_flags)
 
1379
        # Make sure lock checking is active
 
1380
        self.change_selftest_debug_flags(set())
 
1381
        test = TestThatRecordsFlags('test_foo')
 
1382
        test.run(self.make_test_result())
 
1383
        self.assertEqual(set(['strict_locks']), self.flags1)
 
1384
        self.assertEqual(set(), self.flags2)
1340
1385
 
1341
1386
    def test_debug_flags_restored(self):
1342
1387
        """The bzrlib debug flags should be restored to their original state