Skip to content

GH-89812: Miscellaneous pathlib test improvements #106063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1628,11 +1628,6 @@ def cleanup():
# Broken symlink (pointing to itself).
os.symlink('brokenLinkLoop', join('brokenLinkLoop'))

def assertSame(self, path_a, path_b):
self.assertTrue(os.path.samefile(str(path_a), str(path_b)),
"%r and %r don't point to the same file" %
(path_a, path_b))

def assertFileNotFound(self, func, *args, **kwargs):
with self.assertRaises(FileNotFoundError) as cm:
func(*args, **kwargs)
Expand Down Expand Up @@ -1664,7 +1659,7 @@ def test_samefile(self):
def test_empty_path(self):
# The empty path points to '.'
p = self.cls('')
self.assertEqual(p.stat(), os.stat('.'))
self.assertEqual(str(p), '.')

def test_exists(self):
P = self.cls
Expand Down Expand Up @@ -1693,9 +1688,6 @@ def test_open_common(self):
with (p / 'fileA').open('rb') as f:
self.assertIsInstance(f, io.BufferedIOBase)
self.assertEqual(f.read().strip(), b"this is file A")
with (p / 'fileA').open('rb', buffering=0) as f:
self.assertIsInstance(f, io.RawIOBase)
self.assertEqual(f.read().strip(), b"this is file A")

def test_read_write_bytes(self):
p = self.cls(BASE)
Expand Down Expand Up @@ -2017,7 +2009,6 @@ def test_glob_permissions(self):
P = self.cls
base = P(BASE) / 'permissions'
base.mkdir()
self.addCleanup(os_helper.rmtree, base)

for i in range(100):
link = base / f"link{i}"
Expand Down Expand Up @@ -2045,8 +2036,8 @@ def test_glob_above_recursion_limit(self):
recursion_limit = 50
# directory_depth > recursion_limit
directory_depth = recursion_limit + 10
base = pathlib.Path(os_helper.TESTFN, 'deep')
path = pathlib.Path(base, *(['d'] * directory_depth))
base = self.cls(BASE, 'deep')
path = self.cls(base, *(['d'] * directory_depth))
path.mkdir(parents=True)

with set_recursion_limit(recursion_limit):
Expand Down Expand Up @@ -2242,18 +2233,12 @@ def test_is_file_no_follow_symlinks(self):

def test_is_mount(self):
P = self.cls(BASE)
if os.name == 'nt':
R = self.cls('c:\\')
else:
R = self.cls('/')
self.assertFalse((P / 'fileA').is_mount())
self.assertFalse((P / 'dirA').is_mount())
self.assertFalse((P / 'non-existing').is_mount())
self.assertFalse((P / 'fileA' / 'bah').is_mount())
self.assertTrue(R.is_mount())
if self.can_symlink:
self.assertFalse((P / 'linkA').is_mount())
self.assertIs((R / '\udfff').is_mount(), False)

def test_is_symlink(self):
P = self.cls(BASE)
Expand Down Expand Up @@ -2496,6 +2481,12 @@ def with_segments(self, *pathsegments):
for dirpath, dirnames, filenames in p.walk():
self.assertEqual(42, dirpath.session_id)

def test_open_unbuffered(self):
p = self.cls(BASE)
with (p / 'fileA').open('rb', buffering=0) as f:
self.assertIsInstance(f, io.RawIOBase)
self.assertEqual(f.read().strip(), b"this is file A")

def test_resolve_nonexist_relative_issue38671(self):
p = self.cls('non', 'exist')

Expand Down Expand Up @@ -2896,6 +2887,14 @@ def test_is_char_device_true(self):
self.assertIs(self.cls('/dev/null\udfff').is_char_device(), False)
self.assertIs(self.cls('/dev/null\x00').is_char_device(), False)

def test_is_mount_root(self):
if os.name == 'nt':
R = self.cls('c:\\')
else:
R = self.cls('/')
self.assertTrue(R.is_mount())
self.assertFalse((R / '\udfff').is_mount())

def test_passing_kwargs_deprecated(self):
with self.assertWarns(DeprecationWarning):
self.cls(foo="bar")
Expand Down