Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# First we store the absolute directory of this script,
# then two directories above this,with the directory
# 'data' appended
PWD = Path(__file__).parent.absolute()
PWD = Path(__file__).parent.resolve()
DPATH = PWD.parent.parent / "data"

# 3: Give an identifying name for the refinement, similar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@
print("The Ni example refines instrument parameters\n")
print("The instrument parameters are necessary to run this fit\n")
print("Please run the Ni example first\n")

print("Setting Q_damp and Q_broad to the refined values\n")
QDAMP_I = 0.045298
QBROAD_I = 0.016809
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If user doesn't run the bulkNi script, the Qdamp and Qbroad values will be defined here. This is also needed to run tests (for now).

Copy link
Contributor

Choose a reason for hiding this comment

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

let's see if we can fix this properly and not this ugly workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sbillinge To handle this, I had to add special handling for this script. I've pushed said special handling. Let me know if that looks okay.

# If we want to run using multiprocessors, we can switch this to 'True'.
# This requires that the 'psutil' python package installed.
RUN_PARALLEL = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,6 @@ def plot_results(recipe, fig_name):

# Change some style details of the plot
mpl.rcParams.update(mpl.rcParamsDefault)
if (PWD.parent.parent.parent / "utils" / "billinge.mplstyle").exists():
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Contributor

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?

Copy link
Contributor Author

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?

plt.style.use(
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
)

# Create a figure and an axis on which to plot
fig, ax1 = plt.subplots(1, 1)
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
23 changes: 23 additions & 0 deletions news/example-ci.rst
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>
1 change: 1 addition & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pytest-env
pytest-mock
freezegun
DeepDiff
psutil
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
import json
import shutil
from pathlib import Path

import matplotlib
import pytest

PROJECT_ROOT = Path(__file__).resolve().parents[1]
EXAMPLES_ROOT = PROJECT_ROOT / "docs" / "examples"


@pytest.fixture(scope="session")
def tmp_examples(tmp_path_factory):
"""Copy the entire examples/ tree into a temp directory once per
test session.

Returns the path to that copy.
"""
tmpdir = tmp_path_factory.mktemp("examples")
tmp_examples = tmpdir / "examples"
shutil.copytree(EXAMPLES_ROOT, tmp_examples)
yield tmp_examples


@pytest.fixture(scope="session", autouse=True)
def use_headless_matplotlib():
"""Force matplotlib to use a headless backend during tests."""
matplotlib.use("Agg")


@pytest.fixture
def user_filesystem(tmp_path):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import runpy


def test_all_examples(tmp_examples):
scripts = list(tmp_examples.rglob("**/solutions/diffpy-cmi/*.py"))
for script_path in scripts:
print(f"Testing {script_path.relative_to(tmp_examples)}")
runpy.run_path(str(script_path), run_name="__main__")
Loading