~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testinv.py

  • Committer: Robert Collins
  • Date: 2005-10-03 05:16:47 UTC
  • mto: (1393.1.30)
  • mto: This revision was merged to the branch mainline in revision 1400.
  • Revision ID: robertc@robertcollins.net-20051003051646-8a92be7727c533ff
move diff and symlink conditionals into inventory.py from diff.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
from cStringIO import StringIO
17
18
import os
 
19
 
 
20
from bzrlib.branch import Branch
 
21
from bzrlib.diff import internal_diff
 
22
from bzrlib.inventory import Inventory, InventoryEntry, ROOT_ID
 
23
from bzrlib.osutils import has_symlinks
18
24
from bzrlib.selftest import TestCase, TestCaseInTempDir
19
25
 
20
 
from bzrlib.inventory import Inventory, InventoryEntry, ROOT_ID
21
 
 
22
26
 
23
27
class TestInventory(TestCase):
24
28
 
112
116
        left.symlink_target = 'different'
113
117
        self.assertEqual((True, False), left.detect_changes(right))
114
118
        self.assertEqual((True, False), right.detect_changes(left))
 
119
 
 
120
 
 
121
class TestEntryDiffing(TestCaseInTempDir):
 
122
 
 
123
    def setUp(self):
 
124
        super(TestEntryDiffing, self).setUp()
 
125
        self.branch = Branch.initialize('.')
 
126
        print >> open('file', 'wb'), 'foo'
 
127
        self.branch.add(['file'], ['fileid'])
 
128
        if has_symlinks():
 
129
            os.symlink('target1', 'symlink')
 
130
            self.branch.add(['symlink'], ['linkid'])
 
131
        self.branch.commit('message_1', rev_id = '1')
 
132
        print >> open('file', 'wb'), 'bar'
 
133
        if has_symlinks():
 
134
            os.unlink('symlink')
 
135
            os.symlink('target2', 'symlink')
 
136
        self.tree_1 = self.branch.revision_tree('1')
 
137
        self.inv_1 = self.branch.get_inventory('1')
 
138
        self.file_1 = self.inv_1['fileid']
 
139
        self.tree_2 = self.branch.working_tree()
 
140
        self.inv_2 = self.branch.inventory
 
141
        self.file_2 = self.inv_2['fileid']
 
142
        if has_symlinks():
 
143
            self.link_1 = self.inv_1['linkid']
 
144
            self.link_2 = self.inv_2['linkid']
 
145
 
 
146
    def test_file_diff_deleted(self):
 
147
        output = StringIO()
 
148
        self.file_1.diff(internal_diff, 
 
149
                          "old_label", self.tree_1,
 
150
                          "/dev/null", None, None,
 
151
                          output)
 
152
        self.assertEqual(output.getvalue(), "--- old_label\n"
 
153
                                            "+++ /dev/null\n"
 
154
                                            "@@ -1,1 +0,0 @@\n"
 
155
                                            "-foo\n"
 
156
                                            "\n")
 
157
 
 
158
    def test_file_diff_added(self):
 
159
        output = StringIO()
 
160
        self.file_1.diff(internal_diff, 
 
161
                          "new_label", self.tree_1,
 
162
                          "/dev/null", None, None,
 
163
                          output, reverse=True)
 
164
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
 
165
                                            "+++ new_label\n"
 
166
                                            "@@ -0,0 +1,1 @@\n"
 
167
                                            "+foo\n"
 
168
                                            "\n")
 
169
 
 
170
    def test_file_diff_changed(self):
 
171
        output = StringIO()
 
172
        self.file_1.diff(internal_diff, 
 
173
                          "/dev/null", self.tree_1, 
 
174
                          "new_label", self.file_2, self.tree_2,
 
175
                          output)
 
176
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
 
177
                                            "+++ new_label\n"
 
178
                                            "@@ -1,1 +1,1 @@\n"
 
179
                                            "-foo\n"
 
180
                                            "+bar\n"
 
181
                                            "\n")
 
182
        
 
183
    def test_link_diff_deleted(self):
 
184
        output = StringIO()
 
185
        self.link_1.diff(internal_diff, 
 
186
                          "old_label", self.tree_1,
 
187
                          "/dev/null", None, None,
 
188
                          output)
 
189
        self.assertEqual(output.getvalue(),
 
190
                         "=== target was 'target1'\n")
 
191
 
 
192
    def test_link_diff_added(self):
 
193
        output = StringIO()
 
194
        self.link_1.diff(internal_diff, 
 
195
                          "new_label", self.tree_1,
 
196
                          "/dev/null", None, None,
 
197
                          output, reverse=True)
 
198
        self.assertEqual(output.getvalue(),
 
199
                         "=== target is 'target1'\n")
 
200
 
 
201
    def test_link_diff_changed(self):
 
202
        output = StringIO()
 
203
        self.link_1.diff(internal_diff, 
 
204
                          "/dev/null", self.tree_1, 
 
205
                          "new_label", self.link_2, self.tree_2,
 
206
                          output)
 
207
        self.assertEqual(output.getvalue(),
 
208
                         "=== target changed 'target1' => 'target2'\n")