Skip to content

Commit

Permalink
Add test cases for preserving slash in absolute() and expanduser()
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 8, 2023
1 parent 7b6766f commit f5c2265
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,9 @@ def test_absolute_common(self):
self.assertEqual(str(P('a', '..').absolute()), os.path.join(BASE, 'a', '..'))
self.assertEqual(str(P('..', 'b').absolute()), os.path.join(BASE, '..', 'b'))

# Trailing slash should be preserved
self.assertEqual(str(P('a/').absolute()), os.path.join(BASE, 'a', ''))

def _test_home(self, p):
q = self.cls(os.path.expanduser('~'))
self.assertEqual(p, q)
Expand Down Expand Up @@ -3066,6 +3069,12 @@ def test_expanduser_common(self):
P = self.cls
p = P('~')
self.assertEqual(p.expanduser(), P(os.path.expanduser('~')))
p = P('~/')
self.assertEqual(p.expanduser(), P(os.path.expanduser('~/')))
p = P('~/foo')
self.assertEqual(p.expanduser(), P(os.path.expanduser('~/foo')))
p = P('~/foo/')
self.assertEqual(p.expanduser(), P(os.path.expanduser('~/foo/')))
p = P('foo')
self.assertEqual(p.expanduser(), p)
p = P('/~')
Expand Down Expand Up @@ -3845,10 +3854,12 @@ def test_absolute(self):
# Relative path with root
self.assertEqual(str(P('\\').absolute()), drive + '\\')
self.assertEqual(str(P('\\foo').absolute()), drive + '\\foo')
self.assertEqual(str(P('\\foo\\').absolute()), drive + '\\foo\\')

# Relative path on current drive
self.assertEqual(str(P(drive).absolute()), BASE)
self.assertEqual(str(P(drive + 'foo').absolute()), os.path.join(BASE, 'foo'))
self.assertEqual(str(P(drive + 'foo\\').absolute()), os.path.join(BASE, 'foo\\'))

with os_helper.subst_drive(BASE) as other_drive:
# Set the working directory on the substitute drive
Expand All @@ -3860,6 +3871,7 @@ def test_absolute(self):
# Relative path on another drive
self.assertEqual(str(P(other_drive).absolute()), other_cwd)
self.assertEqual(str(P(other_drive + 'foo').absolute()), other_cwd + '\\foo')
self.assertEqual(str(P(other_drive + 'foo\\').absolute()), other_cwd + '\\foo\\')

def test_glob(self):
P = self.cls
Expand Down

0 comments on commit f5c2265

Please sign in to comment.