~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: 2011-07-25 03:36:18 UTC
  • mfrom: (6034.2.4 test-feature-cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20110725033618-n5g9qg6iwyz2dqzw
(mbp) move test feature dependencies into test.features (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
            DocTestMatches(u"...a test message\n", doctest.ELLIPSIS))
94
94
 
95
95
 
96
 
class TestUnicodeFilename(tests.TestCase):
97
 
 
98
 
    def test_probe_passes(self):
99
 
        """UnicodeFilename._probe passes."""
100
 
        # We can't test much more than that because the behaviour depends
101
 
        # on the platform.
102
 
        tests.UnicodeFilename._probe()
103
 
 
104
 
 
105
96
class TestTreeShape(tests.TestCaseInTempDir):
106
97
 
107
98
    def test_unicode_paths(self):
108
 
        self.requireFeature(tests.UnicodeFilename)
 
99
        self.requireFeature(features.UnicodeFilenameFeature)
109
100
 
110
101
        filename = u'hell\u00d8'
111
102
        self.build_tree_contents([(filename, 'contents of hello')])
721
712
class TestProfileResult(tests.TestCase):
722
713
 
723
714
    def test_profiles_tests(self):
724
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
715
        self.requireFeature(features.lsprof_feature)
725
716
        terminal = testtools.testresult.doubles.ExtendedTestResult()
726
717
        result = tests.ProfileResult(terminal)
727
718
        class Sample(tests.TestCase):
782
773
 
783
774
    def test_lsprofiling(self):
784
775
        """Verbose test result prints lsprof statistics from test cases."""
785
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
776
        self.requireFeature(features.lsprof_feature)
786
777
        result_stream = StringIO()
787
778
        result = bzrlib.tests.VerboseTestResult(
788
779
            result_stream,
897
888
                self._call = test, feature
898
889
        result = InstrumentedTestResult(None, None, None, None)
899
890
        test = SampleTestCase('_test_pass')
900
 
        feature = tests.Feature()
 
891
        feature = features.Feature()
901
892
        result.startTest(test)
902
893
        result.addNotSupported(test, feature)
903
894
        # it should invoke 'report_unsupported'.
922
913
            verbosity=2,
923
914
            )
924
915
        test = self.get_passing_test()
925
 
        feature = tests.Feature()
 
916
        feature = features.Feature()
926
917
        result.startTest(test)
927
918
        prefix = len(result_stream.getvalue())
928
919
        result.report_unsupported(test, feature)
941
932
            def addNotSupported(self, test, feature):
942
933
                self._call = test, feature
943
934
        result = InstrumentedTestResult(None, None, None, None)
944
 
        feature = tests.Feature()
 
935
        feature = features.Feature()
945
936
        class Test(tests.TestCase):
946
937
            def test_function(self):
947
938
                raise tests.UnavailableFeature(feature)
1006
997
        self.assertEquals(2, result.count)
1007
998
 
1008
999
 
1009
 
class TestUnicodeFilenameFeature(tests.TestCase):
1010
 
 
1011
 
    def test_probe_passes(self):
1012
 
        """UnicodeFilenameFeature._probe passes."""
1013
 
        # We can't test much more than that because the behaviour depends
1014
 
        # on the platform.
1015
 
        tests.UnicodeFilenameFeature._probe()
1016
 
 
1017
 
 
1018
1000
class TestRunner(tests.TestCase):
1019
1001
 
1020
1002
    def dummy_test(self):
1191
1173
 
1192
1174
    def test_unsupported_features_listed(self):
1193
1175
        """When unsupported features are encountered they are detailed."""
1194
 
        class Feature1(tests.Feature):
 
1176
        class Feature1(features.Feature):
1195
1177
            def _probe(self): return False
1196
 
        class Feature2(tests.Feature):
 
1178
        class Feature2(features.Feature):
1197
1179
            def _probe(self): return False
1198
1180
        # create sample tests
1199
1181
        test1 = SampleTestCase('_test_pass')
1476
1458
 
1477
1459
        Each self.time() call is individually and separately profiled.
1478
1460
        """
1479
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
1461
        self.requireFeature(features.lsprof_feature)
1480
1462
        # overrides the class member with an instance member so no cleanup
1481
1463
        # needed.
1482
1464
        self._gather_lsprof_in_benchmarks = True
1512
1494
 
1513
1495
    def test_requireFeature_available(self):
1514
1496
        """self.requireFeature(available) is a no-op."""
1515
 
        class Available(tests.Feature):
 
1497
        class Available(features.Feature):
1516
1498
            def _probe(self):return True
1517
1499
        feature = Available()
1518
1500
        self.requireFeature(feature)
1519
1501
 
1520
1502
    def test_requireFeature_unavailable(self):
1521
1503
        """self.requireFeature(unavailable) raises UnavailableFeature."""
1522
 
        class Unavailable(tests.Feature):
 
1504
        class Unavailable(features.Feature):
1523
1505
            def _probe(self):return False
1524
1506
        feature = Unavailable()
1525
1507
        self.assertRaises(tests.UnavailableFeature,
1685
1667
        self.assertEqual('original', obj.test_attr)
1686
1668
 
1687
1669
 
1688
 
class _MissingFeature(tests.Feature):
 
1670
class _MissingFeature(features.Feature):
1689
1671
    def _probe(self):
1690
1672
        return False
1691
1673
missing_feature = _MissingFeature()
2037
2019
        self.assertLength(2, output.readlines())
2038
2020
 
2039
2021
    def test_lsprof_tests(self):
2040
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
2022
        self.requireFeature(features.lsprof_feature)
2041
2023
        results = []
2042
2024
        class Test(object):
2043
2025
            def __call__(test, result):
2607
2589
        self.assertEqual('bzr: interrupted\n', result[1])
2608
2590
 
2609
2591
 
2610
 
class TestFeature(tests.TestCase):
2611
 
 
2612
 
    def test_caching(self):
2613
 
        """Feature._probe is called by the feature at most once."""
2614
 
        class InstrumentedFeature(tests.Feature):
2615
 
            def __init__(self):
2616
 
                super(InstrumentedFeature, self).__init__()
2617
 
                self.calls = []
2618
 
            def _probe(self):
2619
 
                self.calls.append('_probe')
2620
 
                return False
2621
 
        feature = InstrumentedFeature()
2622
 
        feature.available()
2623
 
        self.assertEqual(['_probe'], feature.calls)
2624
 
        feature.available()
2625
 
        self.assertEqual(['_probe'], feature.calls)
2626
 
 
2627
 
    def test_named_str(self):
2628
 
        """Feature.__str__ should thunk to feature_name()."""
2629
 
        class NamedFeature(tests.Feature):
2630
 
            def feature_name(self):
2631
 
                return 'symlinks'
2632
 
        feature = NamedFeature()
2633
 
        self.assertEqual('symlinks', str(feature))
2634
 
 
2635
 
    def test_default_str(self):
2636
 
        """Feature.__str__ should default to __class__.__name__."""
2637
 
        class NamedFeature(tests.Feature):
2638
 
            pass
2639
 
        feature = NamedFeature()
2640
 
        self.assertEqual('NamedFeature', str(feature))
2641
 
 
2642
 
 
2643
 
class TestUnavailableFeature(tests.TestCase):
2644
 
 
2645
 
    def test_access_feature(self):
2646
 
        feature = tests.Feature()
2647
 
        exception = tests.UnavailableFeature(feature)
2648
 
        self.assertIs(feature, exception.args[0])
2649
 
 
2650
 
 
2651
 
simple_thunk_feature = tests._CompatabilityThunkFeature(
2652
 
    deprecated_in((2, 1, 0)),
2653
 
    'bzrlib.tests.test_selftest',
2654
 
    'simple_thunk_feature','UnicodeFilename',
2655
 
    replacement_module='bzrlib.tests'
2656
 
    )
2657
 
 
2658
 
class Test_CompatibilityFeature(tests.TestCase):
2659
 
 
2660
 
    def test_does_thunk(self):
2661
 
        res = self.callDeprecated(
2662
 
            ['bzrlib.tests.test_selftest.simple_thunk_feature was deprecated'
2663
 
             ' in version 2.1.0. Use bzrlib.tests.UnicodeFilename instead.'],
2664
 
            simple_thunk_feature.available)
2665
 
        self.assertEqual(tests.UnicodeFilename.available(), res)
2666
 
 
2667
 
 
2668
 
class TestModuleAvailableFeature(tests.TestCase):
2669
 
 
2670
 
    def test_available_module(self):
2671
 
        feature = tests.ModuleAvailableFeature('bzrlib.tests')
2672
 
        self.assertEqual('bzrlib.tests', feature.module_name)
2673
 
        self.assertEqual('bzrlib.tests', str(feature))
2674
 
        self.assertTrue(feature.available())
2675
 
        self.assertIs(tests, feature.module)
2676
 
 
2677
 
    def test_unavailable_module(self):
2678
 
        feature = tests.ModuleAvailableFeature('bzrlib.no_such_module_exists')
2679
 
        self.assertEqual('bzrlib.no_such_module_exists', str(feature))
2680
 
        self.assertFalse(feature.available())
2681
 
        self.assertIs(None, feature.module)
2682
 
 
2683
 
 
2684
2592
class TestSelftestFiltering(tests.TestCase):
2685
2593
 
2686
2594
    def setUp(self):