Skip to content

Commit

Permalink
pythonGH-89812: Miscellaneous pathlib test improvements
Browse files Browse the repository at this point in the history
- Split out dedicated test for unbuffered `open()`
- Split out dedicated test for `is_mount()` at the filesystem root
- Avoid `os.stat()` when checking that empty paths point to '.'
- Remove unnecessary `rmtree()` call
  • Loading branch information
barneygale committed Jun 24, 2023
1 parent 4a6c84f commit ef08269
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,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 @@ -1700,9 +1700,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 +2014,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 @@ -2210,18 +2206,10 @@ def test_is_file(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 os_helper.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 @@ -2854,6 +2842,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 Expand Up @@ -3121,6 +3117,12 @@ def test_open_mode(self):
st = os.stat(join('other_new_file'))
self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)

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_root(self):
current_directory = os.getcwd()
try:
Expand Down

0 comments on commit ef08269

Please sign in to comment.