~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/test_inv.py

  • Committer: Andrew Bennetts
  • Date: 2008-05-07 22:47:56 UTC
  • mfrom: (3412 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3414.
  • Revision ID: andrew.bennetts@canonical.com-20080507224756-upxgmud0bdo4ysuf
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.diff import internal_diff
24
24
from bzrlib.mutabletree import MutableTree
25
25
from bzrlib.osutils import has_symlinks
26
 
from bzrlib.symbol_versioning import zero_ninetyone, one_zero
27
26
from bzrlib.tests import SymlinkFeature, TestSkipped
28
27
from bzrlib.tests.tree_implementations import TestCaseWithTree
29
28
from bzrlib.transform import _PreviewTree
66
65
            self.link_1 = self.inv_1['linkid']
67
66
            self.link_2 = get_entry(self.tree_2, 'linkid')
68
67
 
69
 
    def test_file_diff_deleted(self):
70
 
        output = StringIO()
71
 
        self.applyDeprecated(one_zero,
72
 
                             self.file_1.diff,
73
 
                             internal_diff,
74
 
                             "old_label", self.tree_1,
75
 
                             "/dev/null", None, None,
76
 
                             output)
77
 
        self.assertEqual(output.getvalue(), "--- old_label\n"
78
 
                                            "+++ /dev/null\n"
79
 
                                            "@@ -1,1 +0,0 @@\n"
80
 
                                            "-foo\n"
81
 
                                            "\n")
82
 
 
83
 
    def test_file_diff_added(self):
84
 
        output = StringIO()
85
 
        self.applyDeprecated(one_zero,
86
 
                             self.file_1.diff,
87
 
                             internal_diff,
88
 
                             "new_label", self.tree_1,
89
 
                             "/dev/null", None, None,
90
 
                             output, reverse=True)
91
 
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
92
 
                                            "+++ new_label\n"
93
 
                                            "@@ -0,0 +1,1 @@\n"
94
 
                                            "+foo\n"
95
 
                                            "\n")
96
 
 
97
 
    def test_file_diff_changed(self):
98
 
        output = StringIO()
99
 
        self.applyDeprecated(one_zero,
100
 
                             self.file_1.diff,
101
 
                             internal_diff,
102
 
                             "/dev/null", self.tree_1,
103
 
                             "new_label", self.file_2, self.tree_2,
104
 
                             output)
105
 
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
106
 
                                            "+++ new_label\n"
107
 
                                            "@@ -1,1 +1,1 @@\n"
108
 
                                            "-foo\n"
109
 
                                            "+bar\n"
110
 
                                            "\n")
111
 
 
112
 
    def test_file_diff_binary(self):
113
 
        output = StringIO()
114
 
        self.applyDeprecated(one_zero,
115
 
                             self.file_1.diff,
116
 
                             internal_diff,
117
 
                             "/dev/null", self.tree_1,
118
 
                             "new_label", self.file_2b, self.tree_2,
119
 
                             output)
120
 
        self.assertEqual(output.getvalue(),
121
 
                         "Binary files /dev/null and new_label differ\n")
122
 
 
123
 
    def test_link_diff_deleted(self):
124
 
        self.requireFeature(SymlinkFeature)
125
 
        output = StringIO()
126
 
        self.applyDeprecated(one_zero,
127
 
                             self.link_1.diff,
128
 
                             internal_diff, "old_label",
129
 
                             self.tree_1, "/dev/null", None, None,
130
 
                             output)
131
 
        self.assertEqual(output.getvalue(),
132
 
                         "=== target was 'target1'\n")
133
 
 
134
 
    def test_link_diff_added(self):
135
 
        self.requireFeature(SymlinkFeature)
136
 
        output = StringIO()
137
 
        self.applyDeprecated(one_zero,
138
 
                             self.link_1.diff,
139
 
                             internal_diff,
140
 
                             "new_label", self.tree_1,
141
 
                             "/dev/null", None, None,
142
 
                             output, reverse=True)
143
 
        self.assertEqual(output.getvalue(),
144
 
                         "=== target is 'target1'\n")
145
 
 
146
 
    def test_link_diff_changed(self):
147
 
        self.requireFeature(SymlinkFeature)
148
 
        output = StringIO()
149
 
        self.applyDeprecated(one_zero,
150
 
                             self.link_1.diff,
151
 
                             internal_diff,
152
 
                             "/dev/null", self.tree_1,
153
 
                             "new_label", self.link_2, self.tree_2,
154
 
                             output)
155
 
        self.assertEqual(output.getvalue(),
156
 
                         "=== target changed 'target1' => 'target2'\n")
157
 
 
158
68
 
159
69
class TestPreviousHeads(TestCaseWithTree):
160
70
 
190
100
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
191
101
            self.branch.repository.get_transaction())
192
102
 
193
 
    def get_previous_heads(self, inventories):
194
 
        return self.applyDeprecated(zero_ninetyone,
195
 
            self.file_active.find_previous_heads,
196
 
            inventories,
197
 
            self.branch.repository.weave_store,
198
 
            self.branch.repository.get_transaction())
199
 
 
200
 
    def test_fileid_in_no_inventory(self):
201
 
        self.assertEqual({}, self.get_previous_heads([self.inv_A]))
202
 
 
203
 
    def test_fileid_in_one_inventory(self):
204
 
        self.assertEqual({'B':self.inv_B['fileid']},
205
 
                         self.get_previous_heads([self.inv_B]))
206
 
        self.assertEqual({'B':self.inv_B['fileid']},
207
 
                         self.get_previous_heads([self.inv_A, self.inv_B]))
208
 
        self.assertEqual({'B':self.inv_B['fileid']},
209
 
                         self.get_previous_heads([self.inv_B, self.inv_A]))
210
 
 
211
 
    def test_fileid_in_two_inventories_gives_both_entries(self):
212
 
        self.assertEqual({'B':self.inv_B['fileid'],
213
 
                          'C':self.inv_C['fileid']},
214
 
                          self.get_previous_heads([self.inv_B, self.inv_C]))
215
 
        self.assertEqual({'B':self.inv_B['fileid'],
216
 
                          'C':self.inv_C['fileid']},
217
 
                          self.get_previous_heads([self.inv_C, self.inv_B]))
218
 
 
219
 
    def test_fileid_in_two_inventories_already_merged_gives_head(self):
220
 
        self.assertEqual({'D':self.inv_D['fileid']},
221
 
                         self.get_previous_heads([self.inv_B, self.inv_D]))
222
 
        self.assertEqual({'D':self.inv_D['fileid']},
223
 
                         self.get_previous_heads([self.inv_D, self.inv_B]))
224
 
 
225
103
    # TODO: test two inventories with the same file revision
226
104
 
227
105