376
381
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
377
382
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
378
383
self.assertEqual([
380
385
{'interrepo_class': str,
381
386
'repository_format': 'C1',
382
387
'repository_format_to': 'C2',
383
388
'transport_readonly_server': 'b',
384
389
'transport_server': 'a'}),
386
391
{'interrepo_class': int,
387
392
'repository_format': 'D1',
388
393
'repository_format_to': 'D2',
1131
1137
self.fail('test reached')
1133
1139
def cleanup(self):
1140
calls.append('cleanup')
1136
1142
runner = TextTestRunner(stream=self._log_file)
1137
1143
test = SkippedSetupTest('test_skip')
1138
1144
result = self.run_test_runner(runner, test)
1139
1145
self.assertTrue(result.wasSuccessful())
1140
1146
# Check if cleanup was called the right number of times.
1141
self.assertEqual(0, test.counter)
1147
self.assertEqual(['setUp', 'cleanup'], calls)
1143
1149
def test_skipped_from_test(self):
1144
1151
class SkippedTest(TestCase):
1146
1153
def setUp(self):
1154
calls.append('setUp')
1148
1155
self.addCleanup(self.cleanup)
1150
1157
def test_skip(self):
1151
1158
raise TestSkipped('skipped test')
1153
1160
def cleanup(self):
1161
calls.append('cleanup')
1156
1163
runner = TextTestRunner(stream=self._log_file)
1157
1164
test = SkippedTest('test_skip')
1158
1165
result = self.run_test_runner(runner, test)
1159
1166
self.assertTrue(result.wasSuccessful())
1160
1167
# Check if cleanup was called the right number of times.
1161
self.assertEqual(0, test.counter)
1168
self.assertEqual(['setUp', 'cleanup'], calls)
1163
1170
def test_not_applicable(self):
1164
1171
# run a test that is skipped because it's not applicable
1721
1728
self.loader = TestUtil.TestLoader()
1722
1729
self.suite.addTest(self.loader.loadTestsFromModuleNames([
1723
1730
'bzrlib.tests.test_selftest']))
1724
self.all_names = self._test_ids(self.suite)
1726
def _test_ids(self, test_suite):
1727
"""Get the ids for the tests in a test suite."""
1728
return [t.id() for t in iter_suite_tests(test_suite)]
1731
self.all_names = _test_ids(self.suite)
1730
1733
def test_condition_id_re(self):
1731
1734
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1732
1735
'test_condition_id_re')
1733
1736
filtered_suite = filter_suite_by_condition(self.suite,
1734
1737
condition_id_re('test_condition_id_re'))
1735
self.assertEqual([test_name], self._test_ids(filtered_suite))
1738
self.assertEqual([test_name], _test_ids(filtered_suite))
1737
1740
def test_condition_id_in_list(self):
1738
1741
test_names = ['bzrlib.tests.test_selftest.TestSelftestFiltering.'
1742
1745
self.suite, tests.condition_id_in_list(id_list))
1743
1746
my_pattern = 'TestSelftestFiltering.*test_condition_id_in_list'
1744
1747
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1745
self.assertEqual(self._test_ids(re_filtered),
1746
self._test_ids(filtered_suite))
1748
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1748
1750
def test_condition_isinstance(self):
1749
1751
filtered_suite = filter_suite_by_condition(self.suite,
1750
1752
condition_isinstance(self.__class__))
1751
1753
class_pattern = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1752
1754
re_filtered = filter_suite_by_re(self.suite, class_pattern)
1753
self.assertEqual(self._test_ids(re_filtered),
1754
self._test_ids(filtered_suite))
1755
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1756
1757
def test_exclude_tests_by_condition(self):
1757
1758
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1760
1761
lambda x:x.id() == excluded_name)
1761
1762
self.assertEqual(len(self.all_names) - 1,
1762
1763
filtered_suite.countTestCases())
1763
self.assertFalse(excluded_name in self._test_ids(filtered_suite))
1764
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1764
1765
remaining_names = list(self.all_names)
1765
1766
remaining_names.remove(excluded_name)
1766
self.assertEqual(remaining_names, self._test_ids(filtered_suite))
1767
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1768
1769
def test_exclude_tests_by_re(self):
1769
self.all_names = self._test_ids(self.suite)
1770
self.all_names = _test_ids(self.suite)
1770
1771
filtered_suite = exclude_tests_by_re(self.suite, 'exclude_tests_by_re')
1771
1772
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1772
1773
'test_exclude_tests_by_re')
1773
1774
self.assertEqual(len(self.all_names) - 1,
1774
1775
filtered_suite.countTestCases())
1775
self.assertFalse(excluded_name in self._test_ids(filtered_suite))
1776
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1776
1777
remaining_names = list(self.all_names)
1777
1778
remaining_names.remove(excluded_name)
1778
self.assertEqual(remaining_names, self._test_ids(filtered_suite))
1779
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1780
1781
def test_filter_suite_by_condition(self):
1781
1782
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1782
1783
'test_filter_suite_by_condition')
1783
1784
filtered_suite = filter_suite_by_condition(self.suite,
1784
1785
lambda x:x.id() == test_name)
1785
self.assertEqual([test_name], self._test_ids(filtered_suite))
1786
self.assertEqual([test_name], _test_ids(filtered_suite))
1787
1788
def test_filter_suite_by_re(self):
1788
1789
filtered_suite = filter_suite_by_re(self.suite, 'test_filter_suite_by_r')
1789
filtered_names = self._test_ids(filtered_suite)
1790
filtered_names = _test_ids(filtered_suite)
1790
1791
self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.'
1791
1792
'TestSelftestFiltering.test_filter_suite_by_re'])
1809
1810
def test_randomize_suite(self):
1810
1811
randomized_suite = randomize_suite(self.suite)
1811
1812
# randomizing should not add or remove test names.
1812
self.assertEqual(set(self._test_ids(self.suite)),
1813
set(self._test_ids(randomized_suite)))
1813
self.assertEqual(set(_test_ids(self.suite)),
1814
set(_test_ids(randomized_suite)))
1814
1815
# Technically, this *can* fail, because random.shuffle(list) can be
1815
1816
# equal to list. Trying multiple times just pushes the frequency back.
1816
1817
# As its len(self.all_names)!:1, the failure frequency should be low
1817
1818
# enough to ignore. RBC 20071021.
1818
1819
# It should change the order.
1819
self.assertNotEqual(self.all_names, self._test_ids(randomized_suite))
1820
self.assertNotEqual(self.all_names, _test_ids(randomized_suite))
1820
1821
# But not the length. (Possibly redundant with the set test, but not
1821
1822
# necessarily.)
1822
self.assertEqual(len(self.all_names),
1823
len(self._test_ids(randomized_suite)))
1823
self.assertEqual(len(self.all_names), len(_test_ids(randomized_suite)))
1825
1825
def test_sort_suite_by_re(self):
1826
1826
sorted_suite = self.applyDeprecated(one_zero,
1827
1827
sort_suite_by_re, self.suite, 'test_filter_suite_by_r')
1828
sorted_names = self._test_ids(sorted_suite)
1828
sorted_names = _test_ids(sorted_suite)
1829
1829
self.assertEqual(sorted_names[0], 'bzrlib.tests.test_selftest.'
1830
1830
'TestSelftestFiltering.test_filter_suite_by_re')
1831
1831
self.assertEquals(sorted(self.all_names), sorted(sorted_names))
1833
1833
def test_split_suit_by_re(self):
1834
self.all_names = self._test_ids(self.suite)
1834
self.all_names = _test_ids(self.suite)
1835
1835
split_suite = split_suite_by_re(self.suite, 'test_filter_suite_by_r')
1836
1836
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1837
1837
'test_filter_suite_by_re')
1838
self.assertEqual([filtered_name], self._test_ids(split_suite[0]))
1839
self.assertFalse(filtered_name in self._test_ids(split_suite[1]))
1838
self.assertEqual([filtered_name], _test_ids(split_suite[0]))
1839
self.assertFalse(filtered_name in _test_ids(split_suite[1]))
1840
1840
remaining_names = list(self.all_names)
1841
1841
remaining_names.remove(filtered_name)
1842
self.assertEqual(remaining_names, self._test_ids(split_suite[1]))
1842
self.assertEqual(remaining_names, _test_ids(split_suite[1]))
1845
1845
class TestCheckInventoryShape(TestCaseWithTransport):
1916
1916
module.__class__.load_tests = load_tests
1917
1917
self.assertEqual(2, loader.loadTestsFromModule(module).countTestCases())
1919
def test_load_tests_from_module_name_smoke_test(self):
1920
loader = TestUtil.TestLoader()
1921
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
1922
self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
1925
def test_load_tests_from_module_name_with_bogus_module_name(self):
1926
loader = TestUtil.TestLoader()
1927
self.assertRaises(ImportError, loader.loadTestsFromModuleName, 'bogus')
1920
1930
class TestTestIdList(tests.TestCase):
1954
1964
'mod1.submod1',
1955
1965
'mod1.submod2.cl1.meth1', 'mod1.submod2.cl2.meth2',
1957
self.assertTrue(id_list.is_module_name_used('mod1'))
1958
self.assertTrue(id_list.is_module_name_used('mod1.submod1'))
1959
self.assertTrue(id_list.is_module_name_used('mod1.submod2'))
1960
self.assertTrue(id_list.test_in('mod1.cl1.meth1'))
1961
self.assertTrue(id_list.test_in('mod1.submod1'))
1962
self.assertTrue(id_list.test_in('mod1.func1'))
1967
self.assertTrue(id_list.refers_to('mod1'))
1968
self.assertTrue(id_list.refers_to('mod1.submod1'))
1969
self.assertTrue(id_list.refers_to('mod1.submod2'))
1970
self.assertTrue(id_list.includes('mod1.cl1.meth1'))
1971
self.assertTrue(id_list.includes('mod1.submod1'))
1972
self.assertTrue(id_list.includes('mod1.func1'))
1964
1974
def test_bad_chars_in_params(self):
1965
1975
id_list = self._create_id_list(['mod1.cl1.meth1(xx.yy)'])
1966
self.assertTrue(id_list.is_module_name_used('mod1'))
1967
self.assertTrue(id_list.test_in('mod1.cl1.meth1(xx.yy)'))
1976
self.assertTrue(id_list.refers_to('mod1'))
1977
self.assertTrue(id_list.includes('mod1.cl1.meth1(xx.yy)'))
1969
1979
def test_module_used(self):
1970
1980
id_list = self._create_id_list(['mod.class.meth'])
1971
self.assertTrue(id_list.is_module_name_used('mod'))
1972
self.assertTrue(id_list.is_module_name_used('mod.class'))
1973
self.assertTrue(id_list.is_module_name_used('mod.class.meth'))
1981
self.assertTrue(id_list.refers_to('mod'))
1982
self.assertTrue(id_list.refers_to('mod.class'))
1983
self.assertTrue(id_list.refers_to('mod.class.meth'))
1975
1985
def test_test_suite(self):
1976
1986
# This test is slow, so we do a single test with one test in each
1991
2001
suite = tests.test_suite(test_list)
1992
self.assertEquals(test_list, self._test_ids(suite))
2002
self.assertEquals(test_list, _test_ids(suite))
2004
def test_test_suite_matches_id_list_with_unknown(self):
2005
loader = TestUtil.TestLoader()
2006
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2007
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',
2009
not_found, duplicates = tests.suite_matches_id_list(suite, test_list)
2010
self.assertEquals(['bogus'], not_found)
2011
self.assertEquals([], duplicates)
2013
def test_suite_matches_id_list_with_duplicates(self):
2014
loader = TestUtil.TestLoader()
2015
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2016
dupes = loader.suiteClass()
2017
for test in iter_suite_tests(suite):
2019
dupes.addTest(test) # Add it again
2021
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',]
2022
not_found, duplicates = tests.suite_matches_id_list(
2024
self.assertEquals([], not_found)
2025
self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
1995
2029
class TestLoadTestIdList(tests.TestCaseInTempDir):
2025
2059
self.assertEquals('bar baz', tlist[3])
2062
class TestFilteredByModuleTestLoader(tests.TestCase):
2064
def _create_loader(self, test_list):
2065
id_filter = tests.TestIdList(test_list)
2066
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
2069
def test_load_tests(self):
2070
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2071
loader = self._create_loader(test_list)
2073
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2074
self.assertEquals(test_list, _test_ids(suite))
2076
def test_exclude_tests(self):
2077
test_list = ['bogus']
2078
loader = self._create_loader(test_list)
2080
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2081
self.assertEquals([], _test_ids(suite))