-
Notifications
You must be signed in to change notification settings - Fork 5
test: Run tutorials in tests #45
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 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c58bb59
simon template for examples testing
sbillinge 7cb8a66
add psutils to tests.txt
cadenmyers13 86d91e8
condition that sets qdamp and qbroad if Ni fit is not ran
cadenmyers13 c8883e8
change mpl backend and remove old stylesheets
cadenmyers13 199630b
news
cadenmyers13 b40a87f
Remove comment from tests/conftest.py
cadenmyers13 c7b94c4
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] 9490394
fix typo in psutil name
cadenmyers13 e3d5cff
fix typo in psutil name
cadenmyers13 5a1091a
Add special handling to get Qdamp and Qbroad params
cadenmyers13 ba6825a
add bg stylesheets
cadenmyers13 eb8cab3
add bg stylesheets to requirments
cadenmyers13 b77fb30
remove mpl defaults override
cadenmyers13 9b7c4c2
fix so fitbulkni runs first
cadenmyers13 b8822b2
remove posix
cadenmyers13 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,43 @@ | ||
| import re | ||
| import runpy | ||
|
|
||
|
|
||
| def get_instrument_params(res_file): | ||
| """Parse Qdamp and Qbroad from a .res file.""" | ||
| qdamp = qbroad = None | ||
| with open(res_file, "r") as f: | ||
| for line in f: | ||
| if line.startswith("Calib_Qbroad"): | ||
| qbroad = float(re.split(r"\s+", line.strip())[1]) | ||
| elif line.startswith("Calib_Qdamp"): | ||
| qdamp = float(re.split(r"\s+", line.strip())[1]) | ||
| return qdamp, qbroad | ||
|
|
||
|
|
||
| def test_all_examples(tmp_examples): | ||
| scripts = list(tmp_examples.rglob("**/solutions/diffpy-cmi/*.py")) | ||
| """Run all example scripts to ensure they execute without error.""" | ||
| # Run Ni example first to produce .res file | ||
| ni_script = list(tmp_examples.rglob("**/FitBulkNi.py"))[0] | ||
| runpy.run_path(str(ni_script), run_name="__main__") | ||
| res_file = ni_script.parent / "res" / "Fit_Ni_Bulk.res" | ||
| assert res_file.exists(), f"Ni results file not found: {res_file}" | ||
|
|
||
| qdamp_i, qbroad_i = get_instrument_params(res_file) | ||
| pt_script = list(tmp_examples.rglob("**/fitNPPt.py"))[0] | ||
| refined_Ni_params = {"QDAMP_I": qdamp_i, "QBROAD_I": qbroad_i} | ||
| # run the NPPt script with the refined Ni params | ||
| runpy.run_path( | ||
| str(pt_script), run_name="__main__", init_globals=refined_Ni_params | ||
| ) | ||
|
|
||
| # Run all other example scripts, patching the instrument values | ||
| all_scripts = list(tmp_examples.rglob("**/solutions/diffpy-cmi/*.py")) | ||
| scripts = [ | ||
| s for s in all_scripts if s.name not in ("fitBulkNi.py", "fitNPPt.py") | ||
| ] | ||
| for script_path in scripts: | ||
| print(f"Testing {script_path.relative_to(tmp_examples)}") | ||
| runpy.run_path(str(script_path), run_name="__main__") | ||
| mod_globals = {"QDAMP_I": qdamp_i, "QBROAD_I": qbroad_i} | ||
| runpy.run_path( | ||
| str(script_path), run_name="__main__", init_globals=mod_globals | ||
| ) | ||
Oops, something went wrong.
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.
This seems to have turned something beautiful into something very ugly though. I think the figbulkNI runs first anyway so we probably don't need any of this. Do you want to have another crack at it, or should I try and see what I can come up with?
Also why are you recursively globbing a single file? I can see we need to work a bit on your coding skills......
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.
@sbillinge Let me give this another shot. Im just trying to figure out how to pull the results file from the temp dir.