-
Notifications
You must be signed in to change notification settings - Fork 5
CI: test that runs pdf pack examples in CI #40
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 12 commits
1e2632f
856596e
c379a11
522c561
ac32634
3840f07
f02c948
bce5b86
6d2764e
0ef05db
4d70e15
f1c2ac2
5b27183
d0e17cf
89e89bb
f6ad035
9408042
b2fd64a
666707d
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 |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ | |
|
|
||
| # If we want to run using multiprocessors, we can switch this to 'True'. | ||
| # This requires that the 'psutil' python package installed. | ||
| RUN_PARALLEL = True | ||
| RUN_PARALLEL = False | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires psutil to be installed or it throws an error
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to do this either. Is there a reason not to install psutil? or make it conditional on whether psutil is installed? We don't want to change the behavior of the examples just so the CI will run. |
||
|
|
||
|
|
||
| # Functions that will carry out the refinement ################## | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * Add CI for testing examples of the PDF pack. | ||
|
|
||
| **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,8 +1,12 @@ | ||
| import importlib.util | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| import matplotlib | ||
| import pytest | ||
|
|
||
| __examples_dir__ = Path(__file__).parent.parent / "docs" / "examples" | ||
|
||
|
|
||
|
|
||
| @pytest.fixture | ||
| def user_filesystem(tmp_path): | ||
|
|
@@ -17,3 +21,24 @@ def user_filesystem(tmp_path): | |
| json.dump(home_config_data, f) | ||
|
|
||
| yield tmp_path | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session", autouse=True) | ||
| def use_headless_matplotlib(): | ||
| """Force matplotlib to use a headless backend during tests.""" | ||
| matplotlib.use("Agg") | ||
|
|
||
|
|
||
| def load_module_from_path(path: Path): | ||
| """Load a module given an absolute Path.""" | ||
| spec = importlib.util.spec_from_file_location(path.stem, path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| def run_cmi_script(script_path: Path): | ||
| """General runner for example scripts with a main().""" | ||
| module = load_module_from_path(script_path) | ||
| assert hasattr(module, "main"), f"{script_path} has no main() function" | ||
| module.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from conftest import __examples_dir__, run_cmi_script | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "relative_path", | ||
| [ | ||
| f"{__examples_dir__}/ch03NiModelling" | ||
|
||
| + "/solutions/diffpy-cmi/fitBulkNi.py", | ||
| f"{__examples_dir__}/ch03NiModelling" | ||
| + "/solutions/diffpy-cmi/fitNPPt.py", | ||
| ], | ||
| ) | ||
| def test_ch03_examples(relative_path): | ||
| script_path = Path(__file__).parent.parent / relative_path | ||
| run_cmi_script(script_path) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from conftest import __examples_dir__, run_cmi_script | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "relative_path", | ||
| [ | ||
| f"{__examples_dir__}/ch05Fit2Phase/solutions/diffpy-cmi/fit2P.py", | ||
| ], | ||
| ) | ||
| def test_ch05_examples(relative_path): | ||
| script_path = Path(__file__).parent.parent / relative_path | ||
| run_cmi_script(script_path) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from conftest import __examples_dir__, run_cmi_script | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "relative_path", | ||
| [ | ||
| f"{__examples_dir__}/ch06RefineCrystalStructureGen" | ||
| + "/solutions/diffpy-cmi/fitCrystalGen.py", | ||
| ], | ||
| ) | ||
| def test_ch06_examples(relative_path): | ||
| script_path = Path(__file__).parent.parent / relative_path | ||
| run_cmi_script(script_path) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from conftest import __examples_dir__, run_cmi_script | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "relative_path", | ||
| [ | ||
| f"{__examples_dir__}/ch07StructuralPhaseTransitions" | ||
| + "/solutions/diffpy-cmi/fitTSeries.py", | ||
| ], | ||
| ) | ||
| def test_ch07_examples(relative_path): | ||
| script_path = Path(__file__).parent.parent / relative_path | ||
| run_cmi_script(script_path) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from conftest import __examples_dir__, run_cmi_script | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "relative_path", | ||
| [ | ||
| f"{__examples_dir__}/ch08NPRefinement" | ||
| + "/solutions/diffpy-cmi/fitCdSeNP.py", | ||
| ], | ||
| ) | ||
| def test_ch08_examples(relative_path): | ||
| script_path = Path(__file__).parent.parent / relative_path | ||
| run_cmi_script(script_path) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from conftest import __examples_dir__, run_cmi_script | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "relative_path", | ||
| [ | ||
| f"{__examples_dir__}/ch11ClusterXYZ/solutions/diffpy-cmi/fitCdSeNP.py", | ||
| ], | ||
| ) | ||
| def test_ch11_examples(relative_path): | ||
| script_path = Path(__file__).parent.parent / relative_path | ||
| run_cmi_script(script_path) |
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.
The examples create these dirs. This prevents any accidental commits of the data
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 is not good. This is precisely what we want to avoid (test-generated junk). How do the examples decide where to write these files? Can you copy the files to tmpdir and then run them?