Skip to content
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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

patkenneally
Copy link
Collaborator

@patkenneally patkenneally commented Sep 24, 2024

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

@@ -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()
Copy link
Collaborator

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()
Copy link
Collaborator

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants