1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
2
# -*- encoding: utf-8 -*-
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.
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.
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
19
"""Tests for roundtripping text parsing."""
21
from __future__ import absolute_import
23
from ....tests import TestCase
25
from ..roundtrip import (
27
deserialize_fileid_map,
29
generate_roundtripping_metadata,
31
parse_roundtripping_metadata,
36
class RoundtripTests(TestCase):
39
md = parse_roundtripping_metadata("revision-id: foo\n")
40
self.assertEquals("foo", md.revision_id)
42
def test_parent_ids(self):
43
md = parse_roundtripping_metadata("parent-ids: foo bar\n")
44
self.assertEquals(("foo", "bar"), md.explicit_parent_ids)
46
def test_properties(self):
47
md = parse_roundtripping_metadata("property-foop: blar\n")
48
self.assertEquals({"foop": "blar"}, md.properties)
51
class FormatTests(TestCase):
54
metadata = CommitSupplement()
55
metadata.revision_id = "bla"
56
self.assertEquals("revision-id: bla\n",
57
generate_roundtripping_metadata(metadata, "utf-8"))
59
def test_parent_ids(self):
60
metadata = CommitSupplement()
61
metadata.explicit_parent_ids = ("foo", "bar")
62
self.assertEquals("parent-ids: foo bar\n",
63
generate_roundtripping_metadata(metadata, "utf-8"))
65
def test_properties(self):
66
metadata = CommitSupplement()
67
metadata.properties = {"foo": "bar"}
68
self.assertEquals("property-foo: bar\n",
69
generate_roundtripping_metadata(metadata, "utf-8"))
72
metadata = CommitSupplement()
74
generate_roundtripping_metadata(metadata, "utf-8"))
77
class ExtractMetadataTests(TestCase):
79
def test_roundtrip(self):
80
(msg, metadata) = extract_bzr_metadata("""Foo
84
self.assertEquals("Foo", msg)
85
self.assertEquals("foo", metadata.revision_id)
88
class GenerateMetadataTests(TestCase):
90
def test_roundtrip(self):
91
metadata = CommitSupplement()
92
metadata.revision_id = "myrevid"
93
msg = inject_bzr_metadata("Foo", metadata, "utf-8")
94
self.assertEquals("""Foo
99
def test_no_metadata(self):
100
metadata = CommitSupplement()
101
msg = inject_bzr_metadata("Foo", metadata, "utf-8")
102
self.assertEquals("Foo", msg)
105
class FileIdRoundTripTests(TestCase):
107
def test_deserialize(self):
108
self.assertEquals({"bar/bla": "fid"},
109
deserialize_fileid_map("bar/bla\0fid\n"))
111
def test_serialize(self):
112
self.assertEquals(["bar/bla\0fid\n"],
113
serialize_fileid_map({"bar/bla": "fid"}))