253
253
def test_formats_to_scenarios(self):
254
254
"""The adapter can generate all the scenarios needed."""
255
from bzrlib.tests.repository_implementations import formats_to_scenarios
255
from bzrlib.tests.per_repository import formats_to_scenarios
256
256
formats = [("(c)", remote.RemoteRepositoryFormat()),
257
257
("(d)", repository.format_registry.get(
258
258
'Bazaar pack repository format 1 (needs bzr 0.92)\n'))]
293
293
"""Tests for the test adaption facilities."""
295
295
def test_adapt_applies_scenarios(self):
296
from bzrlib.tests.repository_implementations import TestScenarioApplier
296
from bzrlib.tests.per_repository import TestScenarioApplier
297
297
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
298
298
adapter = TestScenarioApplier()
299
299
adapter.scenarios = [("1", "dict"), ("2", "settings")]
307
307
(input_test, ("2", "settings"))], calls)
309
309
def test_adapt_test_to_scenario(self):
310
from bzrlib.tests.repository_implementations import TestScenarioApplier
310
from bzrlib.tests.per_repository import TestScenarioApplier
311
311
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
312
312
adapter = TestScenarioApplier()
313
313
# setup two adapted tests
422
422
tests = list(iter(suite))
423
423
# XXX We should not have tests fail as we add more scenarios
424
424
# abentley 20080412
425
self.assertEqual(5, len(tests))
425
self.assertEqual(6, len(tests))
426
426
# this must match the default format setp up in
427
427
# TreeTestProviderAdapter.adapt
428
428
default_format = workingtree.WorkingTreeFormat3
1785
1785
def test_condition_id_startswith(self):
1786
1786
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1787
start = klass + 'test_condition_id_starts'
1788
test_names = [klass + 'test_condition_id_startswith']
1787
start1 = klass + 'test_condition_id_starts'
1788
start2 = klass + 'test_condition_id_in'
1789
test_names = [ klass + 'test_condition_id_in_list',
1790
klass + 'test_condition_id_startswith',
1789
1792
filtered_suite = filter_suite_by_condition(
1790
self.suite, tests.condition_id_startswith(start))
1791
my_pattern = 'TestSelftestFiltering.*test_condition_id_startswith'
1792
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1793
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1793
self.suite, tests.condition_id_startswith([start1, start2]))
1794
self.assertEqual(test_names, _test_ids(filtered_suite))
1795
1796
def test_condition_isinstance(self):
1796
1797
filtered_suite = filter_suite_by_condition(self.suite,
1850
1851
def test_filter_suite_by_id_startswith(self):
1851
1852
# By design this test may fail if another test is added whose name also
1852
# begins with the start value used.
1853
# begins with one of the start value used.
1853
1854
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1854
start = klass + 'test_filter_suite_by_id_starts'
1855
test_list = [klass + 'test_filter_suite_by_id_startswith']
1856
filtered_suite = tests.filter_suite_by_id_startswith(self.suite, start)
1857
filtered_names = _test_ids(filtered_suite)
1855
start1 = klass + 'test_filter_suite_by_id_starts'
1856
start2 = klass + 'test_filter_suite_by_id_li'
1857
test_list = [klass + 'test_filter_suite_by_id_list',
1858
klass + 'test_filter_suite_by_id_startswith',
1860
filtered_suite = tests.filter_suite_by_id_startswith(
1861
self.suite, [start1, start2])
1858
1862
self.assertEqual(
1860
['bzrlib.tests.test_selftest.'
1861
'TestSelftestFiltering.test_filter_suite_by_id_startswith'])
1864
_test_ids(filtered_suite),
1863
1867
def test_preserve_input(self):
1864
1868
# NB: Surely this is something in the stdlib to do this?
2171
2175
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2172
2176
self.assertEquals([], _test_ids(suite))
2179
class TestTestPrefixRegistry(tests.TestCase):
2181
def _get_registry(self):
2182
tp_registry = tests.TestPrefixAliasRegistry()
2185
def test_register_new_prefix(self):
2186
tpr = self._get_registry()
2187
tpr.register('foo', 'fff.ooo.ooo')
2188
self.assertEquals('fff.ooo.ooo', tpr.get('foo'))
2190
def test_register_existing_prefix(self):
2191
tpr = self._get_registry()
2192
tpr.register('bar', 'bbb.aaa.rrr')
2193
tpr.register('bar', 'bBB.aAA.rRR')
2194
self.assertEquals('bbb.aaa.rrr', tpr.get('bar'))
2195
self.assertContainsRe(self._get_log(keep_log_file=True),
2196
r'.*bar.*bbb.aaa.rrr.*bBB.aAA.rRR')
2198
def test_get_unknown_prefix(self):
2199
tpr = self._get_registry()
2200
self.assertRaises(KeyError, tpr.get, 'I am not a prefix')
2202
def test_resolve_prefix(self):
2203
tpr = self._get_registry()
2204
tpr.register('bar', 'bb.aa.rr')
2205
self.assertEquals('bb.aa.rr', tpr.resolve_alias('bar'))
2207
def test_resolve_unknown_alias(self):
2208
tpr = self._get_registry()
2209
self.assertRaises(errors.BzrCommandError,
2210
tpr.resolve_alias, 'I am not a prefix')
2212
def test_predefined_prefixes(self):
2213
tpr = tests.test_prefix_alias_registry
2214
self.assertEquals('bzrlib', tpr.resolve_alias('bzrlib'))
2215
self.assertEquals('bzrlib.doc', tpr.resolve_alias('bd'))
2216
self.assertEquals('bzrlib.utils', tpr.resolve_alias('bu'))
2217
self.assertEquals('bzrlib.tests', tpr.resolve_alias('bt'))
2218
self.assertEquals('bzrlib.tests.blackbox', tpr.resolve_alias('bb'))
2219
self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))