Rev 2620: Check loading empty collections and support removing items. in http://people.ubuntu.com/~robertc/baz2.0/file-collection

Robert Collins robertc at robertcollins.net
Sat Jul 14 11:13:40 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/file-collection

------------------------------------------------------------
revno: 2620
revision-id: robertc at robertcollins.net-20070714101338-eu0cblg5ds2q2him
parent: robertc at robertcollins.net-20070714100801-bo0gezkinkusmtr3
committer: Robert Collins <robertc at robertcollins.net>
branch nick: file-collection
timestamp: Sat 2007-07-14 20:13:38 +1000
message:
  Check loading empty collections and support removing items.
modified:
  bzrlib/file_collection.py      file_collection.py-20070714100753-j2zz4ahtk331k5zm-1
  bzrlib/tests/test_file_collection.py test_file_collection-20070714093417-5gc9d821to85zo4t-1
=== modified file 'bzrlib/file_collection.py'
--- a/bzrlib/file_collection.py	2007-07-14 10:08:01 +0000
+++ b/bzrlib/file_collection.py	2007-07-14 10:13:38 +0000
@@ -65,11 +65,17 @@
         """Load the names from the transport."""
         self._names = set(self._transport.get_bytes(
             self._index_name).split('\n'))
+        if '' in self._names:
+            self._names.remove('')
 
     def names(self):
         """What are the names in this collection?"""
         return frozenset(self._names)
 
+    def remove(self, name):
+        """Remove name from the collection."""
+        self._names.remove(name)
+
     def save(self):
         """Save the set of names."""
         self._transport.put_bytes(self._index_name, '\n'.join(self._names))

=== modified file 'bzrlib/tests/test_file_collection.py'
--- a/bzrlib/tests/test_file_collection.py	2007-07-14 10:08:01 +0000
+++ b/bzrlib/tests/test_file_collection.py	2007-07-14 10:13:38 +0000
@@ -64,6 +64,15 @@
         collection.load()
         self.assertEqual(set(['0', '1']), collection.names())
 
+    def test_load_empty(self):
+        t = self.get_transport()
+        collection = FileCollection(t, 'index')
+        collection.initialise()
+        collection.save()
+        collection = FileCollection(t, 'index')
+        collection.load()
+        self.assertEqual(set(), collection.names())
+
     def test_names(self):
         t = self.get_transport()
         collection = FileCollection(t, 'index')
@@ -83,3 +92,12 @@
             get_transport('unlistable+' + self.get_url()), 'index')
         collection.load()
         self.assertEqual(set(['0', '1']), collection.names())
+
+    def test_remove(self):
+        t = self.get_transport()
+        collection = FileCollection(t, 'index')
+        collection.initialise()
+        name1 = collection.allocate()
+        name2 = collection.allocate()
+        collection.remove(name1)
+        self.assertEqual(set([name2]), collection.names())




More information about the bazaar-commits mailing list