/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.252.1 by Jelmer Vernooij
Support storing revision id data.
2
# -*- encoding: utf-8 -*-
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.252.1 by Jelmer Vernooij
Support storing revision id data.
17
18
19
"""Tests for roundtripping text parsing."""
20
0.358.3 by Jelmer Vernooij
Enable absolute import.
21
from __future__ import absolute_import
0.252.1 by Jelmer Vernooij
Support storing revision id data.
22
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
23
from ....tests import TestCase
0.252.1 by Jelmer Vernooij
Support storing revision id data.
24
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from ..roundtrip import (
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
26
    CommitSupplement,
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
27
    deserialize_fileid_map,
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
28
    extract_bzr_metadata,
29
    generate_roundtripping_metadata,
30
    inject_bzr_metadata,
31
    parse_roundtripping_metadata,
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
32
    serialize_fileid_map,
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
33
    )
0.252.1 by Jelmer Vernooij
Support storing revision id data.
34
35
36
class RoundtripTests(TestCase):
37
38
    def test_revid(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
39
        md = parse_roundtripping_metadata(b"revision-id: foo\n")
6964.2.3 by Jelmer Vernooij
Review comments.
40
        self.assertEqual(b"foo", md.revision_id)
0.252.1 by Jelmer Vernooij
Support storing revision id data.
41
0.252.9 by Jelmer Vernooij
add extra tests.
42
    def test_parent_ids(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
43
        md = parse_roundtripping_metadata(b"parent-ids: foo bar\n")
6964.2.3 by Jelmer Vernooij
Review comments.
44
        self.assertEqual((b"foo", b"bar"), md.explicit_parent_ids)
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
45
46
    def test_properties(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
47
        md = parse_roundtripping_metadata(b"property-foop: blar\n")
6964.2.3 by Jelmer Vernooij
Review comments.
48
        self.assertEqual({b"foop": b"blar"}, md.properties)
0.252.9 by Jelmer Vernooij
add extra tests.
49
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
50
51
class FormatTests(TestCase):
52
0.252.9 by Jelmer Vernooij
add extra tests.
53
    def test_revid(self):
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
54
        metadata = CommitSupplement()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
55
        metadata.revision_id = b"bla"
6964.2.3 by Jelmer Vernooij
Review comments.
56
        self.assertEqual(b"revision-id: bla\n",
0.252.41 by Jelmer Vernooij
Fix Repository.all_revision_ids.
57
            generate_roundtripping_metadata(metadata, "utf-8"))
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
58
0.252.9 by Jelmer Vernooij
add extra tests.
59
    def test_parent_ids(self):
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
60
        metadata = CommitSupplement()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
61
        metadata.explicit_parent_ids = (b"foo", b"bar")
6964.2.3 by Jelmer Vernooij
Review comments.
62
        self.assertEqual(b"parent-ids: foo bar\n",
0.252.41 by Jelmer Vernooij
Fix Repository.all_revision_ids.
63
            generate_roundtripping_metadata(metadata, "utf-8"))
0.252.9 by Jelmer Vernooij
add extra tests.
64
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
65
    def test_properties(self):
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
66
        metadata = CommitSupplement()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
67
        metadata.properties = {b"foo": b"bar"}
6964.2.3 by Jelmer Vernooij
Review comments.
68
        self.assertEqual(b"property-foo: bar\n",
0.252.41 by Jelmer Vernooij
Fix Repository.all_revision_ids.
69
            generate_roundtripping_metadata(metadata, "utf-8"))
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
70
0.200.1019 by Jelmer Vernooij
Handle empty metadata.
71
    def test_empty(self):
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
72
        metadata = CommitSupplement()
6964.2.3 by Jelmer Vernooij
Review comments.
73
        self.assertEqual(b"",
0.200.1019 by Jelmer Vernooij
Handle empty metadata.
74
            generate_roundtripping_metadata(metadata, "utf-8"))
75
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
76
77
class ExtractMetadataTests(TestCase):
78
79
    def test_roundtrip(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
80
        (msg, metadata) = extract_bzr_metadata(b"""Foo
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
81
--BZR--
82
revision-id: foo
83
""")
6964.2.3 by Jelmer Vernooij
Review comments.
84
        self.assertEqual(b"Foo", msg)
85
        self.assertEqual(b"foo", metadata.revision_id)
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
86
87
88
class GenerateMetadataTests(TestCase):
89
90
    def test_roundtrip(self):
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
91
        metadata = CommitSupplement()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
92
        metadata.revision_id = b"myrevid"
93
        msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
6964.2.3 by Jelmer Vernooij
Review comments.
94
        self.assertEqual(b"""Foo
0.252.2 by Jelmer Vernooij
Add functions for adding metadata to revision messages.
95
--BZR--
96
revision-id: myrevid
97
""", msg)
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
98
0.200.1019 by Jelmer Vernooij
Handle empty metadata.
99
    def test_no_metadata(self):
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
100
        metadata = CommitSupplement()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
101
        msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
6964.2.3 by Jelmer Vernooij
Review comments.
102
        self.assertEqual(b"Foo", msg)
0.200.1019 by Jelmer Vernooij
Handle empty metadata.
103
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
104
105
class FileIdRoundTripTests(TestCase):
106
107
    def test_deserialize(self):
6964.2.3 by Jelmer Vernooij
Review comments.
108
        self.assertEqual({"bar/bla": b"fid"},
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
109
            deserialize_fileid_map(b"bar/bla\0fid\n"))
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
110
111
    def test_serialize(self):
7018.3.2 by Jelmer Vernooij
Fix some git tests.
112
        self.assertEqual([b"bar/bla\0fid\n"],
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
113
            serialize_fileid_map({"bar/bla": b"fid"}))
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
114