/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Martin Pool
  • Date: 2009-08-20 05:02:45 UTC
  • mfrom: (4615 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4632.
  • Revision ID: mbp@sourcefrog.net-20090820050245-o7cw6nxrzh1eah8h
News for apport feature

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
        self.assertEqual(sample_permutation,
125
125
                         get_transport_test_permutations(MockModule()))
126
126
 
127
 
    def test_scenarios_invlude_all_modules(self):
 
127
    def test_scenarios_include_all_modules(self):
128
128
        # this checks that the scenario generator returns as many permutations
129
129
        # as there are in all the registered transport modules - we assume if
130
130
        # this matches its probably doing the right thing especially in
293
293
        from bzrlib.tests.per_interrepository import make_scenarios
294
294
        server1 = "a"
295
295
        server2 = "b"
296
 
        formats = [(str, "C1", "C2"), (int, "D1", "D2")]
 
296
        formats = [("C0", "C1", "C2"), ("D0", "D1", "D2")]
297
297
        scenarios = make_scenarios(server1, server2, formats)
298
298
        self.assertEqual([
299
 
            ('str,str,str',
300
 
             {'interrepo_class': str,
301
 
              'repository_format': 'C1',
 
299
            ('C0,str,str',
 
300
             {'repository_format': 'C1',
302
301
              'repository_format_to': 'C2',
303
302
              'transport_readonly_server': 'b',
304
303
              'transport_server': 'a'}),
305
 
            ('int,str,str',
306
 
             {'interrepo_class': int,
307
 
              'repository_format': 'D1',
 
304
            ('D0,str,str',
 
305
             {'repository_format': 'D1',
308
306
              'repository_format_to': 'D2',
309
307
              'transport_readonly_server': 'b',
310
308
              'transport_server': 'a'})],
597
595
                l.attempt_lock()
598
596
        test = TestDanglingLock('test_function')
599
597
        result = test.run()
600
 
        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))
601
604
 
602
605
 
603
606
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
995
998
        runner = tests.TextTestRunner(stream=stream)
996
999
        result = self.run_test_runner(runner, test)
997
1000
        lines = stream.getvalue().splitlines()
998
 
        self.assertEqual([
999
 
            '',
1000
 
            '======================================================================',
1001
 
            'FAIL: unittest.FunctionTestCase (failing_test)',
1002
 
            '----------------------------------------------------------------------',
1003
 
            'Traceback (most recent call last):',
1004
 
            '    raise AssertionError(\'foo\')',
1005
 
            'AssertionError: foo',
1006
 
            '',
1007
 
            '----------------------------------------------------------------------',
1008
 
            '',
1009
 
            'FAILED (failures=1, known_failure_count=1)'],
1010
 
            lines[3:8] + lines[9:13] + lines[14:])
 
1001
        self.assertContainsRe(stream.getvalue(),
 
1002
            '(?sm)^testing.*$'
 
1003
            '.*'
 
1004
            '^======================================================================\n'
 
1005
            '^FAIL: unittest.FunctionTestCase \\(failing_test\\)\n'
 
1006
            '^----------------------------------------------------------------------\n'
 
1007
            'Traceback \\(most recent call last\\):\n'
 
1008
            '  .*' # File .*, line .*, in failing_test' - but maybe not from .pyc
 
1009
            '    raise AssertionError\\(\'foo\'\\)\n'
 
1010
            '.*'
 
1011
            '^----------------------------------------------------------------------\n'
 
1012
            '.*'
 
1013
            'FAILED \\(failures=1, known_failure_count=1\\)'
 
1014
            )
1011
1015
 
1012
1016
    def test_known_failure_ok_run(self):
1013
1017
        # run a test that generates a known failure which should be printed in the final output.
1263
1267
class _TestException(Exception):
1264
1268
    pass
1265
1269
 
 
1270
 
1266
1271
class TestTestCase(tests.TestCase):
1267
1272
    """Tests that test the core bzrlib TestCase."""
1268
1273
 
1317
1322
        # we could set something and run a test that will check
1318
1323
        # it gets santised, but this is probably sufficient for now:
1319
1324
        # if someone runs the test with -Dsomething it will error.
1320
 
        self.assertEqual(set(), bzrlib.debug.debug_flags)
 
1325
        flags = set()
 
1326
        if self._lock_check_thorough:
 
1327
            flags.add('strict_locks')
 
1328
        self.assertEqual(flags, bzrlib.debug.debug_flags)
1321
1329
 
1322
1330
    def change_selftest_debug_flags(self, new_flags):
1323
1331
        orig_selftest_flags = tests.selftest_debug_flags
1338
1346
                self.flags = set(bzrlib.debug.debug_flags)
1339
1347
        test = TestThatRecordsFlags('test_foo')
1340
1348
        test.run(self.make_test_result())
1341
 
        self.assertEqual(set(['a-flag']), self.flags)
 
1349
        flags = set(['a-flag'])
 
1350
        if 'disable_lock_checks' not in tests.selftest_debug_flags:
 
1351
            flags.add('strict_locks')
 
1352
        self.assertEqual(flags, self.flags)
 
1353
 
 
1354
    def test_disable_lock_checks(self):
 
1355
        """The -Edisable_lock_checks flag disables thorough checks."""
 
1356
        class TestThatRecordsFlags(tests.TestCase):
 
1357
            def test_foo(nested_self):
 
1358
                self.flags = set(bzrlib.debug.debug_flags)
 
1359
                self.test_lock_check_thorough = nested_self._lock_check_thorough
 
1360
        self.change_selftest_debug_flags(set())
 
1361
        test = TestThatRecordsFlags('test_foo')
 
1362
        test.run(self.make_test_result())
 
1363
        # By default we do strict lock checking and thorough lock/unlock
 
1364
        # tracking.
 
1365
        self.assertTrue(self.test_lock_check_thorough)
 
1366
        self.assertEqual(set(['strict_locks']), self.flags)
 
1367
        # Now set the disable_lock_checks flag, and show that this changed.
 
1368
        self.change_selftest_debug_flags(set(['disable_lock_checks']))
 
1369
        test = TestThatRecordsFlags('test_foo')
 
1370
        test.run(self.make_test_result())
 
1371
        self.assertFalse(self.test_lock_check_thorough)
 
1372
        self.assertEqual(set(), self.flags)
 
1373
 
 
1374
    def test_this_fails_strict_lock_check(self):
 
1375
        class TestThatRecordsFlags(tests.TestCase):
 
1376
            def test_foo(nested_self):
 
1377
                self.flags1 = set(bzrlib.debug.debug_flags)
 
1378
                self.thisFailsStrictLockCheck()
 
1379
                self.flags2 = set(bzrlib.debug.debug_flags)
 
1380
        # Make sure lock checking is active
 
1381
        self.change_selftest_debug_flags(set())
 
1382
        test = TestThatRecordsFlags('test_foo')
 
1383
        test.run(self.make_test_result())
 
1384
        self.assertEqual(set(['strict_locks']), self.flags1)
 
1385
        self.assertEqual(set(), self.flags2)
1342
1386
 
1343
1387
    def test_debug_flags_restored(self):
1344
1388
        """The bzrlib debug flags should be restored to their original state