summaryrefslogtreecommitdiff
path: root/Lib/test/test_fileinput.py
diff options
context:
space:
mode:
authorRoy Williams <roy.williams.iii@gmail.com>2017-05-22 22:24:17 -0700
committerƁukasz Langa <lukasz@langa.pl>2017-05-22 22:24:17 -0700
commit002665a9da3a2924c4a08511ede62ff4d1dabc48 (patch)
tree1b8d492d97e6251d2c9b84b0433e594985e5a88c /Lib/test/test_fileinput.py
parentd618c8c6d31b9b288f8a070417683974eb98e3ba (diff)
downloadcpython-git-002665a9da3a2924c4a08511ede62ff4d1dabc48.tar.gz
bpo-30432: FileInput doesn't accept PathLike objects for file names (#1732)
* Allow FileInput to accept a single PathLike object as a parameter for `files` Fixes bpo-30432: FileInput doesn't accept PathLike objects for file names * Address comments from @ambv
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r--Lib/test/test_fileinput.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
index 565633fccc..5df810c8f9 100644
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -21,6 +21,7 @@ except ImportError:
from io import BytesIO, StringIO
from fileinput import FileInput, hook_encoded
+from pathlib import Path
from test.support import verbose, TESTFN, check_warnings
from test.support import unlink as safe_unlink
@@ -530,6 +531,20 @@ class FileInputTests(unittest.TestCase):
self.assertRaises(StopIteration, next, fi)
self.assertEqual(src.linesread, [])
+ def test_pathlib_file(self):
+ t1 = None
+ try:
+ t1 = Path(writeTmp(1, ["Pathlib file."]))
+ with FileInput(t1) as fi:
+ line = fi.readline()
+ self.assertEqual(line, 'Pathlib file.')
+ self.assertEqual(fi.lineno(), 1)
+ self.assertEqual(fi.filelineno(), 1)
+ self.assertEqual(fi.filename(), os.fspath(t1))
+ finally:
+ remove_tempfiles(t1)
+
+
class MockFileInput:
"""A class that mocks out fileinput.FileInput for use during unit tests"""