-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TST: Use tempfiles in all tests. #5425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Includes @jreback's commits from pandas-dev#5422 and hdf_temp: * TST: make pytables tests go thru a temporary dir and file * TST/BUG: incorrect way of testing for r+ modes TST: fix temporary files by using mktemp (rather than mkstemp) which opens them
Why don't we just not use ensure_clean for hdf? Already has a custom |
don't actually use the ensure_clean very much, just a couple of time, it DOES have a custom one (that generates stores).....anyway fixed already |
@jtratner ok now? |
""" | ||
create a temporary file. the caller is responsible for deleting the file | ||
""" | ||
return tempfile.mktemp(suffix=filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, you can't do this because it's deprecated, let's keep tempfile.mkstemp() in ensure_clean, and then move this create_temp_file
function to pandas/io/tests/test_pytables.py with a note that the insecure version is required because of compatibility issues with hdf.
From the docs for Python 3:
tempfile.mktemp(suffix='', prefix='tmp', dir=None)
Deprecated since version 2.3: Use mkstemp() instead.
Return an absolute pathname of a file that did not exist at the time the call is made. The prefix, suffix, and dir arguments are the same as for mkstemp().
Warning Use of this function may introduce a security hole in your program. By the time you get around to doing anything with the file name it returns, someone else may have beaten you to the punch. mktemp() usage can be replaced easily with NamedTemporaryFile(), passing it the delete=False parameter:
>>> f = NamedTemporaryFile(delete=False)
>>> f
<open file '<fdopen>', mode 'w+b' at 0x384698>
>>> f.name
'/var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/tmpG7V1Y0'
>>> f.write("Hello World!\n")
>>> f.close()
>>> os.unlink(f.name)
>>> os.path.exists(f.name)
False
Not a huge deal for a test suite but we may as well avoid using deprecated/insecure files where we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's just dumb, ok....i'll change it back and use a private one for hdf....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, somewhat dumb...but principled maybe? :P
Seems like it only fails for pytables, so may as well just special case it.
…y w/o opening a named temporary file TST: named temporary file creation back to mkstemp in utils/testing.py/ensure_clean
@jtratner ok? |
|
||
try: | ||
filename = tempfile.mkstemp(suffix=filename)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call putting this within the try/finally.
Yes, nice and principled :) |
TST: Use tempfiles in all tests.
related #5419
Includes @jreback's commits from #5422 and hdf_temp:
TST: fix temporary files by using mktemp (rather than mkstemp) which opens them