- 
                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
Changes from 13 commits
c58bb59
              7cb8a66
              86d91e8
              c8883e8
              199630b
              b40a87f
              c7b94c4
              9490394
              e3d5cff
              5a1091a
              ba6825a
              eb8cab3
              b77fb30
              9b7c4c2
              b8822b2
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|  | ||
| * Add tests that run PDF example scripts | ||
|  | ||
| **Changed:** | ||
|  | ||
| * <news item> | ||
|  | ||
| **Deprecated:** | ||
|  | ||
| * <news item> | ||
|  | ||
| **Removed:** | ||
|  | ||
| * <news item> | ||
|  | ||
| **Fixed:** | ||
|  | ||
| * <news item> | ||
|  | ||
| **Security:** | ||
|  | ||
| * <news item> | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| ipywidgets | ||
| matplotlib | ||
| ipympl | ||
| bg-mpl-stylesheets | ||
| py3dmol>=2.0.1 | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -8,3 +8,5 @@ pytest-env | |
| pytest-mock | ||
| freezegun | ||
| DeepDiff | ||
| psutil | ||
| bg-mpl-stylesheets | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +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): | ||
| """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)}") | ||
| mod_globals = {"QDAMP_I": qdamp_i, "QBROAD_I": qbroad_i} | ||
| runpy.run_path( | ||
| str(script_path), run_name="__main__", init_globals=mod_globals | ||
| ) | ||
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.
where is the group style added back in?
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 I will have to add it to each file I think, I can do this!
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.
better on another PR, but can we also do this work on the examples scripts also? Not just the solutions?
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 Yeah I can do this. Do you want me to revert back then?