Commits

Antoine Pitrou  committed 36e733f

Rename relative_to() to relative(), removing the old relative() method.

  • Participants
  • Parent commits 64b5d6c
  • Branches pep428

Comments (0)

Files changed (2)

         return self._from_parsed_parts(self._drv, self._root,
                                        self._parts[:-1] + [name])
 
-    def relative(self):
-        """Return a new path without any drive and root.
-        """
-        if self._drv or self._root:
-            return self._from_parsed_parts('', '', self._parts[1:])
-        else:
-            return self._from_parsed_parts('', '', self._parts)
-
-    def relative_to(self, *other):
+    def relative(self, *other):
         """Return the relative path to another path identified by the passed
         arguments.  If the operation is not possible (because this is not
         a subpath of the other path), raise ValueError.

File test_pathlib.py

     def test_relative_common(self):
         P = self.cls
         p = P('a/b')
-        self.assertEqual(p.relative(), P('a/b'))
+        self.assertRaises(TypeError, p.relative)
+        self.assertEqual(p.relative(P()), P('a/b'))
+        self.assertEqual(p.relative(P('a')), P('b'))
+        self.assertEqual(p.relative(P('a/b')), P())
+        # With several args
+        self.assertEqual(p.relative('a', 'b'), P())
+        # Unrelated paths
+        self.assertRaises(ValueError, p.relative, P('c'))
+        self.assertRaises(ValueError, p.relative, P('a/b/c'))
+        self.assertRaises(ValueError, p.relative, P('a/c'))
+        self.assertRaises(ValueError, p.relative, P('/a'))
         p = P('/a/b')
-        self.assertEqual(p.relative(), P('a/b'))
-        p = P('/')
-        self.assertEqual(p.relative(), P())
-
-    def test_relative_to_common(self):
-        P = self.cls
-        p = P('a/b')
-        self.assertRaises(TypeError, p.relative_to)
-        self.assertEqual(p.relative_to(P()), P('a/b'))
-        self.assertEqual(p.relative_to(P('a')), P('b'))
-        self.assertEqual(p.relative_to(P('a/b')), P())
-        # With several args
-        self.assertEqual(p.relative_to('a', 'b'), P())
+        self.assertEqual(p.relative(P('/')), P('a/b'))
+        self.assertEqual(p.relative(P('/a')), P('b'))
+        self.assertEqual(p.relative(P('/a/b')), P())
         # Unrelated paths
-        self.assertRaises(ValueError, p.relative_to, P('c'))
-        self.assertRaises(ValueError, p.relative_to, P('a/b/c'))
-        self.assertRaises(ValueError, p.relative_to, P('a/c'))
-        self.assertRaises(ValueError, p.relative_to, P('/a'))
-        p = P('/a/b')
-        self.assertEqual(p.relative_to(P('/')), P('a/b'))
-        self.assertEqual(p.relative_to(P('/a')), P('b'))
-        self.assertEqual(p.relative_to(P('/a/b')), P())
-        # Unrelated paths
-        self.assertRaises(ValueError, p.relative_to, P('/c'))
-        self.assertRaises(ValueError, p.relative_to, P('/a/b/c'))
-        self.assertRaises(ValueError, p.relative_to, P('/a/c'))
-        self.assertRaises(ValueError, p.relative_to, P())
-        self.assertRaises(ValueError, p.relative_to, P('a'))
+        self.assertRaises(ValueError, p.relative, P('/c'))
+        self.assertRaises(ValueError, p.relative, P('/a/b/c'))
+        self.assertRaises(ValueError, p.relative, P('/a/c'))
+        self.assertRaises(ValueError, p.relative, P())
+        self.assertRaises(ValueError, p.relative, P('a'))
 
 
 class PurePosixPathTest(_BasePurePathTest):
     def test_relative(self):
         P = self.cls
         p = P('c:a/b')
-        self.assertEqual(p.relative(), P('a/b'))
+        self.assertEqual(p.relative(P('c:')), P('a/b'))
+        self.assertEqual(p.relative(P('c:a')), P('b'))
+        self.assertEqual(p.relative(P('c:a/b')), P())
+        # Unrelated paths
+        self.assertRaises(ValueError, p.relative, P())
+        self.assertRaises(ValueError, p.relative, P('d:'))
+        self.assertRaises(ValueError, p.relative, P('a'))
+        self.assertRaises(ValueError, p.relative, P('/a'))
+        self.assertRaises(ValueError, p.relative, P('c:a/b/c'))
+        self.assertRaises(ValueError, p.relative, P('c:a/c'))
+        self.assertRaises(ValueError, p.relative, P('c:/a'))
         p = P('c:/a/b')
-        self.assertEqual(p.relative(), P('a/b'))
-        p = P('c:')
-        self.assertEqual(p.relative(), P())
-        p = P('c:/')
-        self.assertEqual(p.relative(), P())
-
-    def test_relative_to(self):
-        P = self.cls
-        p = P('c:a/b')
-        self.assertEqual(p.relative_to(P('c:')), P('a/b'))
-        self.assertEqual(p.relative_to(P('c:a')), P('b'))
-        self.assertEqual(p.relative_to(P('c:a/b')), P())
+        self.assertEqual(p.relative(P('c:')), P('/a/b'))
+        self.assertEqual(p.relative(P('c:/')), P('a/b'))
+        self.assertEqual(p.relative(P('c:/a')), P('b'))
+        self.assertEqual(p.relative(P('c:/a/b')), P())
         # Unrelated paths
-        self.assertRaises(ValueError, p.relative_to, P())
-        self.assertRaises(ValueError, p.relative_to, P('d:'))
-        self.assertRaises(ValueError, p.relative_to, P('a'))
-        self.assertRaises(ValueError, p.relative_to, P('/a'))
-        self.assertRaises(ValueError, p.relative_to, P('c:a/b/c'))
-        self.assertRaises(ValueError, p.relative_to, P('c:a/c'))
-        self.assertRaises(ValueError, p.relative_to, P('c:/a'))
-        p = P('c:/a/b')
-        self.assertEqual(p.relative_to(P('c:')), P('/a/b'))
-        self.assertEqual(p.relative_to(P('c:/')), P('a/b'))
-        self.assertEqual(p.relative_to(P('c:/a')), P('b'))
-        self.assertEqual(p.relative_to(P('c:/a/b')), P())
-        # Unrelated paths
-        self.assertRaises(ValueError, p.relative_to, P('c:/c'))
-        self.assertRaises(ValueError, p.relative_to, P('c:/a/b/c'))
-        self.assertRaises(ValueError, p.relative_to, P('c:/a/c'))
-        self.assertRaises(ValueError, p.relative_to, P('c:a'))
-        self.assertRaises(ValueError, p.relative_to, P('d:'))
-        self.assertRaises(ValueError, p.relative_to, P('d:/'))
-        self.assertRaises(ValueError, p.relative_to, P('/a'))
-        self.assertRaises(ValueError, p.relative_to, P('//c/a'))
+        self.assertRaises(ValueError, p.relative, P('c:/c'))
+        self.assertRaises(ValueError, p.relative, P('c:/a/b/c'))
+        self.assertRaises(ValueError, p.relative, P('c:/a/c'))
+        self.assertRaises(ValueError, p.relative, P('c:a'))
+        self.assertRaises(ValueError, p.relative, P('d:'))
+        self.assertRaises(ValueError, p.relative, P('d:/'))
+        self.assertRaises(ValueError, p.relative, P('/a'))
+        self.assertRaises(ValueError, p.relative, P('//c/a'))
         # UNC paths
         p = P('//a/b/c/d')
-        self.assertEqual(p.relative_to(P('//a/b')), P('c/d'))
-        self.assertEqual(p.relative_to(P('//a/b/c')), P('d'))
-        self.assertEqual(p.relative_to(P('//a/b/c/d')), P())
+        self.assertEqual(p.relative(P('//a/b')), P('c/d'))
+        self.assertEqual(p.relative(P('//a/b/c')), P('d'))
+        self.assertEqual(p.relative(P('//a/b/c/d')), P())
         # Unrelated paths
-        self.assertRaises(ValueError, p.relative_to, P('/a/b/c'))
-        self.assertRaises(ValueError, p.relative_to, P('c:/a/b/c'))
-        self.assertRaises(ValueError, p.relative_to, P('//z/b/c'))
-        self.assertRaises(ValueError, p.relative_to, P('//a/z/c'))
+        self.assertRaises(ValueError, p.relative, P('/a/b/c'))
+        self.assertRaises(ValueError, p.relative, P('c:/a/b/c'))
+        self.assertRaises(ValueError, p.relative, P('//z/b/c'))
+        self.assertRaises(ValueError, p.relative, P('//a/z/c'))
 
     def test_is_absolute(self):
         P = self.cls