~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 15:05:06 UTC
  • mto: This revision was merged to the branch mainline in revision 2254.
  • Revision ID: abentley@panoramicfeedback.com-20070110150506-v9731hp13vdksj23
Ensure that changes are detected correctly

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    )
22
22
 
23
23
 
 
24
class InstrumentedReporter(object):
 
25
    def __init__(self):
 
26
        self.calls = []
 
27
 
 
28
    def report(self, file_id, path, versioned, renamed, modified, exe_change,
 
29
               kind):
 
30
        self.calls.append((file_id, path, versioned, renamed, modified,
 
31
                           exe_change, kind))
 
32
 
24
33
class TestReportChanges(tests.TestCase):
25
34
 
26
 
    def reportEqual(self, expected, file_id='fid', path='path', 
 
35
    def reportEqual(self, expected, file_id='fid', path='path',
27
36
                    versioned_change='unchanged', renamed=False,
28
 
                    modified='unchanged', exe_change=False, 
 
37
                    modified='unchanged', exe_change=False,
29
38
                    kind=('file', 'file'), old_path=None):
30
39
        result = []
31
40
        def result_line(format, *args):
32
41
            result.append(format % args)
33
42
        inv = inventory.Inventory()
34
43
        if old_path is not None:
35
 
            inv.add(inventory.InventoryFile(file_id, old_path, 
 
44
            inv.add(inventory.InventoryFile(file_id, old_path,
36
45
                                            inv.root.file_id))
37
46
        reporter = delta.ChangeReporter(inv, result_line)
38
 
        reporter.report(file_id, path, versioned_change, renamed, modified, 
 
47
        reporter.report(file_id, path, versioned_change, renamed, modified,
39
48
                         exe_change, kind)
40
49
        self.assertEqualDiff(expected, result[0])
41
50
 
44
53
        self.reportEqual('    path')
45
54
 
46
55
    def test_kind(self):
47
 
        self.reportEqual(' K  path => path/', modified='kind changed', 
 
56
        self.reportEqual(' K  path => path/', modified='kind changed',
48
57
                         kind=('file', 'directory'))
49
58
        self.reportEqual(' K  path/ => path', modified='kind changed',
50
59
                         kind=('directory', 'file'), old_path='old')
52
61
                         modified='kind changed', kind=('file', 'directory'),
53
62
                         old_path='old')
54
63
    def test_new(self):
55
 
        self.reportEqual(' N  path/', modified='created', 
 
64
        self.reportEqual(' N  path/', modified='created',
56
65
                         kind=(None, 'directory'))
57
 
        self.reportEqual('+   path/', versioned_change='added', 
 
66
        self.reportEqual('+   path/', versioned_change='added',
58
67
                         modified='unchanged', kind=(None, 'directory'))
59
 
        self.reportEqual('+N  path/', versioned_change='added', 
 
68
        self.reportEqual('+N  path/', versioned_change='added',
60
69
                         modified='created', kind=(None, 'directory'))
61
 
        self.reportEqual('+M  path/', versioned_change='added', 
 
70
        self.reportEqual('+M  path/', versioned_change='added',
62
71
                         modified='modified', kind=(None, 'directory'))
63
 
        self.reportEqual('+K  path => path/', versioned_change='added', 
 
72
        self.reportEqual('+K  path => path/', versioned_change='added',
64
73
                         modified='kind changed', kind=('file', 'directory'))
65
74
 
66
75
    def test_removal(self):
67
76
        self.reportEqual(' D  path/', modified='deleted',
68
77
                         kind=('directory', None), old_path='old')
69
 
        self.reportEqual('-   path/', versioned_change='removed', 
 
78
        self.reportEqual('-   path/', versioned_change='removed',
70
79
                         kind=(None, 'directory'))
71
 
        self.reportEqual('-D  path', versioned_change='removed', 
 
80
        self.reportEqual('-D  path', versioned_change='removed',
72
81
                         modified='deleted', kind=('file', 'directory'))
73
82
 
74
83
    def test_modification(self):
75
84
        self.reportEqual(' M  path', modified='modified')
76
85
        self.reportEqual(' M* path', modified='modified', exe_change=True)
 
86
 
 
87
    def report_changes_equal(self,
 
88
                             file_id='fid',
 
89
                             path='path',
 
90
                             content_change=False,
 
91
                             versioned=(True, True),
 
92
                             parent_id=('pid', 'pid'),
 
93
                             name=('name', 'name'),
 
94
                             kind=('file', 'file'),
 
95
                             executable=(False, False),
 
96
                             versioned_change='unchanged',
 
97
                             renamed=False,
 
98
                             modified='unchanged',
 
99
                             exe_change=False):
 
100
        reporter = InstrumentedReporter()
 
101
        delta.report_changes([(file_id, path, content_change, versioned,
 
102
                               parent_id, name, kind, executable)], reporter)
 
103
        output = reporter.calls[0]
 
104
        self.assertEqual(file_id, output[0])
 
105
        self.assertEqual(path, output[1])
 
106
        self.assertEqual(versioned_change, output[2])
 
107
        self.assertEqual(renamed, output[3])
 
108
        self.assertEqual(modified, output[4])
 
109
        self.assertEqual(exe_change, output[5])
 
110
        self.assertEqual(kind, output[6])
 
111
 
 
112
    def test_report_changes(self):
 
113
        """Test change detection of report_changes"""
 
114
        #Ensure no changes are detected by default
 
115
        self.report_changes_equal(modified='unchanged', renamed=False,
 
116
                                  versioned_change='unchanged',
 
117
                                  exe_change=False)
 
118
        self.report_changes_equal(modified='kind changed',
 
119
                                  kind=('file', 'directory'))
 
120
        self.report_changes_equal(modified='created',
 
121
                                  kind=(None, 'directory'))
 
122
        self.report_changes_equal(modified='deleted',
 
123
                                  kind=('directory', None))
 
124
        self.report_changes_equal(content_change=True, modified='modified')
 
125
        self.report_changes_equal(renamed=True, name=('old', 'new'))
 
126
        self.report_changes_equal(renamed=True,
 
127
                                  parent_id=('old-parent', 'new-parent'))
 
128
        self.report_changes_equal(versioned_change='added',
 
129
                                  versioned=(False, True))
 
130
        self.report_changes_equal(versioned_change='removed',
 
131
                                  versioned=(True, False))
 
132
        # execute bit is only detected as "changed" if the file is and was
 
133
        # a regular file.
 
134
        self.report_changes_equal(exe_change=True,
 
135
                                  executable=(True, False))
 
136
        self.report_changes_equal(exe_change=False,
 
137
                                  executable=(True, False),
 
138
                                  kind=('directory', 'directory'))
 
139
        self.report_changes_equal(exe_change=False, modified='kind changed',
 
140
                                  executable=(False, True),
 
141
                                  kind=('directory', 'file'))
 
142
 
 
143
        # Now make sure they all work together
 
144
        self.report_changes_equal(versioned_change='removed',
 
145
                                  modified='deleted',
 
146
                                  versioned=(True, False),
 
147
                                  kind=('directory', None))
 
148
        self.report_changes_equal(versioned_change='removed',
 
149
                                  modified='created',
 
150
                                  versioned=(True, False),
 
151
                                  kind=(None, 'file'))
 
152
        self.report_changes_equal(versioned_change='removed',
 
153
                                  modified='modified',
 
154
                                  renamed=True,
 
155
                                  exe_change=True,
 
156
                                  versioned=(True, False),
 
157
                                  content_change=True,
 
158
                                  name=('old', 'new'),
 
159
                                  executable=(False, True)
 
160
                                  )