slashes."""
return str(self).replace(self.pathmod.sep, '/')
- def __repr__(self):
- return "{}({!r})".format(self.__class__.__name__, self.as_posix())
-
@property
def drive(self):
"""The drive prefix (letter or UNC path), if any."""
self.assertEqual(hash(pp), hash(p))
self.assertEqual(str(pp), str(p))
+ def test_repr_common(self):
+ for pathstr in ('a', 'a/b', 'a/b/c', '/', '/a/b', '/a/b/c'):
+ with self.subTest(pathstr=pathstr):
+ p = self.cls(pathstr)
+ clsname = p.__class__.__name__
+ r = repr(p)
+ # The repr() is in the form ClassName("forward-slashes path").
+ self.assertTrue(r.startswith(clsname + '('), r)
+ self.assertTrue(r.endswith(')'), r)
+ inner = r[len(clsname) + 1 : -1]
+ self.assertEqual(eval(inner), p.as_posix())
+
def test_fspath_common(self):
P = self.cls
p = P('a/b')
self.assertFalse(hasattr(P, '__fspath__'))
self.assertFalse(hasattr(P, '__bytes__'))
self.assertIs(P.__reduce__, object.__reduce__)
+ self.assertIs(P.__repr__, object.__repr__)
self.assertIs(P.__hash__, object.__hash__)
self.assertIs(P.__eq__, object.__eq__)
self.assertIs(P.__lt__, object.__lt__)
self.assertEqual(P(pathstr).as_posix(), pathstr)
# Other tests for as_posix() are in test_equivalences().
- def test_repr_common(self):
- for pathstr in ('a', 'a/b', 'a/b/c', '/', '/a/b', '/a/b/c'):
- with self.subTest(pathstr=pathstr):
- p = self.cls(pathstr)
- clsname = p.__class__.__name__
- r = repr(p)
- # The repr() is in the form ClassName("forward-slashes path").
- self.assertTrue(r.startswith(clsname + '('), r)
- self.assertTrue(r.endswith(')'), r)
- inner = r[len(clsname) + 1 : -1]
- self.assertEqual(eval(inner), p.as_posix())
-
def test_eq_common(self):
P = self.cls
self.assertEqual(P('a/b'), P('a/b'))