Skip to content

895 Update temp directory function in all tests and examples #899

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

Merged
merged 6 commits into from
Aug 13, 2020
Merged

895 Update temp directory function in all tests and examples #899

merged 6 commits into from
Aug 13, 2020

Conversation

Nic-Ma
Copy link
Contributor

@Nic-Ma Nic-Ma commented Aug 13, 2020

Fixes #895 .

Description

This PR updated the tempfile usage in all the tests and examples according to @ericspod 's suggestion.
I didn't change the usage in integration tests because it's used as a class member and didn't change the usage in all the notebooks because it's hard to use "with ... as ... :" in notebooks.

And I also fixed several missing "delete" issue for temp directory in tests, thanks for @ericspod 's suggestion, tempfile.TemporaryDirectory is really better to avoid errors.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh --codeformat --coverage.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Aug 13, 2020

/black

1 similar comment
@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Aug 13, 2020

/black

@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Aug 13, 2020

/black

@Nic-Ma Nic-Ma changed the title [WIP] 895 Update temp directory function in all tests and examples 895 Update temp directory function in all tests and examples Aug 13, 2020
@Nic-Ma Nic-Ma marked this pull request as ready for review August 13, 2020 08:16
@ericspod
Copy link
Member

I'm good with this, does anyone have any other input @wyli @atbenmurray ?

@wyli
Copy link
Contributor

wyli commented Aug 13, 2020

this was changed back and forth @Nic-Ma and now I can't remember why we did those, e.g.
#446
10203f3

@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Aug 13, 2020

Hi @wyli ,

The previous 2 PRs were:

  1. At the beginning, only few tests used tempdir and others used current dir, so the first PR is to use tempdir for all.
  2. The second PR is because I thought with tempfile.TemporaryDirectory() as tempdir: is using system /tmp/ folder, so I used tempfile. mkdtemp() to replace them, which is not correct.

Now thanks for @ericspod 's suggestion, with tempfile.TemporaryDirectory() as tempdir: actually creates a temp dir and good for our cases, I think it's much more clear now.

Thanks.

Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sounds good, I only have a minor comment about the style

print(f"generating synthetic data to {tempdir} (this may take a while)")
for i in range(5):
im, seg = create_test_image_3d(128, 128, 128, num_seg_classes=1)
with tempfile.TemporaryDirectory() as tempdir:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid this large block of indentation by adding the context from outside of main, something like:

 if __name__ == "__main__":
    with tempfile.TemporaryDirectory() as tempdir:
        main(tempdir)

Copy link
Contributor Author

@Nic-Ma Nic-Ma Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I will change the examples soon.
Thanks.

@ericspod ericspod merged commit 57f8dbf into Project-MONAI:master Aug 13, 2020
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.

Update all tests to use tempfile.TemporaryDirectory
4 participants