File tree Expand file tree Collapse file tree 3 files changed +5
-4
lines changed
Expand file tree Collapse file tree 3 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -40,11 +40,11 @@ def fallback_resources(spec):
4040
4141
4242@contextlib .contextmanager
43- def _tempfile (reader ):
43+ def _tempfile (reader , suffix = '' ):
4444 # Not using tempfile.NamedTemporaryFile as it leads to deeper 'try'
4545 # blocks due to the need to close the temporary file to work on Windows
4646 # properly.
47- fd , raw_path = tempfile .mkstemp ()
47+ fd , raw_path = tempfile .mkstemp (suffix = suffix )
4848 try :
4949 os .write (fd , reader ())
5050 os .close (fd )
@@ -63,7 +63,7 @@ def as_file(path):
6363 Given a Traversable object, return that object as a
6464 path on the local file system in a context manager.
6565 """
66- with _tempfile (path .read_bytes ) as local :
66+ with _tempfile (path .read_bytes , suffix = path . name ) as local :
6767 yield local
6868
6969
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ def _path_from_reader(reader, resource):
161161 yield Path (reader .resource_path (norm_resource ))
162162 return
163163 opener_reader = reader .open_resource (norm_resource )
164- with _common ._tempfile (opener_reader .read ) as res :
164+ with _common ._tempfile (opener_reader .read , suffix = norm_resource ) as res :
165165 yield res
166166
167167
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ def test_reading(self):
1919 # Test also implicitly verifies the returned object is a pathlib.Path
2020 # instance.
2121 with resources .path (self .data , 'utf-8.file' ) as path :
22+ self .assertTrue (path .name .endswith ("utf-8.file" ), repr (path ))
2223 # pathlib.Path.read_text() was introduced in Python 3.5.
2324 with path .open ('r' , encoding = 'utf-8' ) as file :
2425 text = file .read ()
You can’t perform that action at this time.
0 commit comments