~ubuntu-branches/ubuntu/utopic/dulwich/utopic

« back to all changes in this revision

Viewing changes to dulwich/tests/test_diff_tree.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2014-04-23 01:41:04 UTC
  • mfrom: (1.5.5)
  • Revision ID: package-import@ubuntu.com-20140423014104-nulhaisomztpfriy
Tags: 0.9.6-1
* New upstream release.
* Allow output to stderr in autopktest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        blob_a2 = make_object(Blob, data='a2')
104
104
        blob_b1 = make_object(Blob, data='b1')
105
105
        blob_c2 = make_object(Blob, data='c2')
106
 
        tree1 = self.commit_tree([('a', blob_a1, 0100644),
107
 
                                  ('b', blob_b1, 0100755)])
108
 
        tree2 = self.commit_tree([('a', blob_a2, 0100644),
109
 
                                  ('c', blob_c2, 0100755)])
 
106
        tree1 = self.commit_tree([('a', blob_a1, 0o100644),
 
107
                                  ('b', blob_b1, 0o100755)])
 
108
        tree2 = self.commit_tree([('a', blob_a2, 0o100644),
 
109
                                  ('c', blob_c2, 0o100755)])
110
110
 
111
111
        self.assertEqual([], merge_entries('', self.empty_tree,
112
112
                                           self.empty_tree))
113
113
        self.assertEqual([
114
 
          ((None, None, None), ('a', 0100644, blob_a1.id)),
115
 
          ((None, None, None), ('b', 0100755, blob_b1.id)),
 
114
          ((None, None, None), ('a', 0o100644, blob_a1.id)),
 
115
          ((None, None, None), ('b', 0o100755, blob_b1.id)),
116
116
          ], merge_entries('', self.empty_tree, tree1))
117
117
        self.assertEqual([
118
 
          ((None, None, None), ('x/a', 0100644, blob_a1.id)),
119
 
          ((None, None, None), ('x/b', 0100755, blob_b1.id)),
 
118
          ((None, None, None), ('x/a', 0o100644, blob_a1.id)),
 
119
          ((None, None, None), ('x/b', 0o100755, blob_b1.id)),
120
120
          ], merge_entries('x', self.empty_tree, tree1))
121
121
 
122
122
        self.assertEqual([
123
 
          (('a', 0100644, blob_a2.id), (None, None, None)),
124
 
          (('c', 0100755, blob_c2.id), (None, None, None)),
 
123
          (('a', 0o100644, blob_a2.id), (None, None, None)),
 
124
          (('c', 0o100755, blob_c2.id), (None, None, None)),
125
125
          ], merge_entries('', tree2, self.empty_tree))
126
126
 
127
127
        self.assertEqual([
128
 
          (('a', 0100644, blob_a1.id), ('a', 0100644, blob_a2.id)),
129
 
          (('b', 0100755, blob_b1.id), (None, None, None)),
130
 
          ((None, None, None), ('c', 0100755, blob_c2.id)),
 
128
          (('a', 0o100644, blob_a1.id), ('a', 0o100644, blob_a2.id)),
 
129
          (('b', 0o100755, blob_b1.id), (None, None, None)),
 
130
          ((None, None, None), ('c', 0o100755, blob_c2.id)),
131
131
          ], merge_entries('', tree1, tree2))
132
132
 
133
133
        self.assertEqual([
134
 
          (('a', 0100644, blob_a2.id), ('a', 0100644, blob_a1.id)),
135
 
          ((None, None, None), ('b', 0100755, blob_b1.id)),
136
 
          (('c', 0100755, blob_c2.id), (None, None, None)),
 
134
          (('a', 0o100644, blob_a2.id), ('a', 0o100644, blob_a1.id)),
 
135
          ((None, None, None), ('b', 0o100755, blob_b1.id)),
 
136
          (('c', 0o100755, blob_c2.id), (None, None, None)),
137
137
          ], merge_entries('', tree2, tree1))
138
138
 
139
 
        self.assertMergeFails(merge_entries, 0xdeadbeef, 0100644, '1' * 40)
 
139
        self.assertMergeFails(merge_entries, 0xdeadbeef, 0o100644, '1' * 40)
140
140
        self.assertMergeFails(merge_entries, 'a', 'deadbeef', '1' * 40)
141
 
        self.assertMergeFails(merge_entries, 'a', 0100644, 0xdeadbeef)
 
141
        self.assertMergeFails(merge_entries, 'a', 0o100644, 0xdeadbeef)
142
142
 
143
143
    test_merge_entries = functest_builder(_do_test_merge_entries,
144
144
                                          _merge_entries_py)
