~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

remove all trailing whitespace from bzr source

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
class TestTransportProviderAdapter(TestCase):
132
132
    """A group of tests that test the transport implementation adaption core.
133
133
 
134
 
    This is a meta test that the tests are applied to all available 
 
134
    This is a meta test that the tests are applied to all available
135
135
    transports.
136
136
 
137
 
    This will be generalised in the future which is why it is in this 
 
137
    This will be generalised in the future which is why it is in this
138
138
    test file even though it is specific to transport tests at the moment.
139
139
    """
140
140
 
163
163
        permutation_count = 0
164
164
        for module in modules:
165
165
            try:
166
 
                permutation_count += len(reduce(getattr, 
 
166
                permutation_count += len(reduce(getattr,
167
167
                    (module + ".get_test_permutations").split('.')[1:],
168
168
                     __import__(module))())
169
169
            except errors.DependencyNotPresent:
321
321
            ("new id 2", {"bzrdir_format":None}))
322
322
        # input_test should have been altered.
323
323
        self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
324
 
        # the new tests are mutually incompatible, ensuring it has 
 
324
        # the new tests are mutually incompatible, ensuring it has
325
325
        # made new ones, and unspecified elements in the scenario
326
326
        # should not have been altered.
327
327
        self.assertEqual("bzr_format", adapted_test1.bzrdir_format)
522
522
        """The test_home_dir for TestCaseWithMemoryTransport is missing.
523
523
 
524
524
        This is because TestCaseWithMemoryTransport is for tests that do not
525
 
        need any disk resources: they should be hooked into bzrlib in such a 
526
 
        way that no global settings are being changed by the test (only a 
 
525
        need any disk resources: they should be hooked into bzrlib in such a
 
526
        way that no global settings are being changed by the test (only a
527
527
        few tests should need to do that), and having a missing dir as home is
528
528
        an effective way to ensure that this is the case.
529
529
        """
531
531
            self.TEST_ROOT + "/MemoryTransportMissingHomeDir",
532
532
            self.test_home_dir)
533
533
        self.assertIsSameRealPath(self.test_home_dir, os.environ['HOME'])
534
 
        
 
534
 
535
535
    def test_cwd_is_TEST_ROOT(self):
536
536
        self.assertIsSameRealPath(self.test_dir, self.TEST_ROOT)
537
537
        cwd = osutils.getcwd()
678
678
    def test_make_bzrdir_preserves_transport(self):
679
679
        t = self.get_transport()
680
680
        result_bzrdir = self.make_bzrdir('subdir')
681
 
        self.assertIsInstance(result_bzrdir.transport, 
 
681
        self.assertIsInstance(result_bzrdir.transport,
682
682
                              MemoryTransport)
683
683
        # should not be on disk, should only be in memory
684
684
        self.failIfExists('subdir')
746
746
                time.sleep(0.003)
747
747
        self.check_timing(ShortDelayTestCase('test_short_delay'),
748
748
                          r"^ +[0-9]+ms$")
749
 
        
 
749
 
750
750
    def test_assigned_benchmark_file_stores_date(self):
751
751
        output = StringIO()
752
752
        result = bzrlib.tests.TextTestResult(self._log_file,
779
779
        self.assertContainsRe(lines[1],
780
780
            " *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
781
781
            "._time_hello_world_encoding")
782
 
 
 
782
 
783
783
    def _time_hello_world_encoding(self):
784
784
        """Profile two sleep calls
785
 
        
 
785
 
786
786
        This is used to exercise the test framework.
787
787
        """
788
788
        self.time(unicode, 'hello', errors='replace')
806
806
        # execute the test, which should succeed and record profiles
807
807
        example_test_case.run(result)
808
808
        # lsprofile_something()
809
 
        # if this worked we want 
 
809
        # if this worked we want
810
810
        # LSProf output for <built in function unicode> (['hello'], {'errors': 'replace'})
811
811
        #    CallCount    Recursive    Total(ms)   Inline(ms) module:lineno(function)
812
812
        # (the lsprof header)
813
813
        # ... an arbitrary number of lines
814
814
        # and the function call which is time.sleep.
815
 
        #           1        0            ???         ???       ???(sleep) 
 
815
        #           1        0            ???         ???       ???(sleep)
816
816
        # and then repeated but with 'world', rather than 'hello'.
817
817
        # this should appear in the output stream of our test result.
818
818
        output = result_stream.getvalue()
953
953
        output = result_stream.getvalue()[prefix:]
954
954
        lines = output.splitlines()
955
955
        self.assertEqual(lines, ['NODEP                   0ms', "    The feature 'Feature' is not available."])
956
 
    
 
956
 
957
957
    def test_text_report_unsupported(self):
958
958
        # text test output formatting
959
959
        pb = MockProgress()
982
982
            ('update', '[2 in 0s, 2 missing] passing_test', None, None),
983
983
            ],
984
984
            pb.calls[1:])
