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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# -*- coding: utf-8 -*-
#
# QBzr - Qt frontend to Bazaar commands
# Copyright (C) 2009 Alexander Belchenko
#
# 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 commit data object and operations."""
from bzrlib.tests import TestCase, TestCaseWithTransport
from bzrlib.plugins.qbzr.lib.commit_data import (
CommitData,
QBzrCommitData,
)
class TestCommitDataBase(TestCase):
def test_empty(self):
d = CommitData()
# CommitData instance has bool value False if there is no data inside
self.assertFalse(bool(d))
self.assertEqual(None, d['message'])
self.assertEqual({}, d.as_dict())
self.assertEqual([], d.keys())
def test_set_data_dict(self):
d = CommitData()
d.set_data({'message': 'foo bar'})
# CommitData instance has bool value True if there is some data inside
self.assertTrue(bool(d))
self.assertEqual('foo bar', d['message'])
self.assertEqual({'message': 'foo bar'}, d.as_dict())
self.assertEqual(['message'], d.keys())
def test_set_data_kw(self):
d = CommitData()
d.set_data(message='foo bar')
# CommitData instance has bool value True if there is some data inside
self.assertTrue(bool(d))
self.assertEqual('foo bar', d['message'])
self.assertEqual({'message': 'foo bar'}, d.as_dict())
self.assertEqual(['message'], d.keys())
def test_set_data_dict_and_kw(self):
d = CommitData()
d.set_data({'fixes': 'lp:123456'}, message='foo bar')
# CommitData instance has bool value True if there is some data inside
self.assertTrue(bool(d))
self.assertEqual('foo bar', d['message'])
self.assertEqual({'message': 'foo bar',
'fixes': 'lp:123456',
}, d.as_dict())
self.assertEqual(set(['message', 'fixes']), set(d.keys()))
def test_init_with_data(self):
d = CommitData(data={'fixes': 'lp:123456', 'message': 'foo bar'})
# CommitData instance has bool value True if there is some data inside
self.assertTrue(bool(d))
self.assertEqual('foo bar', d['message'])
self.assertEqual({'message': 'foo bar',
'fixes': 'lp:123456',
}, d.as_dict())
self.assertEqual(set(['message', 'fixes']), set(d.keys()))
def test_compare_data(self):
this = CommitData(data={'fixes': 'lp:123456', 'message': 'foo bar'})
self.assertTrue(this.compare_data(
CommitData(data={'fixes': 'lp:123456',
'message': 'foo bar'})))
self.assertTrue(this.compare_data({'fixes': 'lp:123456',
'message': 'foo bar'}))
other = CommitData(data={'fixes': 'lp:123456',
'message': 'foo bar',
'old_revid': 'xxx',
'new_revid': 'yyy',
})
self.assertFalse(this.compare_data(other))
self.assertTrue(this.compare_data(other, all_keys=False))
class TestCommitDataWithTree(TestCaseWithTransport):
def test_set_data_on_uncommit(self):
wt = self.make_branch_and_tree('.')
revid1 = wt.commit(message='1')
# imitate uncommit in branch with only one revision
d = CommitData(branch=wt.branch)
d.set_data_on_uncommit(revid1, None)
self.assertEqual({'message': '1',
'old_revid': revid1,
'new_revid': 'null:',
}, d.as_dict())
#
revid2 = wt.commit(message='2')
# imitate uncommit in branch with several revisions
d = CommitData(branch=wt.branch)
d.set_data_on_uncommit(revid2, revid1)
self.assertEqual({'message': '2',
'old_revid': revid2,
'new_revid': revid1,
}, d.as_dict())
def test_set_data_on_uncommit_bugids(self):
wt = self.make_branch_and_tree('.')
self.run_bzr('commit --unchanged -m foo --fixes lp:12345 --fixes lp:67890')
revid1 = wt.last_revision()
d = CommitData(branch=wt.branch)
d.set_data_on_uncommit(revid1, None)
self.assertEqual({'message': 'foo',
'bugs': 'lp:12345 lp:67890',
'old_revid': revid1,
'new_revid': 'null:',
}, d.as_dict())
def test_load_nothing(self):
wt = self.make_branch_and_tree('.')
d = CommitData(tree=wt)
d.load()
self.assertEqual({}, d.as_dict())
def test_save_data(self):
wt = self.make_branch_and_tree('.')
d = CommitData(tree=wt)
d.set_data(message='spam', old_revid='foo', new_revid='bar')
d.save()
# check branch.conf
cfg = wt.branch.get_config()
self.assertEqual({'message': 'spam',
'old_revid': 'foo',
'new_revid': 'bar',
}, cfg.get_user_option('commit_data'))
def test_save_filter_out_empty_data(self):
wt = self.make_branch_and_tree('.')
d = CommitData(tree=wt)
d.set_data({'message': '', 'foo': 'bar'})
d.save()
# check branch.conf
cfg = wt.branch.get_config()
self.assertEqual({'foo': 'bar'}, cfg.get_user_option('commit_data'))
def test_load_saved_data(self):
wt = self.make_branch_and_tree('.')
cfg = wt.branch.get_config()
cfg.set_user_option('commit_data',
{'message': 'spam',
'old_revid': 'foo',
'new_revid': 'bar',
})
d = CommitData(tree=wt)
d.load()
self.assertEqual({'message': 'spam',
'old_revid': 'foo',
'new_revid': 'bar',
}, d.as_dict())
def test_wipe_saved_data(self):
wt = self.make_branch_and_tree('.')
cfg = wt.branch.get_config()
cfg.set_user_option('commit_data',
{'message': 'spam',
'old_revid': 'foo',
'new_revid': 'bar',
})
d = CommitData(tree=wt)
d.wipe()
# check branch.conf
cfg = wt.branch.get_config()
self.assertEqual({}, cfg.get_user_option('commit_data'))
class TestQBzrCommitData(TestCaseWithTransport):
def test_io_old_data_transition(self):
# we should handle old data (i.e. qbzr_commit_message) gracefully
wt = self.make_branch_and_tree('.')
cfg = wt.branch.get_config()
cfg.set_user_option('qbzr_commit_message', 'spam')
# load
d = QBzrCommitData(tree=wt)
d.load()
self.assertEqual({'message': 'spam',
}, d.as_dict())
#
# if here both old and new then prefer new
cfg.set_user_option('commit_data', {'foo': 'bar'})
d = QBzrCommitData(tree=wt)
d.load()
self.assertEqual({'foo': 'bar',
}, d.as_dict())
#
# on save we should clear old data
d = QBzrCommitData(tree=wt)
d.set_data(message='eggs', old_revid='foo', new_revid='bar')
d.save()
# check branch.conf
cfg = wt.branch.get_config()
self.assertEqual('', cfg.get_user_option('qbzr_commit_message'))
self.assertEqual({'message': 'eggs',
'old_revid': 'foo',
'new_revid': 'bar',
}, cfg.get_user_option('commit_data'))
#
# on wipe we should clear old data too
cfg = wt.branch.get_config()
cfg.set_user_option('qbzr_commit_message', 'spam')
d = QBzrCommitData(tree=wt)
d.wipe()
# check branch.conf
cfg = wt.branch.get_config()
self.assertEqual('', cfg.get_user_option('qbzr_commit_message'))
self.assertEqual({}, cfg.get_user_option('commit_data'))
|