147
147
 
148
148
    def _do_test_is_tree(self, is_tree):
149
149
        self.assertFalse(is_tree(TreeEntry(None, None, None)))
150
 
        self.assertFalse(is_tree(TreeEntry('a', 0100644, 'a' * 40)))
151
 
        self.assertFalse(is_tree(TreeEntry('a', 0100755, 'a' * 40)))
152
 
        self.assertFalse(is_tree(TreeEntry('a', 0120000, 'a' * 40)))
153
 
        self.assertTrue(is_tree(TreeEntry('a', 0040000, 'a' * 40)))
 
150
        self.assertFalse(is_tree(TreeEntry('a', 0o100644, 'a' * 40)))
 
151
        self.assertFalse(is_tree(TreeEntry('a', 0o100755, 'a' * 40)))
 
152
        self.assertFalse(is_tree(TreeEntry('a', 0o120000, 'a' * 40)))
 
153
        self.assertTrue(is_tree(TreeEntry('a', 0o040000, 'a' * 40)))
154
154
        self.assertRaises(TypeError, is_tree, TreeEntry('a', 'x', 'a' * 40))
155
155
        self.assertRaises(AttributeError, is_tree, 1234)
156
156
 
180
180
    def test_tree_changes_add_delete(self):
181
181
        blob_a = make_object(Blob, data='a')
182
182
        blob_b = make_object(Blob, data='b')
183
 
        tree = self.commit_tree([('a', blob_a, 0100644),
184
 
                                 ('x/b', blob_b, 0100755)])
 
183
        tree = self.commit_tree([('a', blob_a, 0o100644),
 
184
                                 ('x/b', blob_b, 0o100755)])
185
185
        self.assertChangesEqual(
186
 
          [TreeChange.add(('a', 0100644, blob_a.id)),
187
 
           TreeChange.add(('x/b', 0100755, blob_b.id))],
 
186
          [TreeChange.add(('a', 0o100644, blob_a.id)),
 
187
           TreeChange.add(('x/b', 0o100755, blob_b.id))],
188
188
          self.empty_tree, tree)
189
189
        self.assertChangesEqual(
190
 
          [TreeChange.delete(('a', 0100644, blob_a.id)),
191
 
           TreeChange.delete(('x/b', 0100755, blob_b.id))],
 
190
          [TreeChange.delete(('a', 0o100644, blob_a.id)),
 
191
           TreeChange.delete(('x/b', 0o100755, blob_b.id))],
192
192
          tree, self.empty_tree)
193
193
 
194
194
    def test_tree_changes_modify_contents(self):
202
202
 
203
203
    def test_tree_changes_modify_mode(self):
204
204
        blob_a = make_object(Blob, data='a')
205
 
        tree1 = self.commit_tree([('a', blob_a, 0100644)])
206
 
        tree2 = self.commit_tree([('a', blob_a, 0100755)])
 
205
        tree1 = self.commit_tree([('a', blob_a, 0o100644)])
 
206
        tree2 = self.commit_tree([('a', blob_a, 0o100755)])
207
207
        self.assertChangesEqual(
208
 
          [TreeChange(CHANGE_MODIFY, ('a', 0100644, blob_a.id),
209
 
                      ('a', 0100755, blob_a.id))], tree1, tree2)
 
208
          [TreeChange(CHANGE_MODIFY, ('a', 0o100644, blob_a.id),
 
209
                      ('a', 0o100755, blob_a.id))], tree1, tree2)
210
210
 
211
211
    def test_tree_changes_change_type(self):
212
212
        blob_a1 = make_object(Blob, data='a')
213
213
        blob_a2 = make_object(Blob, data='/foo/bar')
214
 
        tree1 = self.commit_tree([('a', blob_a1, 0100644)])
215
 
        tree2 = self.commit_tree([('a', blob_a2, 0120000)])
 
214
        tree1 = self.commit_tree([('a', blob_a1, 0o100644)])
 
215
        tree2 = self.commit_tree([('a', blob_a2, 0o120000)])
216
216
        self.assertChangesEqual(
217
 
          [TreeChange.delete(('a', 0100644, blob_a1.id)),
218
 
           TreeChange.add(('a', 0120000, blob_a2.id))],
 
217
          [TreeChange.delete(('a', 0o100644, blob_a1.id)),
 
218
           TreeChange.add(('a', 0o120000, blob_a2.id))],
219
219
          tree1, tree2)
220
220
 
221
221
    def test_tree_changes_to_tree(self):
392
392
        self.assertChangesForMergeEqual([], [has, doesnt_have], doesnt_have)
