~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1025
1025
        self.assertNotEqual(otherdir2, mydir)
1026
1026
        self.assertFalse(otherdir2 == mydir)
1027
1027
 
 
1028
    def test_with_features(self):
 
1029
        tree = self.make_branch_and_tree('tree', format='2a')
 
1030
        tree.bzrdir.update_feature_flags({"bar": "required"})
 
1031
        self.assertRaises(errors.MissingFeature, bzrdir.BzrDir.open, 'tree')
 
1032
        bzrdir.BzrDirMetaFormat1.register_feature('bar')
 
1033
        self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, 'bar')
 
1034
        dir = bzrdir.BzrDir.open('tree')
 
1035
        self.assertEquals("required", dir._format.features.get("bar"))
 
1036
        tree.bzrdir.update_feature_flags({"bar": None, "nonexistant": None})
 
1037
        dir = bzrdir.BzrDir.open('tree')
 
1038
        self.assertEquals({}, dir._format.features)
 
1039
 
1028
1040
    def test_needs_conversion_different_working_tree(self):
1029
1041
        # meta1dirs need an conversion if any element is not the default.
1030
1042
        new_format = bzrdir.format_registry.make_bzrdir('dirstate')
1286
1298
    def _get_config(self):
1287
1299
        return config.TransportConfig(self._transport, 'branch.conf')
1288
1300
 
 
1301
    def _get_config_store(self):
 
1302
        return config.BranchStore(self)
 
1303
 
1289
1304
    def set_parent(self, parent):
1290
1305
        self._parent = parent
1291
1306
 
1435
1450
        self.assertRaises(errors.BzrError, converter.convert, tree.bzrdir,
1436
1451
            None)
1437
1452
 
 
1453
 
 
1454
class SampleBzrFormat(bzrdir.BzrFormat):
 
1455
 
 
1456
    @classmethod
 
1457
    def get_format_string(cls):
 
1458
        return "First line\n"
 
1459
 
 
1460
 
 
1461
class TestBzrFormat(TestCase):
 
1462
    """Tests for BzrFormat."""
 
1463
 
 
1464
    def test_as_string(self):
 
1465
        format = SampleBzrFormat()
 
1466
        format.features = {"foo": "required"}
 
1467
        self.assertEquals(format.as_string(),
 
1468
            "First line\n"
 
1469
            "required foo\n")
 
1470
        format.features["another"] = "optional"
 
1471
        self.assertEquals(format.as_string(),
 
1472
            "First line\n"
 
1473
            "required foo\n"
 
1474
            "optional another\n")
 
1475
 
 
1476
    def test_network_name(self):
 
1477
        # The network string should include the feature info
 
1478
        format = SampleBzrFormat()
 
1479
        format.features = {"foo": "required"}
 
1480
        self.assertEquals(
 
1481
            "First line\nrequired foo\n",
 
1482
            format.network_name())
 
1483
 
 
1484
    def test_from_string_no_features(self):
 
1485
        # No features
 
1486
        format = SampleBzrFormat.from_string(
 
1487
            "First line\n")
 
1488
        self.assertEquals({}, format.features)
 
1489
 
 
1490
    def test_from_string_with_feature(self):
 
1491
        # Proper feature
 
1492
        format = SampleBzrFormat.from_string(
 
1493
            "First line\nrequired foo\n")
 
1494
        self.assertEquals("required", format.features.get("foo"))
 
1495
 
 
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")
 
1500
 
 
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")
 
1505
 
 
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"))
 
1511
 
 
1512
    def test_eq(self):
 
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)
 
1521
 
 
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)
 
1530
 
 
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,
 
1536
            True)
 
1537
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1538
        SampleBzrFormat.register_feature("nested-trees")
 
1539
        format.check_support_status(True)
 
1540
 
 
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,
 
1546
            True)
 
1547
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1548
        SampleBzrFormat.register_feature("nested-trees")
 
1549
        format.check_support_status(True)
 
1550
 
 
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")
 
1557
 
 
1558
    def test_feature_with_space(self):
 
1559
        # spaces are not allowed in feature names
 
1560
        self.assertRaises(ValueError, SampleBzrFormat.register_feature,
 
1561
            "nested trees")