Kyle Roberts added the comment:
Thanks for the comments Antoine. I didn't have a good reason for using the file
name at the time, although even when using the file name I should have used the
file variable that was already created. I tried using the file descriptor,
but I encountered a [Errno
R. David Murray added the comment:
Personally I prefer having the test create the needed test file, rather than
adding a new file to the repository, for small files. That's just my opinion,
though; as you found what you did is common practice currently. Your patch
doesn't include the file,
Kyle Roberts added the comment:
Thanks for the quick response. The test file is sandwiched in between the two
patch files, so it's easy to miss. You made a great point about not cluttering
up the repo with any unnecessary files. I'll change the test methods to create
a new copy_from file
R. David Murray added the comment:
I did miss it. Not that it matters if you are going to rewrite the test, but
FYI you can include new files in a patch by adding them ('hg add') before doing
the 'hg diff' to generate the patch.
--
___
Python
Kyle Roberts added the comment:
Very cool, I didn't think it'd be included in the patch for some reason. Thanks!
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17673
___
Antoine Pitrou added the comment:
Some comments about the patch:
- unless I'm missing something, I think you should re-use the fd instead of
reopening the file by name
- it would be nice if copy_from accepted an open file-like object, e.g. a
BytesIO instance
- I don't think you need a specific
Kyle Roberts added the comment:
Attached is a patch to include the copy_from argument in mkstemp,
TemporaryFile, and NamedTemporaryFile. Also attached is a text file for testing
the copy operation.
Some notes:
I intended to use shutil's copyfile(src, dst) method to copy the copy_from file
Changes by Kyle Roberts roberts...@gmail.com:
Added file: http://bugs.python.org/file29896/copy_from_test.txt
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17673
___
Kyle Roberts added the comment:
Sorry, disregard my second question about finding a test file. I found an
example in test_mailcap.py. I've uploaded a new patch with the cleaner test
functions.
--
Added file: http://bugs.python.org/file29897/copy_from_v2.patch
Kyle Roberts added the comment:
I think `copy_from` should be included for mkstemp as well. It provides similar
functionality to TemporaryFile and NamedTemporaryFile, but it doesn't delete
the temp file on close as the other two do by default. Thoughts?
--
Kyle Roberts added the comment:
I'm working on a patch for this.
--
nosy: +kyle.roberts
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17673
___
New submission from Antoine Pitrou:
It is sometimes useful to create a temporary file as a copy of an existing file
(especially e.g. in tests, when you want to mutate the temp file but not the
original). I would suggest adding a `copy_from` argument to TemporaryFile and
NamedTemporaryFile,
12 matches
Mail list logo