393
393
 
394
394
    def test_tree_changes_for_merge_octopus_no_conflict(self):
395
 
        r = range(5)
 
395
        r = list(range(5))
396
396
        blobs = [make_object(Blob, data=str(i)) for i in r]
397
397
        parents = [self.commit_tree([('a', blobs[i])]) for i in r]
398
398
        for i in r:
403
403
        # Because the octopus merge strategy is limited, I doubt it's possible
404
404
        # to create this with the git command line. But the output is well-
405
405
        # defined, so test it anyway.
406
 
        r = range(5)
 
406
        r = list(range(5))
407
407
        parent_blobs = [make_object(Blob, data=str(i)) for i in r]
408
408
        merge_blob = make_object(Blob, data='merge')
409
409
        parents = [self.commit_tree([('a', parent_blobs[i])]) for i in r]
591
591
 
592
592
    def test_exact_rename_split_different_type(self):
593
593
        blob = make_object(Blob, data='/foo')
594
 
        tree1 = self.commit_tree([('a', blob, 0100644)])
595
 
        tree2 = self.commit_tree([('a', blob, 0120000)])
 
594
        tree1 = self.commit_tree([('a', blob, 0o100644)])
 
595
        tree2 = self.commit_tree([('a', blob, 0o120000)])
596
596
        self.assertEqual(
597
 
          [TreeChange.add(('a', 0120000, blob.id)),
598
 
           TreeChange.delete(('a', 0100644, blob.id))],
 
597
          [TreeChange.add(('a', 0o120000, blob.id)),
 
598
           TreeChange.delete(('a', 0o100644, blob.id))],
599
599
          self.detect_renames(tree1, tree2))
600
600
 
601
601
    def test_exact_rename_and_different_type(self):
602
602
        blob1 = make_object(Blob, data='1')
603
603
        blob2 = make_object(Blob, data='2')
604
604
        tree1 = self.commit_tree([('a', blob1)])
605
 
        tree2 = self.commit_tree([('a', blob2, 0120000), ('b', blob1)])
 
605
        tree2 = self.commit_tree([('a', blob2, 0o120000), ('b', blob1)])
606
606
        self.assertEqual(
607
 
          [TreeChange.add(('a', 0120000, blob2.id)),
 
607
          [TreeChange.add(('a', 0o120000, blob2.id)),
608
608
           TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('b', F, blob1.id))],
609
609
          self.detect_renames(tree1, tree2))
610
610
 
649
649
    def test_exact_copy_change_mode(self):
650
650
        blob = make_object(Blob, data='a\nb\nc\nd\n')
651
651
        tree1 = self.commit_tree([('a', blob)])
652
 
        tree2 = self.commit_tree([('a', blob, 0100755), ('b', blob)])
 
652
        tree2 = self.commit_tree([('a', blob, 0o100755), ('b', blob)])
653
653
        self.assertEqual(
654
654
          [TreeChange(CHANGE_MODIFY, ('a', F, blob.id),
655
 
                      ('a', 0100755, blob.id)),
 
655
                      ('a', 0o100755, blob.id)),
656
656
           TreeChange(CHANGE_COPY, ('a', F, blob.id), ('b', F, blob.id))],
657
657
          self.detect_renames(tree1, tree2))
658
658
 
760
760
        blob2 = make_object(Blob, data='blob2')
761
761
        link1 = '1' * 40
762
762
        link2 = '2' * 40
763
 
        tree1 = self.commit_tree([('a', blob1), ('b', link1, 0160000)])
764
 
        tree2 = self.commit_tree([('c', blob2), ('d', link2, 0160000)])
 
763
        tree1 = self.commit_tree([('a', blob1), ('b', link1, 0o160000)])
 
764
        tree2 = self.commit_tree([('c', blob2), ('d', link2, 0o160000)])
765
765
        self.assertEqual(
766
 
          [TreeChange.delete(('a', 0100644, blob1.id)),
767
 
           TreeChange.delete(('b', 0160000, link1)),
768
 
           TreeChange.add(('c', 0100644, blob2.id)),
769
 
           TreeChange.add(('d', 0160000, link2))],
 
766
          [TreeChange.delete(('a', 0o100644, blob1.id)),
 
767
           TreeChange.delete(('b', 0o160000, link1)),
 
768
           TreeChange.add(('c', 0o100644, blob2.id)),
 
769
           TreeChange.add(('d', 0o160000, link2))],
770
770
          self.detect_renames(tree1, tree2))
771
771
 
772
772
    def test_exact_rename_swap(self):