-
Notifications
You must be signed in to change notification settings - Fork 2
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
Change tests to use tempfile #338
base: develop
Are you sure you want to change the base?
Conversation
2b6fed4
to
a549525
Compare
@@ -60,10 +62,13 @@ def test_ck_read_write(show_plots): | |||
timeWrite = scObjectLogger.times() | |||
sigmaWrite = scObjectLogger.sigma_BN | |||
omegaWrite = scObjectLogger.omega_BN_B | |||
pyswice_ck_utilities.ckWrite("test.bc", timeWrite, sigmaWrite, omegaWrite, timeInit, spacecraft_id=-202) | |||
|
|||
tempDirectory = tempfile.TemporaryDirectory() |
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.
We should either call .cleanup()
on this object at some point, or -- and more preferably -- use it in a with
block to ensure proper cleanup automatically.
shutil.rmtree(dirName) | ||
assert not os.path.exists(dirName), "No leftover data should exist after the test" | ||
# shutil.rmtree(dirName) | ||
tempDirectory.cleanup() |
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.
It would arguably be better to use a with
statement rather than manually calling .cleanup()
, especially in case an exception occurs (meaning the directory would not actually get cleaned up promptly).
Of course, if any native C or C++ code causes a SIGSEGV or SIGABRT, cleanup wouldn't happen even in a with
block`; but those signals would indicate severe bugs unto themselves!
Description
Tests shouldn't be creating directories in the source tree. Rather we should use managed contexts that manage temporary files and directories.
Verification
CI test run unchanged.
Documentation
NA
Future work
NA