~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Martin Pool
  • Date: 2011-06-14 01:26:41 UTC
  • mto: (6034.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 6043.
  • Revision ID: mbp@canonical.com-20110614012641-dnb69zb57ae5je4w
Move all test features into bzrlib.tests.features

Show diffs side-by-side

added added

removed removed

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