/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: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

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 ...tests import TestCase
22
 
 
23
 
from ..roundtrip import (
24
 
    CommitSupplement,
25
 
    extract_bzr_metadata,
26
 
    generate_roundtripping_metadata,
27
 
    inject_bzr_metadata,
28
 
    parse_roundtripping_metadata,
29
 
    )
30
 
 
31
 
 
32
 
class RoundtripTests(TestCase):
33
 
 
34
 
    def test_revid(self):
35
 
        md = parse_roundtripping_metadata(b"revision-id: foo\n")
36
 
        self.assertEqual(b"foo", md.revision_id)
37
 
 
38
 
    def test_parent_ids(self):
39
 
        md = parse_roundtripping_metadata(b"parent-ids: foo bar\n")
40
 
        self.assertEqual((b"foo", b"bar"), md.explicit_parent_ids)
41
 
 
42
 
    def test_properties(self):
43
 
        md = parse_roundtripping_metadata(b"property-foop: blar\n")
44
 
        self.assertEqual({b"foop": b"blar"}, md.properties)
45
 
 
46
 
 
47
 
class FormatTests(TestCase):
48
 
 
49
 
    def test_revid(self):
50
 
        metadata = CommitSupplement()
51
 
        metadata.revision_id = b"bla"
52
 
        self.assertEqual(b"revision-id: bla\n",
53
 
                         generate_roundtripping_metadata(metadata, "utf-8"))
54
 
 
55
 
    def test_parent_ids(self):
56
 
        metadata = CommitSupplement()
57
 
        metadata.explicit_parent_ids = (b"foo", b"bar")
58
 
        self.assertEqual(b"parent-ids: foo bar\n",
59
 
                         generate_roundtripping_metadata(metadata, "utf-8"))
60
 
 
61
 
    def test_properties(self):
62
 
        metadata = CommitSupplement()
63
 
        metadata.properties = {b"foo": b"bar"}
64
 
        self.assertEqual(b"property-foo: bar\n",
65
 
                         generate_roundtripping_metadata(metadata, "utf-8"))
66
 
 
67
 
    def test_empty(self):
68
 
        metadata = CommitSupplement()
69
 
        self.assertEqual(b"",
70
 
                         generate_roundtripping_metadata(metadata, "utf-8"))
71
 
 
72
 
 
73
 
class ExtractMetadataTests(TestCase):
74
 
 
75
 
    def test_roundtrip(self):
76
 
        (msg, metadata) = extract_bzr_metadata(b"""Foo
77
 
--BZR--
78
 
revision-id: foo
79
 
""")
80
 
        self.assertEqual(b"Foo", msg)
81
 
        self.assertEqual(b"foo", metadata.revision_id)
82
 
 
83
 
 
84
 
class GenerateMetadataTests(TestCase):
85
 
 
86
 
    def test_roundtrip(self):
87
 
        metadata = CommitSupplement()
88
 
        metadata.revision_id = b"myrevid"
89
 
        msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
90
 
        self.assertEqual(b"""Foo
91
 
--BZR--
92
 
revision-id: myrevid
93
 
""", msg)
94
 
 
95
 
    def test_no_metadata(self):
96
 
        metadata = CommitSupplement()
97
 
        msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
98
 
        self.assertEqual(b"Foo", msg)