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

create and delete temporary directory using unittest methods #1132

Merged
merged 7 commits into from
Feb 25, 2020

Conversation

oskooi
Copy link
Collaborator

@oskooi oskooi commented Feb 20, 2020

#1121 involved creating and deleting a temporary directory directly within the __main__ function. However, certain interpreters have script scope enforcement and do not allow the temp_dir directory name to be used outside of the __main__ function leading to an error. Also, on certain systems, os.removedirs cannot delete non-empty directories and aborts with an error.

This PR moves the creation of the temporary directory to within the setUpClass method of the unittest mechanism and stores the directory name as a member of the cls object. The directory deletion is moved to the tearDownClass method and os.removedirs is replaced with meep.delete_output_directory which can force the deletion of a non-empty directory and has a built-in all_wait() to prevent race conditions.

All the tests from #1121 have been updated with these changes.

def tearDown(self):
mp.all_wait()
if mp.am_master():
shutil.rmtree(self.temp_dir,ignore_errors=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can just do mp.delete_directory(self.temp_dir) now

Copy link
Collaborator

Choose a reason for hiding this comment

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

(need a rebase first)

@oskooi oskooi force-pushed the setup_teardown_python_tmpdir branch from 2ec78de to 4de4ba4 Compare February 25, 2020 02:26
@oskooi
Copy link
Collaborator Author

oskooi commented Feb 25, 2020

This is ready to be merged. Afterwards, it would be good to do a 1.13.1 tagged release.

@stevengj stevengj merged commit 1ddec1e into NanoComp:master Feb 25, 2020
@oskooi oskooi deleted the setup_teardown_python_tmpdir branch February 25, 2020 18:20
@stevengj
Copy link
Collaborator

Merged and tagged.

bencbartlett pushed a commit to bencbartlett/meep that referenced this pull request Sep 9, 2021
…p#1132)

* create and delete temporary directory inside unittest methods

* fixes

* put meep.all_wait before rmtree to prevent race condition

* put all_wait before delete_directory in h5test to prevent race condition

* replace shutil.rmtree with meep.delete_directory

* replace setUp/tearDown with setUpClass/tearDownClass

* decorate setUpClass/tearDownClass with classmethod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants