~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-22 18:52:58 UTC
  • mfrom: (6213.1.55 feature-flags)
  • Revision ID: pqm@pqm.ubuntu.com-20111222185258-wgcba8590pbw5sf1
(jelmer) Add support for feature flags in bzr formats. (Jelmer Vernooij)

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.control_transport.put_bytes(
 
1031
            'branch-format',
 
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"))
 
1038
 
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,
1436
1447
            None)
1437
1448
 
 
1449
 
 
1450
class SampleBzrFormat(bzrdir.BzrFormat):
 
1451
 
 
1452
    @classmethod
 
1453
    def get_format_string(cls):
 
1454
        return "First line\n"
 
1455
 
 
1456
 
 
1457
class TestBzrFormat(TestCase):
 
1458
    """Tests for BzrFormat."""
 
1459
 
 
1460
    def test_as_string(self):
 
1461
        format = SampleBzrFormat()
 
1462
        format.features = {"foo": "required"}
 
1463
        self.assertEquals(format.as_string(),
 
1464
            "First line\n"
 
1465
            "required foo\n")
 
1466
        format.features["another"] = "optional"
 
1467
        self.assertEquals(format.as_string(),
 
1468
            "First line\n"
 
1469
            "required foo\n"
 
1470
            "optional another\n")
 
1471
 
 
1472
    def test_network_name(self):
 
1473
        # The network string should include the feature info
 
1474
        format = SampleBzrFormat()
 
1475
        format.features = {"foo": "required"}
 
1476
        self.assertEquals(
 
1477
            "First line\nrequired foo\n",
 
1478
            format.network_name())
 
1479
 
 
1480
    def test_from_string_no_features(self):
 
1481
        # No features
 
1482
        format = SampleBzrFormat.from_string(
 
1483
            "First line\n")
 
1484
        self.assertEquals({}, format.features)
 
1485
 
 
1486
    def test_from_string_with_feature(self):
 
1487
        # Proper feature
 
1488
        format = SampleBzrFormat.from_string(
 
1489
            "First line\nrequired foo\n")
 
1490
        self.assertEquals("required", format.features.get("foo"))
 
1491
 
 
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")
 
1496
 
 
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")
 
1501
 
 
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"))
 
1507
 
 
1508
    def test_eq(self):
 
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)
 
1517
 
 
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)
 
1526
 
 
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,
 
1532
            True)
 
1533
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1534
        SampleBzrFormat.register_feature("nested-trees")
 
1535
        format.check_support_status(True)
 
1536
 
 
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,
 
1542
            True)
 
1543
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1544
        SampleBzrFormat.register_feature("nested-trees")
 
1545
        format.check_support_status(True)
 
1546
 
 
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")
 
1553
 
 
1554
    def test_feature_with_space(self):
 
1555
        # spaces are not allowed in feature names
 
1556
        self.assertRaises(ValueError, SampleBzrFormat.register_feature,
 
1557
            "nested trees")