/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.12.1 by Aaron Bentley
Initial bencode-based encoding
1
# Copyright (C) 2008 Aaron Bentley <aaron@aaronbentley.com>
2
#
3
#    This program is free software; you can redistribute it and/or modify
4
#    it under the terms of the GNU General Public License as published by
5
#    the Free Software Foundation; either version 2 of the License, or
6
#    (at your option) any later version.
7
#
8
#    This program is distributed in the hope that it will be useful,
9
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
#    GNU General Public License for more details.
12
#
13
#    You should have received a copy of the GNU General Public License
14
#    along with this program; if not, write to the Free Software
15
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.12.9 by Aaron Bentley
Simplify tests
17
import os
0.12.1 by Aaron Bentley
Initial bencode-based encoding
18
19
from bzrlib import transform
20
from bzrlib.plugins.shelf2.serialize_transform import (serialize, deserialize)
0.12.9 by Aaron Bentley
Simplify tests
21
from bzrlib import tests
22
23
24
class TestSerializeTransform(tests.TestCaseWithTransport):
25
26
    def get_two_previews(self, tree):
27
        tt = transform.TransformPreview(tree)
28
        self.addCleanup(tt.finalize)
29
        tt2 = transform.TransformPreview(tree)
30
        self.addCleanup(tt2.finalize)
31
        return tt, tt2
0.12.1 by Aaron Bentley
Initial bencode-based encoding
32
0.12.8 by Aaron Bentley
Test deleting and unversioning
33
    def test_roundtrip_creation(self):
0.12.1 by Aaron Bentley
Initial bencode-based encoding
34
        tree = self.make_branch_and_tree('.')
0.12.9 by Aaron Bentley
Simplify tests
35
        tt, tt2 = self.get_two_previews(tree)
0.12.1 by Aaron Bentley
Initial bencode-based encoding
36
        tt.new_file(u'foo\u1234', tt.root, 'bar', 'baz', True)
0.12.6 by Aaron Bentley
Support serializing/deserializing directories
37
        tt.new_directory('qux', tt.root, 'quxx')
0.12.9 by Aaron Bentley
Simplify tests
38
        deserialize(tt2, serialize(tt))
0.12.6 by Aaron Bentley
Support serializing/deserializing directories
39
        self.assertEqual(3, tt2._id_number)
40
        self.assertEqual({'new-1': u'foo\u1234',
41
                          'new-2': 'qux'}, tt2._new_name)
42
        self.assertEqual({'new-1': 'baz', 'new-2': 'quxx'}, tt2._new_id)
43
        self.assertEqual({'new-1': tt.root, 'new-2': tt.root}, tt2._new_parent)
44
        self.assertEqual({'baz': 'new-1', 'quxx': 'new-2'}, tt2._r_new_id)
0.12.7 by Aaron Bentley
Get executability under test.
45
        self.assertEqual({'new-1': True}, tt2._new_executability)
0.12.6 by Aaron Bentley
Support serializing/deserializing directories
46
        self.assertEqual({'new-1': 'file',
47
                          'new-2': 'directory'}, tt2._new_contents)
0.12.5 by Aaron Bentley
Test file content
48
        foo_limbo = open(tt2._limbo_name('new-1'), 'rb')
49
        try:
50
            foo_content = foo_limbo.read()
51
        finally:
52
            foo_limbo.close()
53
        self.assertEqual('bar', foo_content)
0.12.8 by Aaron Bentley
Test deleting and unversioning
54
0.12.10 by Aaron Bentley
Implement symlink serialization
55
    def test_symlink_creation(self):
56
        self.requireFeature(tests.SymlinkFeature)
57
        tree = self.make_branch_and_tree('.')
58
        tt, tt2 = self.get_two_previews(tree)
59
        tt.new_symlink('foo', tt.root, 'bar')
60
        deserialize(tt2, serialize(tt))
61
        foo_content = os.readlink(tt2._limbo_name('new-1'))
62
        self.assertEqual('bar', foo_content)
63
0.12.8 by Aaron Bentley
Test deleting and unversioning
64
    def test_roundtrip_destruction(self):
65
        tree = self.make_branch_and_tree('.')
66
        self.build_tree([u'foo\u1234', 'bar'])
67
        tree.add([u'foo\u1234', 'bar'], ['foo-id', 'bar-id'])
0.12.9 by Aaron Bentley
Simplify tests
68
        tt, tt2 = self.get_two_previews(tree)
0.12.8 by Aaron Bentley
Test deleting and unversioning
69
        foo_trans_id = tt.trans_id_tree_file_id('foo-id')
70
        tt.unversion_file(foo_trans_id)
71
        bar_trans_id = tt.trans_id_tree_file_id('bar-id')
72
        tt.delete_contents(bar_trans_id)
73
        deserialize(tt2, serialize(tt))
74
        self.assertEqual({u'foo\u1234': foo_trans_id,
75
                          'bar': bar_trans_id,
76
                          '': tt.root}, tt2._tree_path_ids)
77
        self.assertEqual({foo_trans_id: u'foo\u1234',
78
                          bar_trans_id: 'bar',
79
                          tt.root: ''}, tt2._tree_id_paths)
80
        self.assertEqual(set([foo_trans_id]), tt2._removed_id)
81
        self.assertEqual(set([bar_trans_id]), tt2._removed_contents)