1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
17
"""Tests for the FileNames class."""
19
from bzrlib import errors
20
from bzrlib.file_names import FileNames
21
from bzrlib.tests import TestCaseWithMemoryTransport
22
from bzrlib.transport import get_transport
25
class TestFileNames(TestCaseWithMemoryTransport):
27
def test_initialise(self):
28
t = self.get_transport()
29
for name in ('index', '00index'):
30
names = FileNames(t, name)
32
self.assertFalse(t.has(name))
34
self.assertEqual('', t.get_bytes(name))
36
def test_allocate_trivial(self):
37
t = self.get_transport()
38
names = FileNames(t, 'index')
40
name = names.allocate()
41
self.assertEqual('0', name)
42
self.assertFalse(t.has('index'))
43
name = names.allocate()
44
self.assertEqual('1', name)
45
self.assertFalse(t.has('index'))
47
def test_allocate_overrun(self):
48
t = self.get_transport()
49
names = FileNames(t, 'index')
52
for number in xrange(5):
53
name = names.allocate()
54
self.assertRaises(errors.BzrError, names.allocate)
57
t = self.get_transport()
58
names = FileNames(t, 'index')
63
names = FileNames(t, 'index')
65
self.assertEqual(set(['0', '1']), names.names())
67
def test_load_empty(self):
68
t = self.get_transport()
69
names = FileNames(t, 'index')
72
names = FileNames(t, 'index')
74
self.assertEqual(set(), names.names())
77
t = self.get_transport()
78
names = FileNames(t, 'index')
82
self.assertEqual(set(['0', '1']), names.names())
84
def test_names_on_unlistable_works(self):
85
t = self.get_transport()
86
names = FileNames(t, 'index')
92
get_transport('unlistable+' + self.get_url()), 'index')
94
self.assertEqual(set(['0', '1']), names.names())
96
def test_remove(self):
97
t = self.get_transport()
98
names = FileNames(t, 'index')
100
name1 = names.allocate()
101
name2 = names.allocate()
103
self.assertEqual(set([name2]), names.names())