summaryrefslogtreecommitdiff
path: root/Lib/test/test_posix.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-07-11 06:36:46 +0300
committerGitHub <noreply@github.com>2017-07-11 06:36:46 +0300
commit1180e5a51871fa53ca6892e83fd2e69dc2600447 (patch)
treeb05732085cdc4aa1995c163f32bc7a04927cef7b /Lib/test/test_posix.py
parent4f9a446f3fb42f800e73cd9414dd1eccb3ca4fa7 (diff)
downloadcpython-git-1180e5a51871fa53ca6892e83fd2e69dc2600447.tar.gz
bpo-30879: os.listdir() and os.scandir() now emit bytes names when (#2634)
called with bytes-like argument.
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r--Lib/test/test_posix.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index aa1b0e4463..22b050d4d7 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()")