985
 
    
 
985
 
986
986
    def test_unavailable_exception(self):
987
987
        """An UnavailableFeature being raised should invoke addNotSupported."""
988
988
        class InstrumentedTestResult(ExtendedTestResult):
1011
1011
        result.addNotSupported(test, feature)
1012
1012
        self.assertFalse(result.wasStrictlySuccessful())
1013
1013
        self.assertEqual(None, result._extractBenchmarkTime(test))
1014
 
 
 
1014
 
1015
1015
    def test_strict_with_known_failure(self):
1016
1016
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1017
1017
                                             verbosity=1)
1049
1049
 
1050
1050
        This current saves and restores:
1051
1051
        TestCaseInTempDir.TEST_ROOT
1052
 
        
 
1052
 
1053
1053
        There should be no tests in this file that use bzrlib.tests.TextTestRunner
1054
1054
        without using this convenience method, because of our use of global state.
1055
1055
        """
1358
1358
        orig_selftest_flags = tests.selftest_debug_flags
1359
1359
        self.addCleanup(self._restore_selftest_debug_flags, orig_selftest_flags)
1360
1360
        tests.selftest_debug_flags = set(new_flags)
1361
 
        
 
1361
 
1362
1362
    def _restore_selftest_debug_flags(self, flags):
1363
1363
        tests.selftest_debug_flags = flags
1364
1364
 
1411
1411
        # should setup a new log, log content to it, setup a child case (B),
1412
1412
        # which should log independently, then case (A) should log a trailer
1413
1413
        # and return.
1414
 
        # we do two nested children so that we can verify the state of the 
 
1414
        # we do two nested children so that we can verify the state of the
1415
1415
        # logs after the outer child finishes is correct, which a bad clean
1416
1416
        # up routine in tearDown might trigger a fault in our test with only
1417
1417
        # one child, we should instead see the bad result inside our test with
1451
1451
 
1452
1452
    def test__gather_lsprof_in_benchmarks(self):
1453
1453
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.
1454
 
        
 
1454
 
1455
1455
        Each self.time() call is individually and separately profiled.
1456
1456
        """
1457
1457
        self.requireFeature(test_lsprof.LSProfFeature)
1458
 
        # overrides the class member with an instance member so no cleanup 
 
1458
        # overrides the class member with an instance member so no cleanup
1459
1459
        # needed.
1460
1460
        self._gather_lsprof_in_benchmarks = True
1461
1461
        self.time(time.sleep, 0.000)
1487
1487
    def test_run_no_parameters(self):
1488
1488
        test = SampleTestCase('_test_pass')
1489
1489
        test.run()
1490
 
    
 
1490
 
1491
1491
    def test_run_enabled_unittest_result(self):
1492
1492
        """Test we revert to regular behaviour when the test is enabled."""
1493
1493
        test = SampleTestCase('_test_pass')
1656
1656
        self.assertEqual(2, self.applyDeprecated(zero_eleven,
1657
1657
            sample_deprecated_function))
1658
1658
        # calling a nested deprecation with the wrong deprecation version
1659
 
        # fails even if a deeper nested function was deprecated with the 
 
1659
        # fails even if a deeper nested function was deprecated with the
1660
1660
        # supplied version.
1661
1661
        self.assertRaises(AssertionError, self.applyDeprecated,
1662
1662
            zero_eleven, sample_object.sample_nested_deprecation)
1668
1668
    def test_callDeprecated(self):
1669
1669
        def testfunc(be_deprecated, result=None):
1670
1670
            if be_deprecated is True:
1671
 
                symbol_versioning.warn('i am deprecated', DeprecationWarning, 
 
1671
                symbol_versioning.warn('i am deprecated', DeprecationWarning,
1672
1672
                                       stacklevel=1)
1673
1673
            return result
1674
1674
        result = self.callDeprecated(['i am deprecated'], testfunc, True)
1739
1739
            return TestSuite()
1740
1740
        out = StringIO()
1741
1741
        err = StringIO()
1742
 
        self.apply_redirected(out, err, None, bzrlib.tests.selftest, 
 
1742
        self.apply_redirected(out, err, None, bzrlib.tests.selftest,
1743
1743
            test_suite_factory=factory)
1744
1744
        self.assertEqual([True], factory_called)
1745
1745