/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_roundtrip.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
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
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
 
 
19
"""Tests for roundtripping text parsing."""
 
20
 
 
21
from __future__ import absolute_import
 
22
 
 
23
from ...tests import TestCase
 
24
 
 
25
from ..roundtrip import (
 
26
    CommitSupplement,
 
27
    extract_bzr_metadata,
 
28
    generate_roundtripping_metadata,
 
29
    inject_bzr_metadata,
 
30
    parse_roundtripping_metadata,
 
31
    )
 
32
 
 
33
 
 
34
class RoundtripTests(TestCase):
 
35
 
 
36
    def test_revid(self):
 
37
        md = parse_roundtripping_metadata(b"revision-id: foo\n")
 
38
        self.assertEqual(b"foo", md.revision_id)
 
39
 
 
40
    def test_parent_ids(self):
 
41
        md = parse_roundtripping_metadata(b"parent-ids: foo bar\n")
 
42
        self.assertEqual((b"foo", b"bar"), md.explicit_parent_ids)
 
43
 
 
44
    def test_properties(self):
 
45
        md = parse_roundtripping_metadata(b"property-foop: blar\n")
 
46
        self.assertEqual({b"foop": b"blar"}, md.properties)
 
47
 
 
48
 
 
49
class FormatTests(TestCase):
 
50
 
 
51
    def test_revid(self):
 
52
        metadata = CommitSupplement()
 
53
        metadata.revision_id = b"bla"
 
54
        self.assertEqual(b"revision-id: bla\n",
 
55
                         generate_roundtripping_metadata(metadata, "utf-8"))
 
56
 
 
57
    def test_parent_ids(self):
 
58
        metadata = CommitSupplement()
 
59
        metadata.explicit_parent_ids = (b"foo", b"bar")
 
60
        self.assertEqual(b"parent-ids: foo bar\n",
 
61
                         generate_roundtripping_metadata(metadata, "utf-8"))
 
62
 
 
63
    def test_properties(self):
 
64
        metadata = CommitSupplement()
 
65
        metadata.properties = {b"foo": b"bar"}
 
66
        self.assertEqual(b"property-foo: bar\n",
 
67
                         generate_roundtripping_metadata(metadata, "utf-8"))
 
68
 
 
69
    def test_empty(self):
 
70
        metadata = CommitSupplement()
 
71
        self.assertEqual(b"",
 
72
                         generate_roundtripping_metadata(metadata, "utf-8"))
 
73
 
 
74
 
 
75
class ExtractMetadataTests(TestCase):
 
76
 
 
77
    def test_roundtrip(self):
 
78
        (msg, metadata) = extract_bzr_metadata(b"""Foo
 
79
--BZR--
 
80
revision-id: foo
 
81
""")
 
82
        self.assertEqual(b"Foo", msg)
 
83
        self.assertEqual(b"foo", metadata.revision_id)
 
84
 
 
85
 
 
86
class GenerateMetadataTests(TestCase):
 
87
 
 
88
    def test_roundtrip(self):
 
89
        metadata = CommitSupplement()
 
90
        metadata.revision_id = b"myrevid"
 
91
        msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
 
92
        self.assertEqual(b"""Foo
 
93
--BZR--
 
94
revision-id: myrevid
 
95
""", msg)
 
96
 
 
97
    def test_no_metadata(self):
 
98
        metadata = CommitSupplement()
 
99
        msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
 
100
        self.assertEqual(b"Foo", msg)