1025
1025
self.assertNotEqual(otherdir2, mydir)
1026
1026
self.assertFalse(otherdir2 == mydir)
1028
def test_with_features(self):
1029
tree = self.make_branch_and_tree('tree', format='2a')
1030
tree.bzrdir.control_transport.put_bytes(
1032
tree.bzrdir._format.get_format_string() + "required bar\n")
1033
self.assertRaises(errors.MissingFeature, bzrdir.BzrDir.open, 'tree')
1034
bzrdir.BzrDirMetaFormat1.register_feature('bar')
1035
self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, 'bar')
1036
dir = bzrdir.BzrDir.open('tree')
1037
self.assertEquals("required", dir._format.features.get("bar"))
1028
1039
def test_needs_conversion_different_working_tree(self):
1029
1040
# meta1dirs need an conversion if any element is not the default.
1030
1041
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1435
1446
self.assertRaises(errors.BzrError, converter.convert, tree.bzrdir,
1450
class SampleBzrFormat(bzrdir.BzrFormat):
1453
def get_format_string(cls):
1454
return "First line\n"
1457
class TestBzrFormat(TestCase):
1458
"""Tests for BzrFormat."""
1460
def test_as_string(self):
1461
format = SampleBzrFormat()
1462
format.features = {"foo": "required"}
1463
self.assertEquals(format.as_string(),
1466
format.features["another"] = "optional"
1467
self.assertEquals(format.as_string(),
1470
"optional another\n")
1472
def test_network_name(self):
1473
# The network string should include the feature info
1474
format = SampleBzrFormat()
1475
format.features = {"foo": "required"}
1477
"First line\nrequired foo\n",
1478
format.network_name())
1480
def test_from_string_no_features(self):
1482
format = SampleBzrFormat.from_string(
1484
self.assertEquals({}, format.features)
1486
def test_from_string_with_feature(self):
1488
format = SampleBzrFormat.from_string(
1489
"First line\nrequired foo\n")
1490
self.assertEquals("required", format.features.get("foo"))
1492
def test_from_string_format_string_mismatch(self):
1493
# The first line has to match the format string
1494
self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1495
"Second line\nrequired foo\n")
1497
def test_from_string_missing_space(self):
1498
# At least one space is required in the feature lines
1499
self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1500
"First line\nfoo\n")
1502
def test_from_string_with_spaces(self):
1503
# Feature with spaces (in case we add stuff like this in the future)
1504
format = SampleBzrFormat.from_string(
1505
"First line\nrequired foo with spaces\n")
1506
self.assertEquals("required", format.features.get("foo with spaces"))
1509
format1 = SampleBzrFormat()
1510
format1.features = {"nested-trees": "optional"}
1511
format2 = SampleBzrFormat()
1512
format2.features = {"nested-trees": "optional"}
1513
self.assertEquals(format1, format1)
1514
self.assertEquals(format1, format2)
1515
format3 = SampleBzrFormat()
1516
self.assertNotEquals(format1, format3)
1518
def test_check_support_status_optional(self):
1519
# Optional, so silently ignore
1520
format = SampleBzrFormat()
1521
format.features = {"nested-trees": "optional"}
1522
format.check_support_status(True)
1523
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1524
SampleBzrFormat.register_feature("nested-trees")
1525
format.check_support_status(True)
1527
def test_check_support_status_required(self):
1528
# Optional, so trigger an exception
1529
format = SampleBzrFormat()
1530
format.features = {"nested-trees": "required"}
1531
self.assertRaises(errors.MissingFeature, format.check_support_status,
1533
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1534
SampleBzrFormat.register_feature("nested-trees")
1535
format.check_support_status(True)
1537
def test_check_support_status_unknown(self):
1538
# treat unknown necessity as required
1539
format = SampleBzrFormat()
1540
format.features = {"nested-trees": "unknown"}
1541
self.assertRaises(errors.MissingFeature, format.check_support_status,
1543
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1544
SampleBzrFormat.register_feature("nested-trees")
1545
format.check_support_status(True)
1547
def test_feature_already_registered(self):
1548
# a feature can only be registered once
1549
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1550
SampleBzrFormat.register_feature("nested-trees")
1551
self.assertRaises(errors.FeatureAlreadyRegistered,
1552
SampleBzrFormat.register_feature, "nested-trees")
1554
def test_feature_with_space(self):
1555
# spaces are not allowed in feature names
1556
self.assertRaises(ValueError, SampleBzrFormat.register_feature,