513
517
# Clone source into directory
514
518
target = source_bzrdir.clone(self.get_url('parent/target'))
520
def test_format_initialize_on_transport_ex_stacked_on(self):
521
# trunk is a stackable format. Note that its in the same server area
522
# which is what launchpad does, but not sufficient to exercise the
524
trunk = self.make_branch('trunk', format='1.9')
525
t = self.get_transport('stacked')
526
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
527
repo_name = old_fmt.repository_format.network_name()
528
# Should end up with a 1.9 format (stackable)
529
repo, control, require_stacking, repo_policy = \
530
old_fmt.initialize_on_transport_ex(t,
531
repo_format_name=repo_name, stacked_on='../trunk',
534
# Repositories are open write-locked
535
self.assertTrue(repo.is_write_locked())
536
self.addCleanup(repo.unlock)
538
repo = control.open_repository()
539
self.assertIsInstance(control, bzrdir.BzrDir)
540
opened = bzrdir.BzrDir.open(t.base)
541
if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
542
self.assertEqual(control._format.network_name(),
543
old_fmt.network_name())
544
self.assertEqual(control._format.network_name(),
545
opened._format.network_name())
546
self.assertEqual(control.__class__, opened.__class__)
547
self.assertLength(1, repo._fallback_repositories)
516
549
def test_sprout_obeys_stacking_policy(self):
517
550
child_branch, new_child_transport = self.prepare_default_stacking()
518
551
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
1368
1416
self._transport.put_bytes("a.~1~", "some content")
1369
1417
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1420
class TestMeta1DirColoFormat(TestCaseWithTransport):
1421
"""Tests specific to the meta1 dir with colocated branches format."""
1423
def test_supports_colo(self):
1424
format = bzrdir.BzrDirMetaFormat1Colo()
1425
self.assertTrue(format.colocated_branches)
1427
def test_upgrade_from_2a(self):
1428
tree = self.make_branch_and_tree('.', format='2a')
1429
format = bzrdir.BzrDirMetaFormat1Colo()
1430
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1431
converter = tree.bzrdir._format.get_converter(format)
1432
result = converter.convert(tree.bzrdir, None)
1433
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1434
self.assertFalse(result.needs_format_conversion(format))
1436
def test_downgrade_to_2a(self):
1437
tree = self.make_branch_and_tree('.', format='development-colo')
1438
format = bzrdir.BzrDirMetaFormat1()
1439
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1440
converter = tree.bzrdir._format.get_converter(format)
1441
result = converter.convert(tree.bzrdir, None)
1442
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1443
self.assertFalse(result.needs_format_conversion(format))
1445
def test_downgrade_to_2a_too_many_branches(self):
1446
tree = self.make_branch_and_tree('.', format='development-colo')
1447
tree.bzrdir.create_branch(name="another-colocated-branch")
1448
converter = tree.bzrdir._format.get_converter(
1449
bzrdir.BzrDirMetaFormat1())
1450
self.assertRaises(errors.BzrError, converter.convert, tree.bzrdir,
1454
class SampleBzrFormat(bzrdir.BzrFormat):
1457
def get_format_string(cls):
1458
return "First line\n"
1461
class TestBzrFormat(TestCase):
1462
"""Tests for BzrFormat."""
1464
def test_as_string(self):
1465
format = SampleBzrFormat()
1466
format.features = {"foo": "required"}
1467
self.assertEquals(format.as_string(),
1470
format.features["another"] = "optional"
1471
self.assertEquals(format.as_string(),
1474
"optional another\n")
1476
def test_network_name(self):
1477
# The network string should include the feature info
1478
format = SampleBzrFormat()
1479
format.features = {"foo": "required"}
1481
"First line\nrequired foo\n",
1482
format.network_name())
1484
def test_from_string_no_features(self):
1486
format = SampleBzrFormat.from_string(
1488
self.assertEquals({}, format.features)
1490
def test_from_string_with_feature(self):
1492
format = SampleBzrFormat.from_string(
1493
"First line\nrequired foo\n")
1494
self.assertEquals("required", format.features.get("foo"))
1496
def test_from_string_format_string_mismatch(self):
1497
# The first line has to match the format string
1498
self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1499
"Second line\nrequired foo\n")
1501
def test_from_string_missing_space(self):
1502
# At least one space is required in the feature lines
1503
self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1504
"First line\nfoo\n")
1506
def test_from_string_with_spaces(self):
1507
# Feature with spaces (in case we add stuff like this in the future)
1508
format = SampleBzrFormat.from_string(
1509
"First line\nrequired foo with spaces\n")
1510
self.assertEquals("required", format.features.get("foo with spaces"))
1513
format1 = SampleBzrFormat()
1514
format1.features = {"nested-trees": "optional"}
1515
format2 = SampleBzrFormat()
1516
format2.features = {"nested-trees": "optional"}
1517
self.assertEquals(format1, format1)
1518
self.assertEquals(format1, format2)
1519
format3 = SampleBzrFormat()
1520
self.assertNotEquals(format1, format3)
1522
def test_check_support_status_optional(self):
1523
# Optional, so silently ignore
1524
format = SampleBzrFormat()
1525
format.features = {"nested-trees": "optional"}
1526
format.check_support_status(True)
1527
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1528
SampleBzrFormat.register_feature("nested-trees")
1529
format.check_support_status(True)
1531
def test_check_support_status_required(self):
1532
# Optional, so trigger an exception
1533
format = SampleBzrFormat()
1534
format.features = {"nested-trees": "required"}
1535
self.assertRaises(errors.MissingFeature, format.check_support_status,
1537
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1538
SampleBzrFormat.register_feature("nested-trees")
1539
format.check_support_status(True)
1541
def test_check_support_status_unknown(self):
1542
# treat unknown necessity as required
1543
format = SampleBzrFormat()
1544
format.features = {"nested-trees": "unknown"}
1545
self.assertRaises(errors.MissingFeature, format.check_support_status,
1547
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1548
SampleBzrFormat.register_feature("nested-trees")
1549
format.check_support_status(True)
1551
def test_feature_already_registered(self):
1552
# a feature can only be registered once
1553
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1554
SampleBzrFormat.register_feature("nested-trees")
1555
self.assertRaises(errors.FeatureAlreadyRegistered,
1556
SampleBzrFormat.register_feature, "nested-trees")
1558
def test_feature_with_space(self):
1559
# spaces are not allowed in feature names
1560
self.assertRaises(ValueError, SampleBzrFormat.register_feature,