421
422
tests = list(iter(suite))
422
423
# XXX We should not have tests fail as we add more scenarios
423
424
# abentley 20080412
424
self.assertEqual(5, len(tests))
425
self.assertEqual(6, len(tests))
425
426
# this must match the default format setp up in
426
427
# TreeTestProviderAdapter.adapt
427
428
default_format = workingtree.WorkingTreeFormat3
547
548
self.assertEqual(format.repository_format.__class__,
548
549
tree.branch.repository._format.__class__)
551
def test_make_branch_builder(self):
552
builder = self.make_branch_builder('dir')
553
self.assertIsInstance(builder, branchbuilder.BranchBuilder)
554
# Guard against regression into MemoryTransport leaking
555
# files to disk instead of keeping them in memory.
556
self.failIf(osutils.lexists('dir'))
558
def test_make_branch_builder_with_format(self):
559
# Use a repo layout that doesn't conform to a 'named' layout, to ensure
560
# that the format objects are used.
561
format = bzrdir.BzrDirMetaFormat1()
562
repo_format = weaverepo.RepositoryFormat7()
563
format.repository_format = repo_format
564
builder = self.make_branch_builder('dir', format=format)
565
the_branch = builder.get_branch()
566
# Guard against regression into MemoryTransport leaking
567
# files to disk instead of keeping them in memory.
568
self.failIf(osutils.lexists('dir'))
569
self.assertEqual(format.repository_format.__class__,
570
the_branch.repository._format.__class__)
571
self.assertEqual(repo_format.get_format_string(),
572
self.get_transport().get_bytes(
573
'dir/.bzr/repository/format'))
575
def test_make_branch_builder_with_format_name(self):
576
builder = self.make_branch_builder('dir', format='knit')
577
the_branch = builder.get_branch()
578
# Guard against regression into MemoryTransport leaking
579
# files to disk instead of keeping them in memory.
580
self.failIf(osutils.lexists('dir'))
581
dir_format = bzrdir.format_registry.make_bzrdir('knit')
582
self.assertEqual(dir_format.repository_format.__class__,
583
the_branch.repository._format.__class__)
584
self.assertEqual('Bazaar-NG Knit Repository Format 1',
585
self.get_transport().get_bytes(
586
'dir/.bzr/repository/format'))
550
588
def test_safety_net(self):
551
589
"""No test should modify the safety .bzr directory.
605
643
self.assertRaises(AssertionError, self.assertIsDirectory, 'a_file', t)
606
644
self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
646
def test_make_branch_builder(self):
647
builder = self.make_branch_builder('dir')
648
rev_id = builder.build_commit()
649
self.failUnlessExists('dir')
650
a_dir = bzrdir.BzrDir.open('dir')
651
self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
652
a_branch = a_dir.open_branch()
653
builder_branch = builder.get_branch()
654
self.assertEqual(a_branch.base, builder_branch.base)
655
self.assertEqual((1, rev_id), builder_branch.last_revision_info())
656
self.assertEqual((1, rev_id), a_branch.last_revision_info())
609
659
class TestTestCaseTransports(TestCaseWithTransport):
1735
1785
def test_condition_id_startswith(self):
1736
1786
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1737
start = klass + 'test_condition_id_starts'
1738
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',
1739
1792
filtered_suite = filter_suite_by_condition(
1740
self.suite, tests.condition_id_startswith(start))
1741
my_pattern = 'TestSelftestFiltering.*test_condition_id_startswith'
1742
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1743
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))
1745
1796
def test_condition_isinstance(self):
1746
1797
filtered_suite = filter_suite_by_condition(self.suite,
1800
1851
def test_filter_suite_by_id_startswith(self):
1801
1852
# By design this test may fail if another test is added whose name also
1802
# begins with the start value used.
1853
# begins with one of the start value used.
1803
1854
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1804
start = klass + 'test_filter_suite_by_id_starts'
1805
test_list = [klass + 'test_filter_suite_by_id_startswith']
1806
filtered_suite = tests.filter_suite_by_id_startswith(self.suite, start)
1807
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])
1808
1862
self.assertEqual(
1810
['bzrlib.tests.test_selftest.'
1811
'TestSelftestFiltering.test_filter_suite_by_id_startswith'])
1864
_test_ids(filtered_suite),
1813
1867
def test_preserve_input(self):
1814
1868
# NB: Surely this is something in the stdlib to do this?
2121
2175
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2122
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'))