/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2617.4.2 by Robert Collins
Add FileCollection support class.
1
# Copyright (C) 2007 Canonical Ltd
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
2617.4.4 by Robert Collins
Rename to FileNames as per review.
17
"""Tests for the FileNames class."""
2617.4.2 by Robert Collins
Add FileCollection support class.
18
19
from bzrlib import errors
2617.4.4 by Robert Collins
Rename to FileNames as per review.
20
from bzrlib.file_names import FileNames
2617.4.2 by Robert Collins
Add FileCollection support class.
21
from bzrlib.tests import TestCaseWithMemoryTransport
22
from bzrlib.transport import get_transport
23
24
2617.4.4 by Robert Collins
Rename to FileNames as per review.
25
class TestFileNames(TestCaseWithMemoryTransport):
2617.4.2 by Robert Collins
Add FileCollection support class.
26
27
    def test_initialise(self):
28
        t = self.get_transport()
29
        for name in ('index', '00index'):
2617.4.4 by Robert Collins
Rename to FileNames as per review.
30
            names = FileNames(t, name)
31
            names.initialise()
2617.4.2 by Robert Collins
Add FileCollection support class.
32
            self.assertFalse(t.has(name))
2617.4.4 by Robert Collins
Rename to FileNames as per review.
33
            names.save()
2617.4.2 by Robert Collins
Add FileCollection support class.
34
            self.assertEqual('', t.get_bytes(name))
35
        
36
    def test_allocate_trivial(self):
37
        t = self.get_transport()
2617.4.4 by Robert Collins
Rename to FileNames as per review.
38
        names = FileNames(t, 'index')
39
        names.initialise()
40
        name = names.allocate()
2617.4.2 by Robert Collins
Add FileCollection support class.
41
        self.assertEqual('0', name)
42
        self.assertFalse(t.has('index'))
2617.4.4 by Robert Collins
Rename to FileNames as per review.
43
        name = names.allocate()
2617.4.2 by Robert Collins
Add FileCollection support class.
44
        self.assertEqual('1', name)
45
        self.assertFalse(t.has('index'))
46
47
    def test_allocate_overrun(self):
48
        t = self.get_transport()
2617.4.4 by Robert Collins
Rename to FileNames as per review.
49
        names = FileNames(t, 'index')
50
        names.initialise()
51
        names._cap = 5
2617.4.2 by Robert Collins
Add FileCollection support class.
52
        for number in xrange(5):
2617.4.4 by Robert Collins
Rename to FileNames as per review.
53
            name = names.allocate()
54
        self.assertRaises(errors.BzrError, names.allocate)
2617.4.2 by Robert Collins
Add FileCollection support class.
55
56
    def test_load(self):
57
        t = self.get_transport()
2617.4.4 by Robert Collins
Rename to FileNames as per review.
58
        names = FileNames(t, 'index')
59
        names.initialise()
60
        names.allocate()
61
        names.allocate()
62
        names.save()
63
        names = FileNames(t, 'index')
64
        names.load()
65
        self.assertEqual(set(['0', '1']), names.names())
2617.4.2 by Robert Collins
Add FileCollection support class.
66
2617.4.3 by Robert Collins
Check loading empty collections and support removing items.
67
    def test_load_empty(self):
68
        t = self.get_transport()
2617.4.4 by Robert Collins
Rename to FileNames as per review.
69
        names = FileNames(t, 'index')
70
        names.initialise()
71
        names.save()
72
        names = FileNames(t, 'index')
73
        names.load()
74
        self.assertEqual(set(), names.names())
2617.4.3 by Robert Collins
Check loading empty collections and support removing items.
75
2617.4.2 by Robert Collins
Add FileCollection support class.
76
    def test_names(self):
77
        t = self.get_transport()
2617.4.4 by Robert Collins
Rename to FileNames as per review.
78
        names = FileNames(t, 'index')
79
        names.initialise()
80
        names.allocate()
81
        names.allocate()
82
        self.assertEqual(set(['0', '1']), names.names())
2617.4.2 by Robert Collins
Add FileCollection support class.
83
84
    def test_names_on_unlistable_works(self):
85
        t = self.get_transport()
2617.4.4 by Robert Collins
Rename to FileNames as per review.
86
        names = FileNames(t, 'index')
87
        names.initialise()
88
        names.allocate()
89
        names.allocate()
90
        names.save()
91
        names = FileNames(
2617.4.2 by Robert Collins
Add FileCollection support class.
92
            get_transport('unlistable+' + self.get_url()), 'index')
2617.4.4 by Robert Collins
Rename to FileNames as per review.
93
        names.load()
94
        self.assertEqual(set(['0', '1']), names.names())
2617.4.3 by Robert Collins
Check loading empty collections and support removing items.
95
96
    def test_remove(self):
97
        t = self.get_transport()
2617.4.4 by Robert Collins
Rename to FileNames as per review.
98
        names = FileNames(t, 'index')
99
        names.initialise()
100
        name1 = names.allocate()
101
        name2 = names.allocate()
102
        names.remove(name1)
103
        self.assertEqual(set([name2]), names.names())