-
Notifications
You must be signed in to change notification settings - Fork 2
Provide the ability to delete (remove) HDF5 files at the end of integration tests #157
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
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1da8b5c
Modified a few attribute names in the CreateConfigResult data_class t…
3db6558
Added the --remove-hdf5-files option in integrationtest_commandline.p…
45412ae
Added utility_functions.py as a place to provide functions that can b…
9f1696b
Modified integrationtest_drunc.py to start using the latest CreateCon…
54a78fa
Changed the name of a function argument in utility_functions::remove_…
c9f0c0f
modified the --remove-hdf5-files pytest option to allow users to spec…
ca4c635
Added more help text to a couple of our custom pytest options
a7b9ea1
Merge remote-tracking branch 'origin/develop' into kbiery/hdf5_remova…
4f7846e
Added 'always' and 'never' choices to the --remove-hdf5-files pytest …
bcb238a
Merge remote-tracking branch 'origin/develop' into kbiery/hdf5_remova…
66b6aad
Re-worked the functionality that removes HDF5 files at the end of an …
377b56a
Created a function to delete a file and catch exceptions while doing …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import pytest | ||
| import os | ||
| import re | ||
| from integrationtest.verbosity_helper import IntegtestVerbosityLevels | ||
|
|
||
| import functools | ||
| print = functools.partial(print, flush=True) # always flush print() output | ||
|
|
||
| def basic_checks(run_dunerc, caplog, print_test_name: bool = True): | ||
|
|
||
| # print out the name of the current test, if requested | ||
| if print_test_name and run_dunerc.verbosity_helper.compare_level(IntegtestVerbosityLevels.drunc_transitions): | ||
| # print the name of the current test | ||
| current_test = os.environ.get("PYTEST_CURRENT_TEST") | ||
| match_obj = re.search(r".*\[(.+)-run_.*rc.*\d].*", current_test) | ||
| if match_obj: | ||
| current_test = match_obj.group(1) | ||
| banner_line = re.sub(".", "=", current_test) | ||
| print(banner_line) | ||
| print(current_test) | ||
| print(banner_line) | ||
|
|
||
| # Check that dunerc completed correctly | ||
| if run_dunerc.completed_process.returncode != 0: | ||
| fail_msg = f"The run control session returned a non-zero status code ({run_dunerc.completed_process.returncode})." | ||
| pytest.fail(fail_msg, pytrace=False) | ||
|
|
||
| # Check that there weren't any warnings or errors during setup | ||
| setup_logs = caplog.get_records("setup") | ||
| if len(setup_logs) > 0: | ||
| fail_msg = f"One or more problems were encountered during the setup of the pytest: {setup_logs}" | ||
| pytest.fail(fail_msg, pytrace=False) | ||
|
|
||
|
|
||
| def remove_hdf5_files_if_requested(run_dunerc, this_test_requests_hdf5_file_removal: bool = False): | ||
|
|
||
| # if the user requested that the files should be kept, we can simply exit early | ||
| if (run_dunerc.user_requests_hdf5_file_removal is not None and | ||
| ("false" in run_dunerc.user_requests_hdf5_file_removal.lower() or | ||
| "never" in run_dunerc.user_requests_hdf5_file_removal.lower())): | ||
| return | ||
|
|
||
| # if either of the integtest writer or the user running the test requested that the HDF5 files | ||
| # be deleted at the end of the test, do that. | ||
| if ((run_dunerc.user_requests_hdf5_file_removal is not None and | ||
| ("true" in run_dunerc.user_requests_hdf5_file_removal.lower() or | ||
| "always" in run_dunerc.user_requests_hdf5_file_removal.lower())) or | ||
| this_test_requests_hdf5_file_removal): | ||
| pathlist_string = "" | ||
| filelist_string = "" | ||
| for data_file in run_dunerc.data_files: | ||
| filelist_string += " " + str(data_file) | ||
| if str(data_file.parent) not in pathlist_string: | ||
| pathlist_string += " " + str(data_file.parent) | ||
| for data_file in run_dunerc.tpset_files: | ||
| filelist_string += " " + str(data_file) | ||
| if str(data_file.parent) not in pathlist_string: | ||
| pathlist_string += " " + str(data_file.parent) | ||
| for data_file in run_dunerc.trmon_files: | ||
| filelist_string += " " + str(data_file) | ||
| if str(data_file.parent) not in pathlist_string: | ||
| pathlist_string += " " + str(data_file.parent) | ||
|
|
||
| if pathlist_string and filelist_string: | ||
| if run_dunerc.verbosity_helper.compare_level(IntegtestVerbosityLevels.integtest_debug): | ||
| print("============================================") | ||
| print("Listing the hdf5 files before deleting them:") | ||
| print("============================================") | ||
|
|
||
| os.system(f"df -h {pathlist_string}") | ||
| print("--------------------") | ||
| os.system(f"ls -alF {filelist_string}") | ||
|
|
||
| for data_file in run_dunerc.data_files: | ||
| data_file.unlink() | ||
| for data_file in run_dunerc.tpset_files: | ||
| data_file.unlink() | ||
| for data_file in run_dunerc.trmon_files: | ||
| data_file.unlink() | ||
|
|
||
| if run_dunerc.verbosity_helper.compare_level(IntegtestVerbosityLevels.integtest_debug): | ||
| print("--------------------") | ||
| os.system(f"df -h {pathlist_string}") | ||
| print("============================================") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we want a helper function that catches common errors and prints nicer messages?