summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tempfile.py
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-09-09 15:54:34 (GMT)
committerZachary Ware <zachary.ware@gmail.com>2019-09-09 15:54:34 (GMT)
commit370138ba9c29595df773cc057d17ea26fb6f21bd (patch)
tree2912100b1674bf408ad0628baf4383c7bd4557ea /Lib/test/test_tempfile.py
parent9488a5289de2ceecdfd2098cd70d215f96c4e745 (diff)
downloadcpython-370138ba9c29595df773cc057d17ea26fb6f21bd.zip
cpython-370138ba9c29595df773cc057d17ea26fb6f21bd.tar.gz
cpython-370138ba9c29595df773cc057d17ea26fb6f21bd.tar.bz2
bpo-35803: Document and test dir=PathLike for tempfile (GH-11644)
Co-Authored-By: Ammar Askar <ammar_askar@hotmail.com>
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r--Lib/test/test_tempfile.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index bd4db83..f995f6c 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -3,6 +3,7 @@ import tempfile
import errno
import io
import os
+import pathlib
import signal
import sys
import re
@@ -56,6 +57,9 @@ class TestLowLevelInternals(unittest.TestCase):
with self.assertRaises(TypeError):
tempfile._infer_return_type(b'', None, '')
+ def test_infer_return_type_pathlib(self):
+ self.assertIs(str, tempfile._infer_return_type(pathlib.Path('/')))
+
# Common functionality.
@@ -79,8 +83,13 @@ class BaseTestCase(unittest.TestCase):
nsuf = nbase[len(nbase)-len(suf):]
if dir is not None:
- self.assertIs(type(name), str if type(dir) is str else bytes,
- "unexpected return type")
+ self.assertIs(
+ type(name),
+ str
+ if type(dir) is str or isinstance(dir, os.PathLike) else
+ bytes,
+ "unexpected return type",
+ )
if pre is not None:
self.assertIs(type(name), str if type(pre) is str else bytes,
"unexpected return type")
@@ -425,6 +434,7 @@ class TestMkstempInner(TestBadTempdir, BaseTestCase):
dir = tempfile.mkdtemp()
try:
self.do_create(dir=dir).write(b"blat")
+ self.do_create(dir=pathlib.Path(dir)).write(b"blat")
finally:
os.rmdir(dir)
@@ -659,6 +669,7 @@ class TestMkstemp(BaseTestCase):
dir = tempfile.mkdtemp()
try:
self.do_create(dir=dir)
+ self.do_create(dir=pathlib.Path(dir))
finally:
os.rmdir(dir)
@@ -728,6 +739,7 @@ class TestMkdtemp(TestBadTempdir, BaseTestCase):
dir = tempfile.mkdtemp()
try:
os.rmdir(self.do_create(dir=dir))
+ os.rmdir(self.do_create(dir=pathlib.Path(dir)))
finally:
os.rmdir(dir)