Skip to content
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ __pycache__/
# C extensions
*.so

# ignore any data saved by the diffpy.cmi examples
docs/examples/ch*/solutions/diffpy-cmi/fig/*
docs/examples/ch*/solutions/diffpy-cmi/fit/*
docs/examples/ch*/solutions/diffpy-cmi/res/*

Copy link
Contributor Author

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

Copy link
Contributor

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?

# Distribution / packaging
.Python
env/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Requires psutil to be installed or it throws an error

Copy link
Contributor

Choose a reason for hiding this comment

The 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 ##################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ def plot_results(recipe, figname):
diff = g - gcalc + diffzero

mpl.rcParams.update(mpl.rcParamsDefault)
plt.style.use(
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
)

fig, ax1 = plt.subplots(1, 1)

Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Despite its utility, PDF fitting and analysis can be challenging.
The process of understand PDFs requires time, care, and the development of intuition to connect structural models to experimental data.
Hopefully by the end of this tutorial series, PDF fitting will go from being a mysterious black box to a powerful tool in your structural analysis.

Example usage of ``diffpy.cmi`` can be found at `this GitHub repo <https://github.com/diffpy/pdfttp_data>`_.
Example usage of ``diffpy.cmi`` can be found at `this GitHub repo <https://github.com/Billingegroup/pdfttp_data>`_.

.. _structural-parameters:

Expand Down
23 changes: 23 additions & 0 deletions news/test-tutorial-CI.rst
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>
25 changes: 25 additions & 0 deletions tests/conftest.py
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

we may want to cd to tmpdir copy over the examples something like that.



@pytest.fixture
def user_filesystem(tmp_path):
Expand All @@ -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()
18 changes: 18 additions & 0 deletions tests/test_ch03.py
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

please use our pattern if you can that has a comment that mentions what is being tested and what the expected behavior is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

+ "/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)
15 changes: 15 additions & 0 deletions tests/test_ch05.py
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)
16 changes: 16 additions & 0 deletions tests/test_ch06.py
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)
16 changes: 16 additions & 0 deletions tests/test_ch07.py
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)
16 changes: 16 additions & 0 deletions tests/test_ch08.py
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)
15 changes: 15 additions & 0 deletions tests/test_ch11.py
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)
Loading