[MERGE] Fix MemoryTransport().abspath('/foo')

Andrew Bennetts andrew at canonical.com
Mon Oct 16 05:59:50 BST 2006


John Arbash Meinel wrote:
[...]
> 
> v- Make sure you update to the latest bzr.dev. I got rid of these doc
> string tests, in favor of real tests in the test suite. (I left them as
> as examples, but not as doc tests).
> 
> It turns out DocTest doesn't play nice with lazy_import. So where they
> conflict, I made lazy_import win.

Makes sense.  I've moved the tests to test__combine_paths.

I've left one of the new cases in the docstring, because I think it's worth
giving an example of what _combine_paths does with absolute paths:

+            >>> t._combine_paths('/home/sarah', '/etc')
+            '/etc'

> Other than the one test, it looks good to me.

Thanks!

I've attached a current diff of what's at
http://people.ubuntu.com/~andrew/bzr/memory-transport-abspath/, for the curious.

-Andrew.

-------------- next part --------------
=== modified file 'bzrlib/tests/test_transport.py'
--- bzrlib/tests/test_transport.py	2006-10-06 05:53:44 +0000
+++ bzrlib/tests/test_transport.py	2006-10-16 04:53:55 +0000
@@ -106,6 +106,10 @@
                          t._combine_paths('/home/sarah', 'project/foo'))
         self.assertEqual('/etc',
                          t._combine_paths('/home/sarah', '../../etc'))
+        self.assertEqual('/etc',
+                         t._combine_paths('/home/sarah', '../../../etc'))
+        self.assertEqual('/etc',
+                         t._combine_paths('/home/sarah', '/etc'))
 
 
 class TestCoalesceOffsets(TestCase):
@@ -186,8 +190,9 @@
         self.assertEqual("memory:///", transport.base)
         self.assertEqual("memory:///", transport.abspath('/'))
 
-    def test_relpath(self):
+    def test_abspath_of_relpath_starting_at_root(self):
         transport = MemoryTransport()
+        self.assertEqual("memory:///foo", transport.abspath('/foo'))
 
     def test_append_and_get(self):
         transport = MemoryTransport()

=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- bzrlib/tests/test_transport_implementations.py	2006-09-22 04:39:58 +0000
+++ bzrlib/tests/test_transport_implementations.py	2006-10-16 04:53:55 +0000
@@ -1119,6 +1119,9 @@
         # the abspath of "/" and "/foo/.." should result in the same location
         self.assertEqual(transport.abspath("/"), transport.abspath("/foo/.."))
 
+        self.assertEqual(transport.clone("/").abspath('foo'),
+                         transport.abspath("/foo"))
+
     def test_local_abspath(self):
         transport = self.get_transport()
         try:

=== modified file 'bzrlib/transport/__init__.py'
--- bzrlib/transport/__init__.py	2006-10-13 06:41:04 +0000
+++ bzrlib/transport/__init__.py	2006-10-16 04:53:55 +0000
@@ -330,6 +330,8 @@
                 => '/home/sarah/project/foo'
             t._combine_paths('/home/sarah', '../../etc')
                 => '/etc'
+            t._combine_paths('/home/sarah', '/etc')
+                => '/etc'
 
         :param base_path: urlencoded path for the transport root; typically a 
              URL but need not contain scheme/host/etc.
@@ -361,6 +363,8 @@
             elif p != '':
                 base_parts.append(p)
         path = '/'.join(base_parts)
+        if not path.startswith('/'):
+            path = '/' + path
         return path
 
     def relpath(self, abspath):



More information about the bazaar mailing list