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
86 changes: 40 additions & 46 deletions openfecli/tests/commands/test_gather.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Callable
from click.testing import CliRunner
from importlib import resources
import tarfile
Expand All @@ -6,10 +7,10 @@
import pytest
import pooch
from ..utils import assert_click_success
from ..conftest import HAS_INTERNET

from openfecli.commands.gather import (
gather, format_estimate_uncertainty, _get_column,
_generate_bad_legs_error_message,
)

@pytest.mark.parametrize('est,unc,unc_prec,est_str,unc_str', [
Expand Down Expand Up @@ -134,30 +135,29 @@ def test_get_column(val, col):
solvent lig_ejm_46 lig_jmc_28 23.3 0.8
solvent lig_ejm_46 lig_jmc_28 23.4 0.8
"""

@pytest.fixture()
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:
tar = tarfile.open(d / 'rbfe_results.tar.gz', mode='r')
tar.extractall('.')

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

@pytest.fixture()
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:
tar = tarfile.open(d / 'rbfe_results_parallel.tar.gz', mode='r')
tar.extractall('.')

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

@pytest.mark.parametrize('data_fixture', ['results_dir_serial', 'results_dir_parallel'])
POOCH_CACHE = pooch.os_cache('openfe')
ZENODO_RBFE_DATA = pooch.create(
path = POOCH_CACHE,
base_url="doi:10.5281/zenodo.14884797",
registry={
"rbfe_results_serial_repeats.tar.gz": "md5:d7c5e04786d03e1280a74639c2981546",
"rbfe_results_parallel_repeats.tar.gz": "md5:cc54afe32b56232339a9315f4c3d6d91"},
)

@pytest.fixture
def rbfe_result_dir()->pathlib.Path:
def _rbfe_result_dir(dataset)->str:
ZENODO_RBFE_DATA.fetch(f'{dataset}.tar.gz', processor=pooch.Untar())
cache_dir = pathlib.Path(pooch.os_cache('openfe'))/f'{dataset}.tar.gz.untar/{dataset}/'
return cache_dir

return _rbfe_result_dir

@pytest.mark.skipif(not os.path.exists(POOCH_CACHE) and not HAS_INTERNET,reason="Internet seems to be unavailable and test data is not cached locally.")
@pytest.mark.parametrize('dataset', ['rbfe_results_serial_repeats', 'rbfe_results_parallel_repeats'])
@pytest.mark.parametrize('report', ["", "dg", "ddg", "raw"])
def test_gather(request, data_fixture, report):
def test_gather(rbfe_result_dir, dataset, report):

expected = {
"": _EXPECTED_DG,
"dg": _EXPECTED_DG,
Expand All @@ -171,30 +171,30 @@ def test_gather(request, data_fixture, report):
else:
args = []

results_dir = request.getfixturevalue(data_fixture)
result = runner.invoke(gather, [results_dir] + args + ['-o', '-'])
results_dir = rbfe_result_dir(dataset)
result = runner.invoke(gather, [str(results_dir)] + args + ['-o', '-'])

assert_click_success(result)

actual_lines = set(result.stdout_bytes.split(b'\n'))
assert set(expected.split(b'\n')) == actual_lines

@pytest.mark.skipif(not os.path.exists(POOCH_CACHE) and not HAS_INTERNET,reason="Internet seems to be unavailable and test data is not cached locally.")
class TestGatherFailedEdges:
@pytest.fixture()
def results_dir_serial_missing_legs(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('.')

results_dir_path = os.path.abspath(tar.getnames()[0])
files_to_remove = ["rbfe_lig_ejm_31_complex_lig_ejm_42_complex.json",
"rbfe_lig_ejm_46_solvent_lig_jmc_28_solvent.json"
]
for fname in files_to_remove:
(pathlib.Path(results_dir_path)/ fname).unlink()
return results_dir_path
def results_dir_serial_missing_legs(self, rbfe_result_dir, tmpdir)->str:
"""Example output data, with replicates run in serial and two missing results JSONs."""
# TODO: update to return a list of paths without doing this symlink mess, when gather supports it.
rbfe_result_dir = rbfe_result_dir('rbfe_results_serial_repeats')
tmp_results_dir = tmpdir
files_to_skip = ["rbfe_lig_ejm_31_complex_lig_ejm_42_complex.json",
"rbfe_lig_ejm_46_solvent_lig_jmc_28_solvent.json"
]
for item in os.listdir(rbfe_result_dir):
if item not in files_to_skip:
os.symlink(rbfe_result_dir/item, tmp_results_dir/item)

return str(tmp_results_dir)

def test_missing_leg_error(self, results_dir_serial_missing_legs: str):
runner = CliRunner()
Expand All @@ -213,9 +213,3 @@ def test_missing_leg_allow_partial(self, results_dir_serial_missing_legs: str):
result = runner.invoke(gather, [results_dir_serial_missing_legs] + ['--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"},
)
Binary file modified openfecli/tests/data/rbfe_results.tar.gz
Copy link
Contributor Author

Choose a reason for hiding this comment

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

see here: https://github.com/OpenFreeEnergy/openfe/pull/1121/files#r1964427513

same data, just correctly(?) compressed.

Binary file not shown.
Binary file removed openfecli/tests/data/rbfe_results_parallel.tar.gz
Binary file not shown.
245 changes: 0 additions & 245 deletions openfecli/tests/data/restructure_results_data.ipynb

This file was deleted.

6 changes: 3 additions & 3 deletions openfecli/tests/test_fetchables.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def fetchable_test(fetchable):
assert (pathlib.Path("output-dir") / path).exists()


def test_rhfe_tutorial():
def test_rbfe_tutorial():
fetchable_test(RBFE_TUTORIAL)

def test_rhfe_tutorial_results():
def test_rbfe_tutorial_results():
fetchable_test(RBFE_TUTORIAL_RESULTS)

def test_rhfe_showcase():
def test_rbfe_showcase():
fetchable_test(RBFE_SHOWCASE)