1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# Copyright (C) 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Tests for the commit template creation."""
from bzrlib.plugins import commitfromnews
from bzrlib import msgeditor
from bzrlib.tests import TestCaseWithTransport
class TestCommitTemplate(TestCaseWithTransport):
def capture_template(self, commit, message):
self.messages.append(message)
if message is None:
message = 'let this commit succeed I command thee.'
return message
def setup_capture(self):
commitfromnews.register()
msgeditor.hooks.install_named_hook('commit_message_template',
self.capture_template, 'commitfromnews test template')
self.messages = []
def test_initial(self):
self.setup_capture()
builder = self.make_branch_builder('test')
builder.start_series()
builder.build_snapshot('BASE-id', None,
[('add', ('', None, 'directory', None)),
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
],
message_callback=msgeditor.generate_commit_message_template)
builder.finish_series()
self.assertEqual([None], self.messages)
def test_added_NEWS(self):
self.setup_capture()
builder = self.make_branch_builder('test')
builder.start_series()
content = """----------------------------
commitfromnews release notes
----------------------------
NEXT (In development)
---------------------
IMPROVEMENTS
~~~~~~~~~~~~
* Created plugin, basic functionality of looking for NEWS and including the
NEWS diff.
"""
builder.build_snapshot('BASE-id', None,
[('add', ('', None, 'directory', None)),
('add', ('NEWS', 'foo-id', 'file', content)),
],
message_callback=msgeditor.generate_commit_message_template)
builder.finish_series()
self.assertEqual([content], self.messages)
def test_changed_NEWS(self):
self.setup_capture()
builder = self.make_branch_builder('test')
builder.start_series()
orig_content = """----------------------------
commitfromnews release notes
----------------------------
NEXT (In development)
---------------------
IMPROVEMENTS
~~~~~~~~~~~~
* Created plugin, basic functionality of looking for NEWS and including the
NEWS diff.
"""
mod_content = """----------------------------
commitfromnews release notes
----------------------------
NEXT (In development)
---------------------
IMPROVEMENTS
~~~~~~~~~~~~
* Added a new change to the system.
* Created plugin, basic functionality of looking for NEWS and including the
NEWS diff.
"""
change_content = """* Added a new change to the system.
"""
builder.build_snapshot('BASE-id', None,
[('add', ('', None, 'directory', None)),
('add', ('NEWS', 'foo-id', 'file', orig_content)),
])
builder.build_snapshot(None, None,
[('modify', ('foo-id', mod_content)),
],
message_callback=msgeditor.generate_commit_message_template)
builder.finish_series()
self.assertEqual([change_content], self.messages)
def _todo_test_passes_messages_through(self):
pass
|