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