Beispiel #1
0
class LabeledBranchTest(DownIterateTest):
    def test_dupe_branch_collection(self):
        def fn():
            return [
                Revision("a", ()),
                Revision("b", ("a", )),
                Revision("c", ("b", ), branch_labels=["xy1"]),
                Revision("d", ()),
                Revision("e", ("d", ), branch_labels=["xy1"]),
                Revision("f", ("e", )),
            ]

        assert_raises_message(
            RevisionError,
            r"Branch name 'xy1' in revision (?:e|c) already "
            "used by revision (?:e|c)",
            getattr,
            RevisionMap(fn),
            "_revision_map",
        )

    def test_filter_for_lineage_labeled_head_across_merge(self):
        def fn():
            return [
                Revision("a", ()),
                Revision("b", ("a", )),
                Revision("c1", ("b", ), branch_labels="c1branch"),
                Revision("c2", ("b", )),
                Revision("d", ("c1", "c2")),
            ]

        map_ = RevisionMap(fn)
        c1 = map_.get_revision("c1")
        c2 = map_.get_revision("c2")
        d = map_.get_revision("d")
        eq_(map_.filter_for_lineage([c1, c2, d], "c1branch@head"), [c1, c2, d])

    def test_filter_for_lineage_heads(self):
        eq_(
            self.map.filter_for_lineage([self.map.get_revision("f")], "heads"),
            [self.map.get_revision("f")],
        )

    def setUp(self):
        self.map = RevisionMap(lambda: [
            Revision("a", (), branch_labels="abranch"),
            Revision("b", ("a", )),
            Revision("somelongername", ("b", )),
            Revision("c", ("somelongername", )),
            Revision("d", ()),
            Revision("e", ("d", ), branch_labels=["ebranch"]),
            Revision("someothername", ("e", )),
            Revision("f", ("someothername", )),
        ])

    def test_get_base_revisions_labeled(self):
        eq_(self.map._get_base_revisions("somelongername@base"), ["a"])

    def test_get_current_named_rev(self):
        eq_(self.map.get_revision("ebranch@head"), self.map.get_revision("f"))

    def test_get_base_revisions(self):
        eq_(self.map._get_base_revisions("base"), ["a", "d"])

    def test_iterate_head_to_named_base(self):
        self._assert_iteration("heads", "ebranch@base",
                               ["f", "someothername", "e", "d"])

        self._assert_iteration("heads", "abranch@base",
                               ["c", "somelongername", "b", "a"])

    def test_iterate_named_head_to_base(self):
        self._assert_iteration("ebranch@head", "base",
                               ["f", "someothername", "e", "d"])

        self._assert_iteration("abranch@head", "base",
                               ["c", "somelongername", "b", "a"])

    def test_iterate_named_head_to_heads(self):
        self._assert_iteration("heads", "ebranch@head", ["f"], inclusive=True)

    def test_iterate_named_rev_to_heads(self):
        self._assert_iteration(
            "heads",
            "ebranch@d",
            ["f", "someothername", "e", "d"],
            inclusive=True,
        )

    def test_iterate_head_to_version_specific_base(self):
        self._assert_iteration("heads", "e@base",
                               ["f", "someothername", "e", "d"])

        self._assert_iteration("heads", "c@base",
                               ["c", "somelongername", "b", "a"])

    def test_iterate_to_branch_at_rev(self):
        self._assert_iteration("heads", "ebranch@d",
                               ["f", "someothername", "e", "d"])

    def test_branch_w_down_relative(self):
        self._assert_iteration("heads", "ebranch@-2",
                               ["f", "someothername", "e"])

    def test_branch_w_up_relative(self):
        self._assert_iteration("ebranch@+2", "base",
                               ["someothername", "e", "d"])

    def test_partial_id_resolve(self):
        eq_(self.map.get_revision("ebranch@some").revision, "someothername")
        eq_(self.map.get_revision("abranch@some").revision, "somelongername")

    def test_partial_id_resolve_too_short(self):
        assert_raises_message(
            RevisionError,
            "No such revision or branch 'sos'; please ensure at least "
            "four characters are present for partial revision identifier "
            "matches",
            self.map.get_revision,
            "ebranch@sos",
        )

    def test_branch_at_heads(self):
        eq_(self.map.get_revision("abranch@heads").revision, "c")

    def test_branch_at_syntax(self):
        eq_(self.map.get_revision("abranch@head").revision, "c")
        eq_(self.map.get_revision("abranch@base"), None)
        eq_(self.map.get_revision("ebranch@head").revision, "f")
        eq_(self.map.get_revision("abranch@base"), None)
        eq_(self.map.get_revision("ebranch@d").revision, "d")

    def test_branch_at_self(self):
        eq_(self.map.get_revision("ebranch@ebranch").revision, "e")

    def test_retrieve_branch_revision(self):
        eq_(self.map.get_revision("abranch").revision, "a")
        eq_(self.map.get_revision("ebranch").revision, "e")

    def test_rev_not_in_branch(self):
        assert_raises_message(
            RevisionError,
            "Revision b is not a member of branch 'ebranch'",
            self.map.get_revision,
            "ebranch@b",
        )

        assert_raises_message(
            RevisionError,
            "Revision d is not a member of branch 'abranch'",
            self.map.get_revision,
            "abranch@d",
        )

    def test_actually_short_rev_name(self):
        eq_(self.map.get_revision("e").revision, "e")

    def test_no_revision_exists(self):
        assert_raises_message(
            RevisionError,
            "No such revision or branch 'qprstuv'$",
            self.map.get_revision,
            "abranch@qprstuv",
        )

        assert_raises_message(
            RevisionError,
            "No such revision or branch 'qpr'; please ensure at least "
            "four characters are present for partial revision identifier "
            "matches$",
            self.map.get_revision,
            "abranch@qpr",
        )

    def test_not_actually_a_branch(self):
        eq_(self.map.get_revision("e@d").revision, "d")

    def test_not_actually_a_branch_partial_resolution(self):
        eq_(self.map.get_revision("someoth@d").revision, "d")

    def test_no_such_branch(self):
        assert_raises_message(RevisionError, "No such branch: 'x'",
                              self.map.get_revision, "x@d")
