mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-30879: os.listdir() and os.scandir() now emit bytes names when (#2634)
called with bytes-like argument.
This commit is contained in:
parent
4f9a446f3f
commit
1180e5a518
4 changed files with 35 additions and 6 deletions
|
@ -3420,6 +3420,22 @@ class TestScandir(unittest.TestCase):
|
|||
self.assertEqual(entry.path,
|
||||
os.fsencode(os.path.join(self.path, 'file.txt')))
|
||||
|
||||
def test_bytes_like(self):
|
||||
self.create_file("file.txt")
|
||||
|
||||
for cls in bytearray, memoryview:
|
||||
path_bytes = cls(os.fsencode(self.path))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
entries = list(os.scandir(path_bytes))
|
||||
self.assertEqual(len(entries), 1, entries)
|
||||
entry = entries[0]
|
||||
|
||||
self.assertEqual(entry.name, b'file.txt')
|
||||
self.assertEqual(entry.path,
|
||||
os.fsencode(os.path.join(self.path, 'file.txt')))
|
||||
self.assertIs(type(entry.name), bytes)
|
||||
self.assertIs(type(entry.path), bytes)
|
||||
|
||||
@unittest.skipUnless(os.listdir in os.supports_fd,
|
||||
'fd support for listdir required for this test.')
|
||||
def test_fd(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue