Rev 4947: (jam) Have MemoryServer unregister itself on stop_server in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jan 8 20:54:04 GMT 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4947 [merge]
revision-id: pqm at pqm.ubuntu.com-20100108205400-08gb738zwfbfhnvi
parent: pqm at pqm.ubuntu.com-20100108092739-ojag1uqo8uf5tief
parent: john at arbash-meinel.com-20100108200304-i0xp20kkotbh1q3e
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-01-08 20:54:00 +0000
message:
  (jam) Have MemoryServer unregister itself on stop_server
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
  bzrlib/transport/memory.py     memory.py-20051016101338-cd008dbdf69f04fc
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-01-07 03:03:01 +0000
+++ b/bzrlib/tests/__init__.py	2010-01-08 17:28:25 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py	2010-01-07 03:03:01 +0000
+++ b/bzrlib/tests/test_transport.py	2010-01-08 20:03:04 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
+# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -21,13 +21,18 @@
 import sys
 import threading
 
-import bzrlib
 from bzrlib import (
     errors,
     osutils,
     tests,
+    transport as _mod_transport,
     urlutils,
     )
+from bzrlib.transport import (
+    fakenfs,
+    memory,
+    readonly,
+    )
 from bzrlib.errors import (DependencyNotPresent,
                            FileExists,
                            InvalidURLJoin,
@@ -50,7 +55,6 @@
                               Transport,
                               )
 from bzrlib.transport.chroot import ChrootServer
-from bzrlib.transport.memory import MemoryTransport
 from bzrlib.transport.local import (LocalTransport,
                                     EmulatedWin32LocalTransport)
 from bzrlib.transport.pathfilter import PathFilteringServer
@@ -166,7 +170,7 @@
 
     def test_local_abspath_non_local_transport(self):
         # the base implementation should throw
-        t = MemoryTransport()
+        t = memory.MemoryTransport()
         e = self.assertRaises(errors.NotLocalUrl, t.local_abspath, 't')
         self.assertEqual('memory:///t is not a local path.', str(e))
 
@@ -256,68 +260,83 @@
                    max_size=1*1024*1024*1024)
 
 
+class TestMemoryServer(TestCase):
+
+    def test_create_server(self):
+        server = memory.MemoryServer()
+        server.start_server()
+        url = server.get_url()
+        self.assertTrue(url in _mod_transport.transport_list_registry)
+        t = _mod_transport.get_transport(url)
+        del t
+        server.stop_server()
+        self.assertFalse(url in _mod_transport.transport_list_registry)
+        self.assertRaises(errors.UnsupportedProtocol,
+                          _mod_transport.get_transport, url)
+
+
 class TestMemoryTransport(TestCase):
 
     def test_get_transport(self):
-        MemoryTransport()
+        memory.MemoryTransport()
 
     def test_clone(self):