Beispiel #2
0
class LabeledBranchTest(DownIterateTest):
    def test_dupe_branch_collection(self):
        fn = lambda: [
            Revision('a', ()),
            Revision('b', ('a',)),
            Revision('c', ('b',), branch_labels=['xy1']),
            Revision('d', ()),
            Revision('e', ('d',), branch_labels=['xy1']),
            Revision('f', ('e',))
        ]
        assert_raises_message(
            RevisionError,
            r"Branch name 'xy1' in revision (?:e|c) already "
            "used by revision (?:e|c)",
            getattr, RevisionMap(fn), "_revision_map"
        )

    def test_filter_for_lineage_labeled_head_across_merge(self):
        fn = lambda: [
            Revision('a', ()),
            Revision('b', ('a', )),
            Revision('c1', ('b', ), branch_labels='c1branch'),
            Revision('c2', ('b', )),
            Revision('d', ('c1', 'c2')),

        ]
        map_ = RevisionMap(fn)
        c1 = map_.get_revision('c1')
        c2 = map_.get_revision('c2')
        d = map_.get_revision('d')
        eq_(
            map_.filter_for_lineage([c1, c2, d], "c1branch@head"),
            [c1, c2, d]
        )

    def test_filter_for_lineage_heads(self):
        eq_(
            self.map.filter_for_lineage(
                [self.map.get_revision("f")],
                "heads"
            ),
            [self.map.get_revision("f")]
        )

    def setUp(self):
        self.map = RevisionMap(lambda: [
            Revision('a', (), branch_labels='abranch'),
            Revision('b', ('a',)),
            Revision('somelongername', ('b',)),
            Revision('c', ('somelongername',)),
            Revision('d', ()),
            Revision('e', ('d',), branch_labels=['ebranch']),
            Revision('someothername', ('e',)),
            Revision('f', ('someothername',)),
        ])

    def test_get_base_revisions_labeled(self):
        eq_(
            self.map._get_base_revisions("somelongername@base"),
            ['a']
        )

    def test_get_current_named_rev(self):
        eq_(
            self.map.get_revision("ebranch@head"),
            self.map.get_revision("f")
        )

    def test_get_base_revisions(self):
        eq_(
            self.map._get_base_revisions("base"),
            ['a', 'd']
        )

    def test_iterate_head_to_named_base(self):
        self._assert_iteration(
            "heads", "ebranch@base",
            ['f', 'someothername', 'e', 'd']
        )

        self._assert_iteration(
            "heads", "abranch@base",
            ['c', 'somelongername', 'b', 'a']
        )

    def test_iterate_named_head_to_base(self):
        self._assert_iteration(
            "ebranch@head", "base",
            ['f', 'someothername', 'e', 'd']
        )

        self._assert_iteration(
            "abranch@head", "base",
            ['c', 'somelongername', 'b', 'a']
        )

    def test_iterate_named_head_to_heads(self):
        self._assert_iteration(
            "heads", "ebranch@head",
            ['f'],
            inclusive=True
        )

    def test_iterate_named_rev_to_heads(self):
        self._assert_iteration(
            "heads", "ebranch@d",
            ['f', 'someothername', 'e', 'd'],
            inclusive=True
        )

    def test_iterate_head_to_version_specific_base(self):
        self._assert_iteration(
            "heads", "e@base",
            ['f', 'someothername', 'e', 'd']
        )

        self._assert_iteration(
            "heads", "c@base",
            ['c', 'somelongername', 'b', 'a']
        )

    def test_iterate_to_branch_at_rev(self):
        self._assert_iteration(
            "heads", "ebranch@d",
            ['f', 'someothername', 'e', 'd']
        )

    def test_branch_w_down_relative(self):
        self._assert_iteration(
            "heads", "ebranch@-2",
            ['f', 'someothername', 'e']
        )

    def test_branch_w_up_relative(self):
        self._assert_iteration(
            "ebranch@+2", "base",
            ['someothername', 'e', 'd']
        )

    def test_partial_id_resolve(self):
        eq_(self.map.get_revision("ebranch@some").revision, "someothername")
        eq_(self.map.get_revision("abranch@some").revision, "somelongername")

    def test_branch_at_heads(self):
        eq_(
            self.map.get_revision("abranch@heads").revision,
            "c"
        )

    def test_branch_at_syntax(self):
        eq_(self.map.get_revision("abranch@head").revision, 'c')
        eq_(self.map.get_revision("abranch@base"), None)
        eq_(self.map.get_revision("ebranch@head").revision, 'f')
        eq_(self.map.get_revision("abranch@base"), None)
        eq_(self.map.get_revision("ebranch@d").revision, 'd')

    def test_branch_at_self(self):
        eq_(self.map.get_revision("ebranch@ebranch").revision, 'e')

    def test_retrieve_branch_revision(self):
        eq_(self.map.get_revision("abranch").revision, 'a')
        eq_(self.map.get_revision("ebranch").revision, 'e')

    def test_rev_not_in_branch(self):
        assert_raises_message(
            RevisionError,
            "Revision b is not a member of branch 'ebranch'",
            self.map.get_revision, "ebranch@b"
        )

        assert_raises_message(
            RevisionError,
            "Revision d is not a member of branch 'abranch'",
            self.map.get_revision, "abranch@d"
        )

    def test_no_revision_exists(self):
        assert_raises_message(
            RevisionError,
            "No such revision or branch 'q'",
            self.map.get_revision, "abranch@q"
        )

    def test_not_actually_a_branch(self):
        eq_(self.map.get_revision("e@d").revision, "d")

    def test_not_actually_a_branch_partial_resolution(self):
        eq_(self.map.get_revision("someoth@d").revision, "d")

    def test_no_such_branch(self):
        assert_raises_message(
            RevisionError,
            "No such branch: 'x'",
            self.map.get_revision, "x@d"
        )