169
149
# This test used to know about all the possible transports and the
170
150
# order they were returned but that seems overly brittle (mbp
172
from bzrlib.tests.test_transport_implementations \
173
import TransportTestProviderAdapter
174
scenarios = TransportTestProviderAdapter().scenarios
152
input_test = TestTransportProviderAdapter(
153
"test_adapter_sets_transport_class")
154
from bzrlib.transport import TransportTestProviderAdapter
155
suite = TransportTestProviderAdapter().adapt(input_test)
156
tests = list(iter(suite))
157
self.assertTrue(len(tests) > 6)
175
158
# there are at least that many builtin transports
176
self.assertTrue(len(scenarios) > 6)
177
one_scenario = scenarios[0]
178
self.assertIsInstance(one_scenario[0], str)
179
self.assertTrue(issubclass(one_scenario[1]["transport_class"],
160
self.assertTrue(issubclass(one_test.transport_class,
180
161
bzrlib.transport.Transport))
181
self.assertTrue(issubclass(one_scenario[1]["transport_server"],
162
self.assertTrue(issubclass(one_test.transport_server,
182
163
bzrlib.transport.Server))
185
166
class TestBranchProviderAdapter(TestCase):
186
167
"""A group of tests that test the branch implementation test adapter."""
188
def test_constructor(self):
169
def test_adapted_tests(self):
189
170
# check that constructor parameters are passed through to the adapted
191
from bzrlib.tests.branch_implementations import BranchTestProviderAdapter
172
from bzrlib.branch import BranchTestProviderAdapter
173
input_test = TestBranchProviderAdapter(
174
"test_adapted_tests")
194
177
formats = [("c", "C"), ("d", "D")]
195
178
adapter = BranchTestProviderAdapter(server1, server2, formats)
196
self.assertEqual(2, len(adapter.scenarios))
199
{'branch_format': 'c',
200
'bzrdir_format': 'C',
201
'transport_readonly_server': 'b',
202
'transport_server': 'a'}),
204
{'branch_format': 'd',
205
'bzrdir_format': 'D',
206
'transport_readonly_server': 'b',
207
'transport_server': 'a'})],
179
suite = adapter.adapt(input_test)
180
tests = list(iter(suite))
181
self.assertEqual(2, len(tests))
182
self.assertEqual(tests[0].branch_format, formats[0][0])
183
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
184
self.assertEqual(tests[0].transport_server, server1)
185
self.assertEqual(tests[0].transport_readonly_server, server2)
186
self.assertEqual(tests[1].branch_format, formats[1][0])
187
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
188
self.assertEqual(tests[1].transport_server, server1)
189
self.assertEqual(tests[1].transport_readonly_server, server2)
211
192
class TestBzrDirProviderAdapter(TestCase):
214
195
def test_adapted_tests(self):
215
196
# check that constructor parameters are passed through to the adapted
217
from bzrlib.tests.bzrdir_implementations import BzrDirTestProviderAdapter
198
from bzrlib.bzrdir import BzrDirTestProviderAdapter
199
input_test = TestBzrDirProviderAdapter(
200
"test_adapted_tests")
218
201
vfs_factory = "v"
221
204
formats = ["c", "d"]
222
205
adapter = BzrDirTestProviderAdapter(vfs_factory,
223
206
server1, server2, formats)
226
{'bzrdir_format': 'c',
227
'transport_readonly_server': 'b',
228
'transport_server': 'a',
229
'vfs_transport_factory': 'v'}),
231
{'bzrdir_format': 'd',
232
'transport_readonly_server': 'b',
233
'transport_server': 'a',
234
'vfs_transport_factory': 'v'})],
207
suite = adapter.adapt(input_test)
208
tests = list(iter(suite))
209
self.assertEqual(2, len(tests))
210
self.assertEqual(tests[0].bzrdir_format, formats[0])
211
self.assertEqual(tests[0].vfs_transport_factory, vfs_factory)
212
self.assertEqual(tests[0].transport_server, server1)
213
self.assertEqual(tests[0].transport_readonly_server, server2)
214
self.assertEqual(tests[1].bzrdir_format, formats[1])
215
self.assertEqual(tests[1].vfs_transport_factory, vfs_factory)
216
self.assertEqual(tests[1].transport_server, server1)
217
self.assertEqual(tests[1].transport_readonly_server, server2)
238
220
class TestRepositoryProviderAdapter(TestCase):
239
221
"""A group of tests that test the repository implementation test adapter."""
241
def test_constructor(self):
242
# check that constructor parameters are passed through to the
244
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
223
def test_adapted_tests(self):
224
# check that constructor parameters are passed through to the adapted
226
from bzrlib.repository import RepositoryTestProviderAdapter
227
input_test = TestRepositoryProviderAdapter(
228
"test_adapted_tests")
247
231
formats = [("c", "C"), ("d", "D")]
248
232
adapter = RepositoryTestProviderAdapter(server1, server2, formats)
251
{'bzrdir_format': 'C',
252
'repository_format': 'c',
253
'transport_readonly_server': 'b',
254
'transport_server': 'a'}),
256
{'bzrdir_format': 'D',
257
'repository_format': 'd',
258
'transport_readonly_server': 'b',
259
'transport_server': 'a'})],
233
suite = adapter.adapt(input_test)
234
tests = list(iter(suite))
235
self.assertEqual(2, len(tests))
236
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
237
self.assertEqual(tests[0].repository_format, formats[0][0])
238
self.assertEqual(tests[0].transport_server, server1)
239
self.assertEqual(tests[0].transport_readonly_server, server2)
240
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
241
self.assertEqual(tests[1].repository_format, formats[1][0])
242
self.assertEqual(tests[1].transport_server, server1)
243
self.assertEqual(tests[1].transport_readonly_server, server2)
262
245
def test_setting_vfs_transport(self):
263
246
"""The vfs_transport_factory can be set optionally."""
264
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
265
formats = [("a", "b"), ("c", "d")]
247
from bzrlib.repository import RepositoryTestProviderAdapter
248
input_test = TestRepositoryProviderAdapter(
249
"test_adapted_tests")
250
formats = [("c", "C")]
266
251
adapter = RepositoryTestProviderAdapter(None, None, formats,
267
252
vfs_transport_factory="vfs")
270
{'bzrdir_format': 'b',
271
'repository_format': 'a',
272
'transport_readonly_server': None,
273
'transport_server': None,
274
'vfs_transport_factory': 'vfs'}),
276
{'bzrdir_format': 'd',
277
'repository_format': 'c',
278
'transport_readonly_server': None,
279
'transport_server': None,
280
'vfs_transport_factory': 'vfs'})],
283
def test_formats_to_scenarios(self):
284
"""The adapter can generate all the scenarios needed."""
285
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
286
no_vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
288
vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
289
[], vfs_transport_factory="vfs")
290
# no_vfs generate scenarios without vfs_transport_factor
291
formats = [("c", "C"), (1, "D")]
294
{'bzrdir_format': 'C',
295
'repository_format': 'c',
296
'transport_readonly_server': 'readonly',
297
'transport_server': 'server'}),
299
{'bzrdir_format': 'D',
300
'repository_format': 1,
301
'transport_readonly_server': 'readonly',
302
'transport_server': 'server'})],
303
no_vfs_adapter.formats_to_scenarios(formats))
306
{'bzrdir_format': 'C',
307
'repository_format': 'c',
308
'transport_readonly_server': 'readonly',
309
'transport_server': 'server',
310
'vfs_transport_factory': 'vfs'}),
312
{'bzrdir_format': 'D',
313
'repository_format': 1,
314
'transport_readonly_server': 'readonly',
315
'transport_server': 'server',
316
'vfs_transport_factory': 'vfs'})],
317
vfs_adapter.formats_to_scenarios(formats))
320
class TestTestScenarioApplier(TestCase):
321
"""Tests for the test adaption facilities."""
323
def test_adapt_applies_scenarios(self):
324
from bzrlib.tests.repository_implementations import TestScenarioApplier
325
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
326
adapter = TestScenarioApplier()
327
adapter.scenarios = [("1", "dict"), ("2", "settings")]
329
def capture_call(test, scenario):
330
calls.append((test, scenario))
332
adapter.adapt_test_to_scenario = capture_call
333
adapter.adapt(input_test)
334
self.assertEqual([(input_test, ("1", "dict")),
335
(input_test, ("2", "settings"))], calls)
337
def test_adapt_test_to_scenario(self):
338
from bzrlib.tests.repository_implementations import TestScenarioApplier
339
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
340
adapter = TestScenarioApplier()
341
# setup two adapted tests
342
adapted_test1 = adapter.adapt_test_to_scenario(input_test,
344
{"bzrdir_format":"bzr_format",
345
"repository_format":"repo_fmt",
346
"transport_server":"transport_server",
347
"transport_readonly_server":"readonly-server"}))
348
adapted_test2 = adapter.adapt_test_to_scenario(input_test,
349
("new id 2", {"bzrdir_format":None}))
350
# input_test should have been altered.
351
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
352
# the new tests are mutually incompatible, ensuring it has
353
# made new ones, and unspecified elements in the scenario
354
# should not have been altered.
355
self.assertEqual("bzr_format", adapted_test1.bzrdir_format)
356
self.assertEqual("repo_fmt", adapted_test1.repository_format)
357
self.assertEqual("transport_server", adapted_test1.transport_server)
358
self.assertEqual("readonly-server",
359
adapted_test1.transport_readonly_server)
361
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
362
"test_adapt_test_to_scenario(new id)",
364
self.assertEqual(None, adapted_test2.bzrdir_format)
366
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
367
"test_adapt_test_to_scenario(new id 2)",
253
suite = adapter.adapt(input_test)
254
tests = list(iter(suite))
255
self.assertEqual(1, len(tests))
256
self.assertEqual(tests[0].vfs_transport_factory, "vfs")
371
259
class TestInterRepositoryProviderAdapter(TestCase):
374
262
def test_adapted_tests(self):
375
263
# check that constructor parameters are passed through to the adapted
377
from bzrlib.tests.interrepository_implementations import \
378
InterRepositoryTestProviderAdapter
265
from bzrlib.repository import InterRepositoryTestProviderAdapter
266
input_test = TestInterRepositoryProviderAdapter(
267
"test_adapted_tests")
381
270
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
382
271
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
385
{'interrepo_class': str,
386
'repository_format': 'C1',
387
'repository_format_to': 'C2',
388
'transport_readonly_server': 'b',
389
'transport_server': 'a'}),
391
{'interrepo_class': int,
392
'repository_format': 'D1',
393
'repository_format_to': 'D2',
394
'transport_readonly_server': 'b',
395
'transport_server': 'a'})],
396
adapter.formats_to_scenarios(formats))
272
suite = adapter.adapt(input_test)
273
tests = list(iter(suite))
274
self.assertEqual(2, len(tests))
275
self.assertEqual(tests[0].interrepo_class, formats[0][0])
276
self.assertEqual(tests[0].repository_format, formats[0][1])
277
self.assertEqual(tests[0].repository_format_to, formats[0][2])
278
self.assertEqual(tests[0].transport_server, server1)
279
self.assertEqual(tests[0].transport_readonly_server, server2)
280
self.assertEqual(tests[1].interrepo_class, formats[1][0])
281
self.assertEqual(tests[1].repository_format, formats[1][1])
282
self.assertEqual(tests[1].repository_format_to, formats[1][2])
283
self.assertEqual(tests[1].transport_server, server1)
284
self.assertEqual(tests[1].transport_readonly_server, server2)
399
287
class TestInterVersionedFileProviderAdapter(TestCase):
400
288
"""A group of tests that test the InterVersionedFile test adapter."""
402
def test_scenarios(self):
290
def test_adapted_tests(self):
403
291
# check that constructor parameters are passed through to the adapted
405
from bzrlib.tests.interversionedfile_implementations \
406
import InterVersionedFileTestProviderAdapter
293
from bzrlib.versionedfile import InterVersionedFileTestProviderAdapter
294
input_test = TestInterRepositoryProviderAdapter(
295
"test_adapted_tests")
409
298
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
410
299
adapter = InterVersionedFileTestProviderAdapter(server1, server2, formats)
413
{'interversionedfile_class':str,
414
'transport_readonly_server': 'b',
415
'transport_server': 'a',
416
'versionedfile_factory': 'C1',
417
'versionedfile_factory_to': 'C2'}),
419
{'interversionedfile_class': int,
420
'transport_readonly_server': 'b',
421
'transport_server': 'a',
422
'versionedfile_factory': 'D1',
423
'versionedfile_factory_to': 'D2'})],
300
suite = adapter.adapt(input_test)
301
tests = list(iter(suite))
302
self.assertEqual(2, len(tests))
303
self.assertEqual(tests[0].interversionedfile_class, formats[0][0])
304
self.assertEqual(tests[0].versionedfile_factory, formats[0][1])
305
self.assertEqual(tests[0].versionedfile_factory_to, formats[0][2])
306
self.assertEqual(tests[0].transport_server, server1)
307
self.assertEqual(tests[0].transport_readonly_server, server2)
308
self.assertEqual(tests[1].interversionedfile_class, formats[1][0])
309
self.assertEqual(tests[1].versionedfile_factory, formats[1][1])
310
self.assertEqual(tests[1].versionedfile_factory_to, formats[1][2])
311
self.assertEqual(tests[1].transport_server, server1)
312
self.assertEqual(tests[1].transport_readonly_server, server2)
427
315
class TestRevisionStoreProviderAdapter(TestCase):
428
316
"""A group of tests that test the RevisionStore test adapter."""
430
def test_scenarios(self):
318
def test_adapted_tests(self):
431
319
# check that constructor parameters are passed through to the adapted
433
from bzrlib.tests.revisionstore_implementations \
434
import RevisionStoreTestProviderAdapter
321
from bzrlib.store.revision import RevisionStoreTestProviderAdapter
322
input_test = TestRevisionStoreProviderAdapter(
323
"test_adapted_tests")
435
324
# revision stores need a store factory - i.e. RevisionKnit
436
325
#, a readonly and rw transport
437
326
# transport servers:
1728
1520
self.loader = TestUtil.TestLoader()
1729
1521
self.suite.addTest(self.loader.loadTestsFromModuleNames([
1730
1522
'bzrlib.tests.test_selftest']))
1731
self.all_names = _test_ids(self.suite)
1733
def test_condition_id_re(self):
1734
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1735
'test_condition_id_re')
1736
filtered_suite = filter_suite_by_condition(self.suite,
1737
condition_id_re('test_condition_id_re'))
1738
self.assertEqual([test_name], _test_ids(filtered_suite))
1740
def test_condition_id_in_list(self):
1741
test_names = ['bzrlib.tests.test_selftest.TestSelftestFiltering.'
1742
'test_condition_id_in_list']
1743
id_list = tests.TestIdList(test_names)
1744
filtered_suite = filter_suite_by_condition(
1745
self.suite, tests.condition_id_in_list(id_list))
1746
my_pattern = 'TestSelftestFiltering.*test_condition_id_in_list'
1747
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1748
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1750
def test_condition_isinstance(self):
1751
filtered_suite = filter_suite_by_condition(self.suite,
1752
condition_isinstance(self.__class__))
1753
class_pattern = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1754
re_filtered = filter_suite_by_re(self.suite, class_pattern)
1755
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1757
def test_exclude_tests_by_condition(self):
1758
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1759
'test_exclude_tests_by_condition')
1760
filtered_suite = exclude_tests_by_condition(self.suite,
1761
lambda x:x.id() == excluded_name)
1762
self.assertEqual(len(self.all_names) - 1,
1763
filtered_suite.countTestCases())
1764
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1765
remaining_names = list(self.all_names)
1766
remaining_names.remove(excluded_name)
1767
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1769
def test_exclude_tests_by_re(self):
1770
self.all_names = _test_ids(self.suite)
1771
filtered_suite = exclude_tests_by_re(self.suite, 'exclude_tests_by_re')
1772
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1773
'test_exclude_tests_by_re')
1774
self.assertEqual(len(self.all_names) - 1,
1775
filtered_suite.countTestCases())
1776
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1777
remaining_names = list(self.all_names)
1778
remaining_names.remove(excluded_name)
1779
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1781
def test_filter_suite_by_condition(self):
1782
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1783
'test_filter_suite_by_condition')
1784
filtered_suite = filter_suite_by_condition(self.suite,
1785
lambda x:x.id() == test_name)
1786
self.assertEqual([test_name], _test_ids(filtered_suite))
1523
self.all_names = [t.id() for t in iter_suite_tests(self.suite)]
1788
1525
def test_filter_suite_by_re(self):
1789
filtered_suite = filter_suite_by_re(self.suite, 'test_filter_suite_by_r')
1790
filtered_names = _test_ids(filtered_suite)
1526
filtered_suite = filter_suite_by_re(self.suite, 'test_filter')
1527
filtered_names = [t.id() for t in iter_suite_tests(filtered_suite)]
1791
1528
self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.'
1792
1529
'TestSelftestFiltering.test_filter_suite_by_re'])
1794
def test_filter_suite_by_id_list(self):
1795
test_list = ['bzrlib.tests.test_selftest.'
1796
'TestSelftestFiltering.test_filter_suite_by_id_list']
1797
filtered_suite = tests.filter_suite_by_id_list(
1798
self.suite, tests.TestIdList(test_list))
1799
filtered_names = _test_ids(filtered_suite)
1802
['bzrlib.tests.test_selftest.'
1803
'TestSelftestFiltering.test_filter_suite_by_id_list'])
1805
def test_preserve_input(self):
1806
# NB: Surely this is something in the stdlib to do this?
1807
self.assertTrue(self.suite is preserve_input(self.suite))
1808
self.assertTrue("@#$" is preserve_input("@#$"))
1810
def test_randomize_suite(self):
1811
randomized_suite = randomize_suite(self.suite)
1812
# randomizing should not add or remove test names.
1813
self.assertEqual(set(_test_ids(self.suite)),
1814
set(_test_ids(randomized_suite)))
1815
# Technically, this *can* fail, because random.shuffle(list) can be
1816
# equal to list. Trying multiple times just pushes the frequency back.
1817
# As its len(self.all_names)!:1, the failure frequency should be low
1818
# enough to ignore. RBC 20071021.
1819
# It should change the order.
1820
self.assertNotEqual(self.all_names, _test_ids(randomized_suite))
1821
# But not the length. (Possibly redundant with the set test, but not
1823
self.assertEqual(len(self.all_names), len(_test_ids(randomized_suite)))
1825
1531
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)
1532
sorted_suite = sort_suite_by_re(self.suite, 'test_filter')
1533
sorted_names = [t.id() for t in iter_suite_tests(sorted_suite)]
1829
1534
self.assertEqual(sorted_names[0], 'bzrlib.tests.test_selftest.'
1830
1535
'TestSelftestFiltering.test_filter_suite_by_re')
1831
1536
self.assertEquals(sorted(self.all_names), sorted(sorted_names))
1833
def test_split_suit_by_re(self):
1834
self.all_names = _test_ids(self.suite)
1835
split_suite = split_suite_by_re(self.suite, 'test_filter_suite_by_r')
1836
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1837
'test_filter_suite_by_re')
1838
self.assertEqual([filtered_name], _test_ids(split_suite[0]))
1839
self.assertFalse(filtered_name in _test_ids(split_suite[1]))
1840
remaining_names = list(self.all_names)
1841
remaining_names.remove(filtered_name)
1842
self.assertEqual(remaining_names, _test_ids(split_suite[1]))
1845
class TestCheckInventoryShape(TestCaseWithTransport):
1847
def test_check_inventory_shape(self):
1848
files = ['a', 'b/', 'b/c']
1849
tree = self.make_branch_and_tree('.')
1850
self.build_tree(files)
1854
self.check_inventory_shape(tree.inventory, files)
1859
class TestBlackboxSupport(TestCase):
1860
"""Tests for testsuite blackbox features."""
1862
def test_run_bzr_failure_not_caught(self):
1863
# When we run bzr in blackbox mode, we want any unexpected errors to
1864
# propagate up to the test suite so that it can show the error in the
1865
# usual way, and we won't get a double traceback.
1866
e = self.assertRaises(
1868
self.run_bzr, ['assert-fail'])
1869
# make sure we got the real thing, not an error from somewhere else in
1870
# the test framework
1871
self.assertEquals('always fails', str(e))
1872
# check that there's no traceback in the test log
1873
self.assertNotContainsRe(self._get_log(keep_log_file=True),
1876
def test_run_bzr_user_error_caught(self):
1877
# Running bzr in blackbox mode, normal/expected/user errors should be
1878
# caught in the regular way and turned into an error message plus exit
1880
out, err = self.run_bzr(["log", "/nonexistantpath"], retcode=3)
1881
self.assertEqual(out, '')
1882
self.assertContainsRe(err,
1883
'bzr: ERROR: Not a branch: ".*nonexistantpath/".\n')
1886
class TestTestLoader(TestCase):
1887
"""Tests for the test loader."""
1889
def _get_loader_and_module(self):
1890
"""Gets a TestLoader and a module with one test in it."""
1891
loader = TestUtil.TestLoader()
1893
class Stub(TestCase):
1896
class MyModule(object):
1898
MyModule.a_class = Stub
1900
return loader, module
1902
def test_module_no_load_tests_attribute_loads_classes(self):
1903
loader, module = self._get_loader_and_module()
1904
self.assertEqual(1, loader.loadTestsFromModule(module).countTestCases())
1906
def test_module_load_tests_attribute_gets_called(self):
1907
loader, module = self._get_loader_and_module()
1908
# 'self' is here because we're faking the module with a class. Regular
1909
# load_tests do not need that :)
1910
def load_tests(self, standard_tests, module, loader):
1911
result = loader.suiteClass()
1912
for test in iter_suite_tests(standard_tests):
1913
result.addTests([test, test])
1915
# add a load_tests() method which multiplies the tests from the module.
1916
module.__class__.load_tests = load_tests
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')
1930
class TestTestIdList(tests.TestCase):
1932
def _create_id_list(self, test_list):
1933
return tests.TestIdList(test_list)
1935
def _create_suite(self, test_id_list):
1937
class Stub(TestCase):
1941
def _create_test_id(id):
1944
suite = TestUtil.TestSuite()
1945
for id in test_id_list:
1946
t = Stub('test_foo')
1947
t.id = _create_test_id(id)
1951
def _test_ids(self, test_suite):
1952
"""Get the ids for the tests in a test suite."""
1953
return [t.id() for t in iter_suite_tests(test_suite)]
1955
def test_empty_list(self):
1956
id_list = self._create_id_list([])
1957
self.assertEquals({}, id_list.tests)
1958
self.assertEquals({}, id_list.modules)
1960
def test_valid_list(self):
1961
id_list = self._create_id_list(
1962
['mod1.cl1.meth1', 'mod1.cl1.meth2',
1963
'mod1.func1', 'mod1.cl2.meth2',
1965
'mod1.submod2.cl1.meth1', 'mod1.submod2.cl2.meth2',
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'))
1974
def test_bad_chars_in_params(self):
1975
id_list = self._create_id_list(['mod1.cl1.meth1(xx.yy)'])
1976
self.assertTrue(id_list.refers_to('mod1'))
1977
self.assertTrue(id_list.includes('mod1.cl1.meth1(xx.yy)'))
1979
def test_module_used(self):
1980
id_list = self._create_id_list(['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'))
1985
def test_test_suite(self):
1986
# This test is slow, so we do a single test with one test in each
1990
'bzrlib.tests.test_selftest.TestTestIdList.test_test_suite',
1991
# transport implementations
1992
'bzrlib.tests.test_transport_implementations.TransportTests'
1993
'.test_abspath(LocalURLServer)',
1994
# packages_to_test()
1995
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
1996
# MODULES_TO_DOCTEST
1997
'bzrlib.timestamp.format_highres_date',
1998
# plugins can't be tested that way since selftest may be run with
2001
suite = tests.test_suite(test_list)
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'],
2029
class TestLoadTestIdList(tests.TestCaseInTempDir):
2031
def _create_test_list_file(self, file_name, content):
2032
fl = open(file_name, 'wt')
2036
def test_load_unknown(self):
2037
self.assertRaises(errors.NoSuchFile,
2038
tests.load_test_id_list, 'i_do_not_exist')
2040
def test_load_test_list(self):
2041
test_list_fname = 'test.list'
2042
self._create_test_list_file(test_list_fname,
2043
'mod1.cl1.meth1\nmod2.cl2.meth2\n')
2044
tlist = tests.load_test_id_list(test_list_fname)
2045
self.assertEquals(2, len(tlist))
2046
self.assertEquals('mod1.cl1.meth1', tlist[0])
2047
self.assertEquals('mod2.cl2.meth2', tlist[1])
2049
def test_load_dirty_file(self):
2050
test_list_fname = 'test.list'
2051
self._create_test_list_file(test_list_fname,
2052
' mod1.cl1.meth1\n\nmod2.cl2.meth2 \n'
2054
tlist = tests.load_test_id_list(test_list_fname)
2055
self.assertEquals(4, len(tlist))
2056
self.assertEquals('mod1.cl1.meth1', tlist[0])
2057
self.assertEquals('', tlist[1])
2058
self.assertEquals('mod2.cl2.meth2', tlist[2])
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))