~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_file_names.py

Merge rename of FileCollection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
17
 
"""Tests for the FileCollection class."""
 
17
"""Tests for the FileNames class."""
18
18
 
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
23
23
 
24
24
 
25
 
class TestFileCollection(TestCaseWithMemoryTransport):
 
25
class TestFileNames(TestCaseWithMemoryTransport):
26
26
 
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)
 
31
            names.initialise()
32
32
            self.assertFalse(t.has(name))
33
 
            collection.save()
 
33
            names.save()
34
34
            self.assertEqual('', t.get_bytes(name))
35
35
        
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')
 
39
        names.initialise()
 
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'))
46
46
 
47
47
    def test_allocate_overrun(self):
48
48
        t = self.get_transport()
49
 
        collection = FileCollection(t, 'index')
50
 
        collection.initialise()
51
 
        collection._cap = 5
 
49
        names = FileNames(t, 'index')
 
50
        names.initialise()
 
51
        names._cap = 5
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)
55
55
 
56
56
    def test_load(self):
57
57
        t = self.get_transport()
58
 
        collection = FileCollection(t, 'index')
59
 
        collection.initialise()
60
 
        collection.allocate()
61
 
        collection.allocate()
62
 
        collection.save()
63
 
        collection = FileCollection(t, 'index')
64
 
        collection.load()
65
 
        self.assertEqual(set(['0', '1']), collection.names())
 
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())
66
66
 
67
67
    def test_load_empty(self):
68
68
        t = self.get_transport()
69
 
        collection = FileCollection(t, 'index')
70
 
        collection.initialise()
71
 
        collection.save()
72
 
        collection = FileCollection(t, 'index')
73
 
        collection.load()
74
 
        self.assertEqual(set(), collection.names())
 
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())
75
75
 
76
76
    def test_names(self):
77
77
        t = self.get_transport()
78
 
        collection = FileCollection(t, 'index')
79
 
        collection.initialise()
80
 
        collection.allocate()
81
 
        collection.allocate()
82
 
        self.assertEqual(set(['0', '1']), collection.names())
 
78
        names = FileNames(t, 'index')
 
79
        names.initialise()
 
80
        names.allocate()
 
81
        names.allocate()
 
82
        self.assertEqual(set(['0', '1']), names.names())
83
83
 
84
84
    def test_names_on_unlistable_works(self):
85
85
        t = self.get_transport()
86
 
        collection = FileCollection(t, 'index')
87
 
        collection.initialise()
88
 
        collection.allocate()
89
 
        collection.allocate()
90
 
        collection.save()
91
 
        collection = FileCollection(
 
86
        names = FileNames(t, 'index')
 
87
        names.initialise()
 
88
        names.allocate()
 
89
        names.allocate()
 
90
        names.save()
 
91
        names = FileNames(
92
92
            get_transport('unlistable+' + self.get_url()), 'index')
93
 
        collection.load()
94
 
        self.assertEqual(set(['0', '1']), collection.names())
 
93
        names.load()
 
94
        self.assertEqual(set(['0', '1']), names.names())
95
95
 
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')
 
99
        names.initialise()
 
100
        name1 = names.allocate()
 
101
        name2 = names.allocate()
 
102
        names.remove(name1)
 
103
        self.assertEqual(set([name2]), names.names())