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):
40
40
41
41
42
42
@contextlib .contextmanager
43
- def _tempfile (reader ):
43
+ def _tempfile (reader , suffix = '' ):
44
44
# Not using tempfile.NamedTemporaryFile as it leads to deeper 'try'
45
45
# blocks due to the need to close the temporary file to work on Windows
46
46
# properly.
47
- fd , raw_path = tempfile .mkstemp ()
47
+ fd , raw_path = tempfile .mkstemp (suffix = suffix )
48
48
try :
49
49
os .write (fd , reader ())
50
50
os .close (fd )
@@ -63,7 +63,7 @@ def as_file(path):
63
63
Given a Traversable object, return that object as a
64
64
path on the local file system in a context manager.
65
65
"""
66
- with _tempfile (path .read_bytes ) as local :
66
+ with _tempfile (path .read_bytes , suffix = path . name ) as local :
67
67
yield local
68
68
69
69
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ def _path_from_reader(reader, resource):
161
161
yield Path (reader .resource_path (norm_resource ))
162
162
return
163
163
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 :
165
165
yield res
166
166
167
167
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ def test_reading(self):
19
19
# Test also implicitly verifies the returned object is a pathlib.Path
20
20
# instance.
21
21
with resources .path (self .data , 'utf-8.file' ) as path :
22
+ self .assertTrue (path .name .endswith ("utf-8.file" ), repr (path ))
22
23
# pathlib.Path.read_text() was introduced in Python 3.5.
23
24
with path .open ('r' , encoding = 'utf-8' ) as file :
24
25
text = file .read ()
You can’t perform that action at this time.
0 commit comments