128
128
def test_get_transport_permutations(self):
129
# this checks that we the module get_test_permutations call
130
# is made by the adapter get_transport_test_permitations method.
129
# this checks that get_test_permutations defined by the module is
130
# called by the adapter get_transport_test_permutations method.
131
131
class MockModule(object):
132
132
def get_test_permutations(self):
133
133
return sample_permutation
139
139
adapter.get_transport_test_permutations(MockModule()))
141
141
def test_adapter_checks_all_modules(self):
142
# this checks that the adapter returns as many permurtations as
143
# there are in all the registered# transport modules for there
144
# - we assume if this matches its probably doing the right thing
145
# especially in combination with the tests for setting the right
142
# this checks that the adapter returns as many permutations as there
143
# are in all the registered transport modules - we assume if this
144
# matches its probably doing the right thing especially in combination
145
# with the tests for setting the right classes below.
147
146
from bzrlib.tests.test_transport_implementations \
148
147
import TransportTestProviderAdapter
149
148
from bzrlib.transport import _get_transport_modules
502
501
adapter = TreeTestProviderAdapter(server1, server2, formats)
503
502
suite = adapter.adapt(input_test)
504
503
tests = list(iter(suite))
505
self.assertEqual(4, len(tests))
504
# XXX We should not have tests fail as we add more scenarios
506
self.assertEqual(5, len(tests))
506
507
# this must match the default format setp up in
507
508
# TreeTestProviderAdapter.adapt
508
509
default_format = WorkingTreeFormat3
1747
1748
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1748
1749
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1751
def test_condition_id_startswith(self):
1752
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1753
start = klass + 'test_condition_id_starts'
1754
test_names = [klass + 'test_condition_id_startswith']
1755
filtered_suite = filter_suite_by_condition(
1756
self.suite, tests.condition_id_startswith(start))
1757
my_pattern = 'TestSelftestFiltering.*test_condition_id_startswith'
1758
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1759
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1750
1761
def test_condition_isinstance(self):
1751
1762
filtered_suite = filter_suite_by_condition(self.suite,
1752
1763
condition_isinstance(self.__class__))
1802
1813
['bzrlib.tests.test_selftest.'
1803
1814
'TestSelftestFiltering.test_filter_suite_by_id_list'])
1816
def test_filter_suite_by_id_startswith(self):
1817
# By design this test may fail if another test is added whose name also
1818
# begins with the start value used.
1819
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1820
start = klass + 'test_filter_suite_by_id_starts'
1821
test_list = [klass + 'test_filter_suite_by_id_startswith']
1822
filtered_suite = tests.filter_suite_by_id_startswith(self.suite, start)
1823
filtered_names = _test_ids(filtered_suite)
1826
['bzrlib.tests.test_selftest.'
1827
'TestSelftestFiltering.test_filter_suite_by_id_startswith'])
1805
1829
def test_preserve_input(self):
1806
1830
# NB: Surely this is something in the stdlib to do this?
1807
1831
self.assertTrue(self.suite is preserve_input(self.suite))
1822
1846
# necessarily.)
1823
1847
self.assertEqual(len(self.all_names), len(_test_ids(randomized_suite)))
1825
def test_sort_suite_by_re(self):
1826
sorted_suite = self.applyDeprecated(one_zero,
1827
sort_suite_by_re, self.suite, 'test_filter_suite_by_r')
1828
sorted_names = _test_ids(sorted_suite)
1829
self.assertEqual(sorted_names[0], 'bzrlib.tests.test_selftest.'
1830
'TestSelftestFiltering.test_filter_suite_by_re')
1831
self.assertEquals(sorted(self.all_names), sorted(sorted_names))
1849
def test_split_suit_by_condition(self):
1850
self.all_names = _test_ids(self.suite)
1851
condition = condition_id_re('test_filter_suite_by_r')
1852
split_suite = split_suite_by_condition(self.suite, condition)
1853
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1854
'test_filter_suite_by_re')
1855
self.assertEqual([filtered_name], _test_ids(split_suite[0]))
1856
self.assertFalse(filtered_name in _test_ids(split_suite[1]))
1857
remaining_names = list(self.all_names)
1858
remaining_names.remove(filtered_name)
1859
self.assertEqual(remaining_names, _test_ids(split_suite[1]))
1833
1861
def test_split_suit_by_re(self):
1834
1862
self.all_names = _test_ids(self.suite)
1989
2017
# testmod_names
2018
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
1990
2019
'bzrlib.tests.test_selftest.TestTestIdList.test_test_suite',
1991
2020
# transport implementations
1992
2021
'bzrlib.tests.test_transport_implementations.TransportTests'
1993
2022
'.test_abspath(LocalURLServer)',
1994
# packages_to_test()
1995
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
1996
# MODULES_TO_DOCTEST
2023
# modules_to_doctest
1997
2024
'bzrlib.timestamp.format_highres_date',
1998
2025
# plugins can't be tested that way since selftest may be run with
2080
2107
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2081
2108
self.assertEquals([], _test_ids(suite))
2111
class TestFilteredByNameStartTestLoader(tests.TestCase):
2113
def _create_loader(self, name_start):
2114
def needs_module(name):
2115
return name.startswith(name_start) or name_start.startswith(name)
2116
loader = TestUtil.FilteredByModuleTestLoader(needs_module)
2119
def test_load_tests(self):
2120
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2121
loader = self._create_loader('bzrlib.tests.test_samp')
2123
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2124
self.assertEquals(test_list, _test_ids(suite))
2126
def test_load_tests_inside_module(self):
2127
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2128
loader = self._create_loader('bzrlib.tests.test_sampler.Demo')
2130
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2131
self.assertEquals(test_list, _test_ids(suite))
2133
def test_exclude_tests(self):
2134
test_list = ['bogus']
2135
loader = self._create_loader('bogus')
2137
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2138
self.assertEquals([], _test_ids(suite))