MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_absolute_windows

Method test_absolute_windows

Lib/test/test_pathlib/test_pathlib.py:3331–3374  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3329
3330 @needs_windows
3331 def test_absolute_windows(self):
3332 P = self.cls
3333
3334 # Simple absolute paths.
3335 self.assertEqual(str(P('c:\\').absolute()), 'c:\\')
3336 self.assertEqual(str(P('c:\\a').absolute()), 'c:\\a')
3337 self.assertEqual(str(P('c:\\a\\b').absolute()), 'c:\\a\\b')
3338
3339 # UNC absolute paths.
3340 share = '\\\\server\\share\\'
3341 self.assertEqual(str(P(share).absolute()), share)
3342 self.assertEqual(str(P(share + 'a').absolute()), share + 'a')
3343 self.assertEqual(str(P(share + 'a\\b').absolute()), share + 'a\\b')
3344
3345 # UNC relative paths.
3346 with mock.patch("os.getcwd") as getcwd:
3347 getcwd.return_value = share
3348
3349 self.assertEqual(str(P().absolute()), share)
3350 self.assertEqual(str(P('.').absolute()), share)
3351 self.assertEqual(str(P('a').absolute()), os.path.join(share, 'a'))
3352 self.assertEqual(str(P('a', 'b', 'c').absolute()),
3353 os.path.join(share, 'a', 'b', 'c'))
3354
3355 drive = os.path.splitdrive(self.base)[0]
3356 with os_helper.change_cwd(self.base):
3357 # Relative path with root
3358 self.assertEqual(str(P('\\').absolute()), drive + '\\')
3359 self.assertEqual(str(P('\\foo').absolute()), drive + '\\foo')
3360
3361 # Relative path on current drive
3362 self.assertEqual(str(P(drive).absolute()), self.base)
3363 self.assertEqual(str(P(drive + 'foo').absolute()), os.path.join(self.base, 'foo'))
3364
3365 with os_helper.subst_drive(self.base) as other_drive:
3366 # Set the working directory on the substitute drive
3367 saved_cwd = os.getcwd()
3368 other_cwd = f'{other_drive}\\dirA'
3369 os.chdir(other_cwd)
3370 os.chdir(saved_cwd)
3371
3372 # Relative path on another drive
3373 self.assertEqual(str(P(other_drive).absolute()), other_cwd)
3374 self.assertEqual(str(P(other_drive + 'foo').absolute()), other_cwd + '\\foo')
3375
3376 @needs_windows
3377 def test_expanduser_windows(self):

Callers

nothing calls this directly

Calls 5

strFunction · 0.85
absoluteMethod · 0.80
PClass · 0.70
assertEqualMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected