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
|
#!/usr/bin/env python
# arch-tag: 3fe5d578-07de-406e-950e-6bd26dc93af0
# Copyright (C) 2004--2005 Canonical Limited
# Author: David Allouche <david@allouche.net>
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Test cases for output parsing.
Unit tests for output classifiers and integration tests with actual
output.
"""
import unittest
import arch
import framework
from framework import TestCase
class Classifiers(unittest.TestCase):
tests = []
def _classify_chatter_helper(self, classify):
lines = ['* chatty', 'witty']
classifier = classify(lines)
chatter = classifier.next()
self.assertEqual('chatty', chatter.text)
self.assertEqual('* chatty', str(chatter))
self.assertEqual(arch.Chatter, type(chatter))
non_chatter = classifier.next()
self.assert_(non_chatter is lines[1])
self.assertRaises(StopIteration, classifier.next)
def classify_chatter(self):
"""classify_chatter works"""
self._classify_chatter_helper(arch.classify_chatter)
tests.append('classify_chatter')
def classify_changes(self):
"""classify_changes classifies chatter correctly"""
self._classify_chatter_helper(arch.classify_changeset_creation)
tests.append('classify_changes')
def _classify_tree_change_helper(self, line, type_,
nametype, name, **kwargs):
classifier = arch.classify_changeset_creation([line])
change = classifier.next()
self.assertRaises(StopIteration, classifier.next)
self.assertEqual(type_, type(change))
self.assertEqual(line, str(change))
self.assertEqual(name, change.name)
self.assertEqual(nametype, type(change.name))
for k, v in kwargs.items():
# do not use getattr so backtraces show the attribute name
if k == 'oldname': self.assertEqual(v, change.oldname)
elif k == 'binary': self.assertEqual(v, change.binary)
elif k == 'directory': self.assertEqual(v, change.directory)
else: raise AssertionError('bad argument: %s=%r' % (k, v))
for attr in ('oldname', 'binary', 'directory'):
if attr not in kwargs:
def thunk(): getattr(change, attr)
self.assertRaises(AttributeError, thunk)
def _classify_merge_outcome_helper(self, line, type_,
nametype, name, directory):
classifier = arch.classify_changeset_application([line])
change = classifier.next()
self.assertRaises(StopIteration, classifier.next)
self.assertEqual(type_, type(change))
self.assertEqual(line, str(change))
self.assertEqual(name, change.name)
self.assertEqual(nametype, type(change.name))
self.assertEqual(directory , change.directory)
class ClassifyFileAddition(Classifiers):
tests = []
def classify_changes_addition(self):
"""classify_changes classifies FileAddition"""
type_ = arch.FileAddition
self._classify_tree_change_helper(
'A foo', type_, arch.FileName, 'foo', directory=False)
self._classify_tree_change_helper(
'A/ foo', type_, arch.DirName, 'foo', directory=True)
self._classify_tree_change_helper(
'A fo\(sp)o', type_, arch.FileName, 'fo o', directory=False)
self._classify_tree_change_helper(
'A/ fo\(sp)o', type_, arch.DirName, 'fo o', directory=True)
tests.append('classify_changes_addition')
class ClassifyFileDeletion(Classifiers):
tests = []
def classify_changes_deletion(self):
"""classify_changes classifies FileDeletion"""
type_ = arch.FileDeletion
self._classify_tree_change_helper(
'D foo', type_, arch.FileName, 'foo', directory=False)
self._classify_tree_change_helper(
'D/ foo', type_, arch.DirName, 'foo', directory=True)
self._classify_tree_change_helper(
'D fo\(sp)o', type_, arch.FileName, 'fo o', directory=False)
self._classify_tree_change_helper(
'D/ fo\(sp)o', type_, arch.DirName, 'fo o', directory=True)
tests.append('classify_changes_deletion')
class ClassifyFileModification(Classifiers):
tests = []
def classify_changes_modification(self):
"""classify_changes classifies FileModification"""
type_ = arch.FileModification
self._classify_tree_change_helper(
'M foo', type_, arch.FileName, 'foo', binary=False,
directory=False)
self._classify_tree_change_helper(
'Mb foo', type_, arch.FileName, 'foo', binary=True,
directory=False)
self._classify_tree_change_helper(
'M fo\(sp)o', type_, arch.FileName, 'fo o', binary=False,
directory=False)
self._classify_tree_change_helper(
'Mb fo\(sp)o', type_, arch.FileName, 'fo o', binary=True,
directory=False)
tests.append('classify_changes_modification')
class ClassifyFilePermissionChange(Classifiers):
tests = []
def classify_changes_permissions(self):
"""classify_changes classifies FilePermissionsChange"""
type_ = arch.FilePermissionsChange
self._classify_tree_change_helper(
'-- foo', type_, arch.FileName, 'foo', directory=False)
self._classify_tree_change_helper(
'-/ foo', type_, arch.DirName, 'foo', directory=True)
self._classify_tree_change_helper(
'-- fo\(sp)o', type_, arch.FileName, 'fo o', directory=False)
self._classify_tree_change_helper(
'-/ fo\(sp)o', type_, arch.DirName, 'fo o', directory=True)
tests.append('classify_changes_permissions')
class ClassifyFileRename(Classifiers):
tests = []
def classify_changes_rename(self):
"""classify_changes classifies FileRename"""
type_ = arch.FileRename
self._classify_tree_change_helper(
'=> bar\tfoo', type_, arch.FileName, 'foo',
directory=False, oldname='bar')
self._classify_tree_change_helper(
'/> bar\tfoo', type_, arch.DirName, 'foo',
directory=True, oldname='bar')
self._classify_tree_change_helper(
'=> b\(sp)ar\tfo\(sp)o', type_, arch.FileName, 'fo o',
directory=False, oldname='b ar')
self._classify_tree_change_helper(
'/> b\(sp)ar\tfo\(sp)o', type_, arch.DirName, 'fo o',
directory=True, oldname='b ar')
tests.append('classify_changes_rename')
class ClassifySymLinkModification(Classifiers):
tests = []
def classify_changes_symlink(self):
"""classify_changes classifies SymlinkModification"""
self._classify_tree_change_helper(
'-> foo', arch.SymlinkModification, arch.FileName, 'foo',
directory=False)
self._classify_tree_change_helper(
'-> fo\(sp)o', arch.SymlinkModification, arch.FileName, 'fo o',
directory=False)
tests.append('classify_changes_symlink')
class ClassifyPatchConflict(Classifiers):
tests = []
def classify_changes_conflict(self):
"""classify_changes classifies PatchConflict"""
self._classify_merge_outcome_helper(
'C foo', arch.PatchConflict, arch.FileName, 'foo',
directory=False)
self._classify_merge_outcome_helper(
'C fo\(sp)o', arch.PatchConflict, arch.FileName, 'fo o',
directory=False)
tests.append('classify_changes_conflict')
def test_suite(limit=()):
classes = (
'Classifiers',
'ClassifyFileAddition',
'ClassifyFileDeletion',
'ClassifyFileModification',
'ClassifyFilePermissionChange',
'ClassifyFileRename',
'ClassifySymLinkModification',
'ClassifyPatchConflict',
)
return framework.make_test_suite(globals(), classes, limit)
def main(argv):
return framework.run_test_suite(argv, test_suite)
if __name__ == "__main__":
sys.exit(main(sys.argv))
|