~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Aaron Bentley
  • Date: 2007-01-10 14:08:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2254.
  • Revision ID: abentley@panoramicfeedback.com-20070110140801-ixdm903ldjr4emik
Added revert change display, with tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
from bzrlib import (
 
18
    delta,
 
19
    inventory,
 
20
    tests,
 
21
    )
 
22
 
 
23
 
 
24
class TestReportChanges(tests.TestCase):
 
25
 
 
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):
 
30
        result = []
 
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, 
 
36
                                            inv.root.file_id))
 
37
        reporter = delta.ChangeReporter(inv, result_line)
 
38
        reporter.report(file_id, path, versioned_change, renamed, modified, 
 
39
                         exe_change, kind)
 
40
        self.assertEqualDiff(expected, result[0])
 
41
 
 
42
    def test_rename(self):
 
43
        self.reportEqual('R   old => path', renamed=True, old_path='old')
 
44
        self.reportEqual('    path')
 
45
 
 
46
    def test_kind(self):
 
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'),
 
53
                         old_path='old')
 
54
    def test_new(self):
 
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'))
 
65
 
 
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'))
 
73
 
 
74
    def test_modification(self):
 
75
        self.reportEqual(' M  path', modified='modified')
 
76
        self.reportEqual(' M* path', modified='modified', exe_change=True)