1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
class TestReportChanges(tests.TestCase):
26
def reportEqual(self, expected, file_id='fid', path='path',
27
versioned_change='unchanged', renamed=False,
28
modified='unchanged', exe_change=False,
29
kind=('file', 'file'), old_path=None):
31
def result_line(format, *args):
32
result.append(format % args)
33
inv = inventory.Inventory()
34
if old_path is not None:
35
inv.add(inventory.InventoryFile(file_id, old_path,
37
reporter = delta.ChangeReporter(inv, result_line)
38
reporter.report(file_id, path, versioned_change, renamed, modified,
40
self.assertEqualDiff(expected, result[0])
42
def test_rename(self):
43
self.reportEqual('R old => path', renamed=True, old_path='old')
44
self.reportEqual(' path')
47
self.reportEqual(' K path => path/', modified='kind changed',
48
kind=('file', 'directory'))
49
self.reportEqual(' K path/ => path', modified='kind changed',
50
kind=('directory', 'file'), old_path='old')
51
self.reportEqual('RK old => path/', renamed=True,
52
modified='kind changed', kind=('file', 'directory'),
55
self.reportEqual(' N path/', modified='created',
56
kind=(None, 'directory'))
57
self.reportEqual('+ path/', versioned_change='added',
58
modified='unchanged', kind=(None, 'directory'))
59
self.reportEqual('+N path/', versioned_change='added',
60
modified='created', kind=(None, 'directory'))
61
self.reportEqual('+M path/', versioned_change='added',
62
modified='modified', kind=(None, 'directory'))
63
self.reportEqual('+K path => path/', versioned_change='added',
64
modified='kind changed', kind=('file', 'directory'))
66
def test_removal(self):
67
self.reportEqual(' D path/', modified='deleted',
68
kind=('directory', None), old_path='old')
69
self.reportEqual('- path/', versioned_change='removed',
70
kind=(None, 'directory'))
71
self.reportEqual('-D path', versioned_change='removed',
72
modified='deleted', kind=('file', 'directory'))
74
def test_modification(self):
75
self.reportEqual(' M path', modified='modified')
76
self.reportEqual(' M* path', modified='modified', exe_change=True)