/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (C) 2008 Aaron Bentley <aaron@aaronbentley.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


from bzrlib import transform
from bzrlib.plugins.shelf2.serialize_transform import (serialize, deserialize)
from bzrlib.tests import TestCaseWithTransport


class TestSerializeTransform(TestCaseWithTransport):

    def test_roundtrip_creation(self):
        tree = self.make_branch_and_tree('.')
        tt = transform.TransformPreview(tree)
        self.addCleanup(tt.finalize)
        tt.new_file(u'foo\u1234', tt.root, 'bar', 'baz', True)
        tt.new_directory('qux', tt.root, 'quxx')
        output = serialize(tt)
        tt2 = transform.TransformPreview(tree)
        self.addCleanup(tt2.finalize)
        deserialize(tt2, output)
        self.assertEqual(3, tt2._id_number)
        self.assertEqual({'new-1': u'foo\u1234',
                          'new-2': 'qux'}, tt2._new_name)
        self.assertEqual({'new-1': 'baz', 'new-2': 'quxx'}, tt2._new_id)
        self.assertEqual({'new-1': tt.root, 'new-2': tt.root}, tt2._new_parent)
        self.assertEqual({'baz': 'new-1', 'quxx': 'new-2'}, tt2._r_new_id)
        self.assertEqual({'new-1': True}, tt2._new_executability)
        self.assertEqual({'new-1': 'file',
                          'new-2': 'directory'}, tt2._new_contents)
        foo_limbo = open(tt2._limbo_name('new-1'), 'rb')
        try:
            foo_content = foo_limbo.read()
        finally:
            foo_limbo.close()
        self.assertEqual('bar', foo_content)

    def test_roundtrip_destruction(self):
        tree = self.make_branch_and_tree('.')
        self.build_tree([u'foo\u1234', 'bar'])
        tree.add([u'foo\u1234', 'bar'], ['foo-id', 'bar-id'])
        tt = transform.TransformPreview(tree)
        self.addCleanup(tt.finalize)
        foo_trans_id = tt.trans_id_tree_file_id('foo-id')
        tt.unversion_file(foo_trans_id)
        bar_trans_id = tt.trans_id_tree_file_id('bar-id')
        tt.delete_contents(bar_trans_id)
        tt2 = transform.TransformPreview(tree)
        self.addCleanup(tt2.finalize)
        deserialize(tt2, serialize(tt))
        self.assertEqual({u'foo\u1234': foo_trans_id,
                          'bar': bar_trans_id,
                          '': tt.root}, tt2._tree_path_ids)
        self.assertEqual({foo_trans_id: u'foo\u1234',
                          bar_trans_id: 'bar',
                          tt.root: ''}, tt2._tree_id_paths)
        self.assertEqual(set([foo_trans_id]), tt2._removed_id)
        self.assertEqual(set([bar_trans_id]), tt2._removed_contents)