Skip to content

Commit

Permalink
Merge branch 'main' into parallel_runs_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jthorton authored Jan 29, 2025
2 parents 8552fff + e45b34e commit 7081d12
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
80 changes: 33 additions & 47 deletions openfecli/tests/commands/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import pytest
import pooch
from ..utils import assert_click_success

from openfecli.commands.gather import (
gather, format_estimate_uncertainty, _get_column,
Expand Down Expand Up @@ -135,24 +136,24 @@ def test_get_column(val, col):
"""

@pytest.fixture()
def results_dir_serial(tmpdir):
def results_dir_serial(tmpdir)->str:
"""Example output data, with replicates run in serial (3 replicates per results JSON)."""
with tmpdir.as_cwd():
with resources.files('openfecli.tests.data') as d:
t = tarfile.open(d / 'rbfe_results.tar.gz', mode='r')
t.extractall('.')
tar = tarfile.open(d / 'rbfe_results.tar.gz', mode='r')
tar.extractall('.')

return os.path.abspath(t.getnames()[0])
return os.path.abspath(tar.getnames()[0])

@pytest.fixture()
def results_dir_parallel(tmpdir):
def results_dir_parallel(tmpdir)->str:
"""Example output data, with replicates run in serial (3 replicates per results JSON)."""
with tmpdir.as_cwd():
with resources.files('openfecli.tests.data') as d:
t = tarfile.open(d / 'rbfe_results_parallel.tar.gz', mode='r')
t.extractall('.')
tar = tarfile.open(d / 'rbfe_results_parallel.tar.gz', mode='r')
tar.extractall('.')

return os.path.abspath(t.getnames()[0])
return os.path.abspath(tar.getnames()[0])

@pytest.mark.parametrize('data_fixture', ['results_dir_serial', 'results_dir_parallel'])
@pytest.mark.parametrize('report', ["", "dg", "ddg", "raw"])
Expand Down Expand Up @@ -194,54 +195,39 @@ def test_generate_bad_legs_error_message(include):
for string in expected:
assert string in msg

class TestGatherFailedEdges:
@pytest.fixture()
def results_dir_serial_missing_leg(self, tmpdir)->str:
"""Example output data, with replicates run in serial and one deleted results JSON."""
with tmpdir.as_cwd():
with resources.files('openfecli.tests.data') as d:
tar = tarfile.open(d / 'rbfe_results.tar.gz', mode='r')
tar.extractall('.')

@pytest.mark.xfail
def test_missing_leg_error(results_dir_serial):
file_to_remove = "easy_rbfe_lig_ejm_31_complex_lig_ejm_42_complex.json"
(pathlib.Path("results") / file_to_remove).unlink()
results_dir_path = os.path.abspath(tar.getnames()[0])
file_to_remove = "easy_rbfe_lig_ejm_31_complex_lig_ejm_42_complex.json"
(pathlib.Path(results_dir_path)/ file_to_remove).unlink()
return results_dir_path

runner = CliRunner()
result = runner.invoke(gather, ['results'] + ['-o', '-'])
assert result.exit_code == 1
assert isinstance(result.exception, RuntimeError)
assert "Unable to determine" in str(result.exception)
assert "'lig_ejm_31'" in str(result.exception)
assert "'lig_ejm_42'" in str(result.exception)
def test_missing_leg_error(self, results_dir_serial_missing_leg: str):
runner = CliRunner()
result = runner.invoke(gather, [results_dir_serial_missing_leg] + ['-o', '-'])

assert result.exit_code == 1
assert isinstance(result.exception, RuntimeError)
assert "Unable to determine" in str(result.exception)
assert "'lig_ejm_31'" in str(result.exception)
assert "'lig_ejm_42'" in str(result.exception)

@pytest.mark.xfail
def test_missing_leg_allow_partial(results_dir_serial):
file_to_remove = "easy_rbfe_lig_ejm_31_complex_lig_ejm_42_complex.json"
(pathlib.Path("results") / file_to_remove).unlink()

runner = CliRunner()
result = runner.invoke(gather,
['results'] + ['--allow-partial', '-o', '-'])
assert result.exit_code == 0
def test_missing_leg_allow_partial(self, results_dir_serial_missing_leg: str):
runner = CliRunner()
result = runner.invoke(gather, [results_dir_serial_missing_leg] + ['--allow-partial', '-o', '-'])

assert_click_success(result)

RBFE_RESULTS = pooch.create(
pooch.os_cache('openfe'),
base_url="doi:10.6084/m9.figshare.25148945",
registry={"results.tar.gz": "bf27e728935b31360f95188f41807558156861f6d89b8a47854502a499481da3"},
)


@pytest.fixture
def rbfe_results():
# fetches rbfe results from online
# untars into local directory and returns path to this
d = RBFE_RESULTS.fetch('results.tar.gz', processor=pooch.Untar())

return os.path.join(pooch.os_cache('openfe'), 'results.tar.gz.untar', 'results')


@pytest.mark.download
@pytest.mark.xfail
def test_rbfe_results(rbfe_results):
runner = CliRunner()

result = runner.invoke(gather, ['--report', 'raw', rbfe_results])

assert result.exit_code == 0
assert result.stdout_bytes == _EXPECTED_RAW
15 changes: 15 additions & 0 deletions openfecli/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Helper utilities for CLI tests"""

import click
import traceback


def assert_click_success(result: click.testing.Result): # -no-cov-
"""Pass through error message if a click test fails.
Taken from https://github.com/openpathsampling/openpathsampling-cli/blob/main/paths_cli/commands/pathsampling.py
"""
if result.exit_code != 0:
print(result.output)
traceback.print_tb(result.exc_info[2])
print(result.exc_info[0], result.exc_info[1])
assert result.exit_code == 0

0 comments on commit 7081d12

Please sign in to comment.