Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions news/no-subprocess.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* Removed subprocess calls in test functions.
26 changes: 17 additions & 9 deletions tests/test_morphsqueeze.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import subprocess

import numpy as np
import pytest
from numpy.polynomial import Polynomial

from diffpy.morph.morphapp import create_option_parser, single_morph
from diffpy.morph.morphs.morphsqueeze import MorphSqueeze

squeeze_coeffs_dic = [
Expand Down Expand Up @@ -119,7 +118,9 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs):
),
],
)
def test_morphsqueeze_extrapolate(user_filesystem, squeeze_coeffs, wmsg_gen):
def test_morphsqueeze_extrapolate(
user_filesystem, capsys, squeeze_coeffs, wmsg_gen
):
x_morph = np.linspace(0, 10, 101)
y_morph = np.sin(x_morph)
x_target = x_morph
Expand All @@ -143,12 +144,19 @@ def test_morphsqueeze_extrapolate(user_filesystem, squeeze_coeffs, wmsg_gen):
morph_file, target_file = create_morph_data_file(
user_filesystem / "cwd_dir", x_morph, y_morph, x_target, y_target
)
run_cmd = ["diffpy.morph"]
run_cmd.extend(["--squeeze=" + ",".join(map(str, coeffs))])
run_cmd.extend([str(morph_file), str(target_file)])
run_cmd.append("-n")
result = subprocess.run(run_cmd, capture_output=True, text=True)
assert expected_wmsg in result.stderr

parser = create_option_parser()
(opts, pargs) = parser.parse_args(
[
"--squeeze",
",".join(map(str, coeffs)),
f"{morph_file.as_posix()}",
f"{target_file.as_posix()}",
"-n",
]
)
with pytest.warns(UserWarning, match=expected_wmsg):
single_morph(parser, opts, pargs, stdout_flag=False)


def create_morph_data_file(
Expand Down
21 changes: 10 additions & 11 deletions tests/test_refine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from diffpy.morph.morph_helpers.transformpdftordf import TransformXtalPDFtoRDF
from diffpy.morph.morph_helpers.transformrdftopdf import TransformXtalRDFtoPDF
from diffpy.morph.morphapp import create_option_parser, single_morph
from diffpy.morph.morphs.morphchain import MorphChain
from diffpy.morph.morphs.morphfuncx import MorphFuncx
from diffpy.morph.morphs.morphrgrid import MorphRGrid
Expand Down Expand Up @@ -181,7 +182,7 @@ def stretch(x, y, stretch):

assert res < err

def test_refine_grid_bad(self, user_filesystem):
def test_refine_grid_bad(self, user_filesystem, capsys):
grid = numpy.arange(2)
func = numpy.sin(grid)
grid1, func1, grid2, func2 = grid, func, grid, func
Expand All @@ -208,9 +209,7 @@ def test_refine_grid_bad(self, user_filesystem):
actual_error_message = str(error.value)
assert actual_error_message == expected_error_message

# call from command line
import subprocess

# Test from command line
data_dir_path = user_filesystem / "cwd_dir"
morph_file = data_dir_path / "morph_data"
morph_data_text = [
Expand All @@ -224,18 +223,18 @@ def test_refine_grid_bad(self, user_filesystem):
]
target_data_text = "\n".join(target_data_text)
target_file.write_text(target_data_text)
run_cmd = ["diffpy.morph"]
run_cmd = []
for key, value in config.items():
run_cmd.append(f"--{key}")
run_cmd.append(f"{value}")
run_cmd.extend([str(morph_file), str(target_file)])
run_cmd.append("-n")
result = subprocess.run(run_cmd, capture_output=True, text=True)
expected_error_message = (
"diffpy.morph: error: " + expected_error_message
)
actual_error_message = result.stderr.strip()
assert actual_error_message == expected_error_message
parser = create_option_parser()
(opts, pargs) = parser.parse_args(run_cmd)
with pytest.raises(SystemExit):
single_morph(parser, opts, pargs, stdout_flag=False)
_, err = capsys.readouterr()
assert expected_error_message in actual_error_message


# End of class TestRefine
Expand Down
Loading