-        transport = MemoryTransport()
-        self.assertTrue(isinstance(transport, MemoryTransport))
+        transport = memory.MemoryTransport()
+        self.assertTrue(isinstance(transport, memory.MemoryTransport))
         self.assertEqual("memory:///", transport.clone("/").base)
 
     def test_abspath(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertEqual("memory:///relpath", transport.abspath('relpath'))
 
     def test_abspath_of_root(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertEqual("memory:///", transport.base)
         self.assertEqual("memory:///", transport.abspath('/'))
 
     def test_abspath_of_relpath_starting_at_root(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertEqual("memory:///foo", transport.abspath('/foo'))
 
     def test_append_and_get(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.append_bytes('path', 'content')
         self.assertEqual(transport.get('path').read(), 'content')
         transport.append_file('path', StringIO('content'))
         self.assertEqual(transport.get('path').read(), 'contentcontent')
 
     def test_put_and_get(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.put_file('path', StringIO('content'))
         self.assertEqual(transport.get('path').read(), 'content')
         transport.put_bytes('path', 'content')
         self.assertEqual(transport.get('path').read(), 'content')
 
     def test_append_without_dir_fails(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertRaises(NoSuchFile,
                           transport.append_bytes, 'dir/path', 'content')
 
     def test_put_without_dir_fails(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertRaises(NoSuchFile,
                           transport.put_file, 'dir/path', StringIO('content'))
 
     def test_get_missing(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertRaises(NoSuchFile, transport.get, 'foo')
 
     def test_has_missing(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertEquals(False, transport.has('foo'))
 
     def test_has_present(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.append_bytes('foo', 'content')
         self.assertEquals(True, transport.has('foo'))
 
     def test_list_dir(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.put_bytes('foo', 'content')
         transport.mkdir('dir')
         transport.put_bytes('dir/subfoo', 'content')
@@ -327,28 +346,28 @@
         self.assertEquals(['subfoo'], sorted(transport.list_dir('dir')))
 
     def test_mkdir(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.mkdir('dir')
         transport.append_bytes('dir/path', 'content')
         self.assertEqual(transport.get('dir/path').read(), 'content')
 
     def test_mkdir_missing_parent(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertRaises(NoSuchFile,
                           transport.mkdir, 'dir/dir')
 
     def test_mkdir_twice(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.mkdir('dir')
         self.assertRaises(FileExists, transport.mkdir, 'dir')
 
     def test_parameters(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         self.assertEqual(True, transport.listable())
         self.assertEqual(False, transport.is_readonly())
 
     def test_iter_files_recursive(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.mkdir('dir')
         transport.put_bytes('dir/foo', 'content')
         transport.put_bytes('dir/bar', 'content')
@@ -357,7 +376,7 @@
         self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
 
     def test_stat(self):
-        transport = MemoryTransport()
+        transport = memory.MemoryTransport()
         transport.put_bytes('foo', 'content')
         transport.put_bytes('bar', 'phowar')
         self.assertEqual(7, transport.stat('foo').st_size)
@@ -423,12 +442,12 @@
 class ChrootServerTest(TestCase):
 
     def test_construct(self):
-        backing_transport = MemoryTransport()
+        backing_transport = memory.MemoryTransport()
         server = ChrootServer(backing_transport)
         self.assertEqual(backing_transport, server.backing_transport)
 
     def test_setUp(self):
-        backing_transport = MemoryTransport()
+        backing_transport = memory.MemoryTransport()
         server = ChrootServer(backing_transport)
         server.start_server()
         try:
@@ -437,14 +456,14 @@
             server.stop_server()
 
     def test_stop_server(self):
-        backing_transport = MemoryTransport()
+        backing_transport = memory.MemoryTransport()
         server = ChrootServer(backing_transport)
         server.start_server()
         server.stop_server()
         self.assertFalse(server.scheme in _get_protocol_handlers().keys())
 
     def test_get_url(self):
-        backing_transport = MemoryTransport()
+        backing_transport = memory.MemoryTransport()
         server = ChrootServer(backing_transport)
         server.start_server()
         try:
@@ -541,7 +560,6 @@
     """Readonly decoration specific tests."""
 
     def test_local_parameters(self):
-        import bzrlib.transport.readonly as readonly
         # connect to . in readonly mode
         transport = readonly.ReadonlyTransportDecorator('readonly+.')
         self.assertEqual(True, transport.listable())
@@ -549,7 +567,6 @@
 
     def test_http_parameters(self):
         from bzrlib.tests.http_server import HttpServer
-        import bzrlib.transport.readonly as readonly
         # connect to '.' via http which is not listable
         server = HttpServer()
         self.start_server(server)
@@ -564,7 +581,6 @@
     """NFS decorator specific tests."""
 
     def get_nfs_transport(self, url):
-        import bzrlib.transport.fakenfs as fakenfs
         # connect to url with nfs decoration
         return fakenfs.FakeNFSTransportDecorator('fakenfs+' + url)
 
@@ -584,13 +600,12 @@
         self.start_server(server)
         transport = self.get_nfs_transport(server.get_url())
         self.assertIsInstance(
-            transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
+            transport, fakenfs.FakeNFSTransportDecorator)
         self.assertEqual(False, transport.listable())
         self.assertEqual(True, transport.is_readonly())
 
     def test_fakenfs_server_default(self):
         # a FakeNFSServer() should bring up a local relpath server for itself
-        import bzrlib.transport.fakenfs as fakenfs
         server = fakenfs.FakeNFSServer()
         self.start_server(server)
         # the url should be decorated appropriately

=== modified file 'bzrlib/transport/memory.py'
--- a/bzrlib/transport/memory.py	2010-01-07 03:03:01 +0000
+++ b/bzrlib/transport/memory.py	2010-01-08 17:28:25 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -27,6 +27,9 @@
 from cStringIO import StringIO
 import warnings
 
+from bzrlib import (
+    urlutils,
+    )
 from bzrlib.errors import (
     FileExists,
     LockError,
@@ -42,8 +45,8 @@
     register_transport,
     Server,
     Transport,
+    unregister_transport,
     )
-import bzrlib.urlutils as urlutils
 
 
 
@@ -314,12 +317,12 @@
             result._files = self._files
             result._locks = self._locks
             return result
-        register_transport(self._scheme, memory_factory)
+        self._memory_factory = memory_factory
+        register_transport(self._scheme, self._memory_factory)
 
     def stop_server(self):
         # unregister this server
-        # XXX: why isn't this done? -- mbp 20100106
-        pass
+        unregister_transport(self._scheme, self._memory_factory)
 
     def get_url(self):
         """See bzrlib.transport.Server.get_url."""




More information about the bazaar-commits mailing list