diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_os.py | 16 | ||||
-rw-r--r-- | Lib/test/test_posix.py | 14 |
2 files changed, 27 insertions, 3 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 49e5a37..5ff18ce 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -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): diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index aa1b0e4..22b050d 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -643,17 +643,25 @@ class PosixTester(unittest.TestCase): self.assertRaises(OSError, posix.chdir, support.TESTFN) def test_listdir(self): - self.assertTrue(support.TESTFN in posix.listdir(os.curdir)) + self.assertIn(support.TESTFN, posix.listdir(os.curdir)) def test_listdir_default(self): # When listdir is called without argument, # it's the same as listdir(os.curdir). - self.assertTrue(support.TESTFN in posix.listdir()) + self.assertIn(support.TESTFN, posix.listdir()) def test_listdir_bytes(self): # When listdir is called with a bytes object, # the returned strings are of type bytes. - self.assertTrue(os.fsencode(support.TESTFN) in posix.listdir(b'.')) + self.assertIn(os.fsencode(support.TESTFN), posix.listdir(b'.')) + + def test_listdir_bytes_like(self): + for cls in bytearray, memoryview: + with self.assertWarns(DeprecationWarning): + names = posix.listdir(cls(b'.')) + self.assertIn(os.fsencode(support.TESTFN), names) + for name in names: + self.assertIs(type(name), bytes) @unittest.skipUnless(posix.listdir in os.supports_fd, "test needs fd support for posix.listdir()") |