Added root directory handling to VCS._u_rel_path().
authorW. Trevor King <wking@drexel.edu>
Tue, 29 Dec 2009 14:46:59 +0000 (09:46 -0500)
committerW. Trevor King <wking@drexel.edu>
Tue, 29 Dec 2009 14:46:59 +0000 (09:46 -0500)
Now it returns '.' when you ask for the relative path from root to
itself.  It used to raise AssertionError or InvalidPath.

libbe/storage/vcs/base.py

index 040c3f9c74a65cf6783d0923da37b84be78ff9e5..7565caf9bd144a35840dbdfba40b2b758bbaffb7 100644 (file)
@@ -904,6 +904,10 @@ os.listdir(self.get_path("bugs")):
         >>> vcs = new()
         >>> vcs._u_rel_path("/a.b/c/.be", "/a.b/c")
         '.be'
+        >>> vcs._u_rel_path("/a.b/c/", "/a.b/c")
+        '.'
+        >>> vcs._u_rel_path("/a.b/c/", "/a.b/c/")
+        '.'
         """
         if root == None:
             if self.repo == None:
@@ -912,10 +916,10 @@ os.listdir(self.get_path("bugs")):
         path = os.path.abspath(path)
         absRoot = os.path.abspath(root)
         absRootSlashedDir = os.path.join(absRoot,"")
+        if path in [absRoot, absRootSlashedDir]:
+            return '.'
         if not path.startswith(absRootSlashedDir):
             raise InvalidPath(path, absRootSlashedDir)
-        assert path != absRootSlashedDir, \
-            "file %s == root directory %s" % (path, absRootSlashedDir)
         relpath = path[len(absRootSlashedDir):]
         return relpath
 
@@ -1093,4 +1097,5 @@ if libbe.TESTING == True:
     make_vcs_testcase_subclasses(VCS, sys.modules[__name__])
 
     unitsuite =unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
-    suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()])
+    #suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()])
+    suite = unittest.TestSuite([doctest.DocTestSuite()])