folding-studio-demo / folding-studio /tests /utils /test_input_validation.py
jfaustin's picture
add dockerfile and folding studio cli
44459bb
raw
history blame
3.25 kB
"""Test path helpers."""
from pathlib import Path
import pytest
import typer
from folding_studio.utils.input_validation import (
extract_and_validate_custom_msas,
extract_and_validate_custom_templates,
validate_initial_guess,
)
def test_extract_and_validate_custom_templates_pass(tmp_path: Path):
"""Test extract and validate custom templates pass."""
test_str_paths = [
tmp_path / "template.cif",
tmp_path / "dir_1/template_1.cif",
tmp_path / "dir_1/template_2.cif",
tmp_path / "dir_1/dir_11/template.cif",
tmp_path / "dir_2/template_1.cif",
tmp_path / "dir_2/template_2.cif",
tmp_path / "dir_3/template_1.cif",
tmp_path / "dir_3/template_2.cif",
]
for path in test_str_paths:
path.parent.mkdir(exist_ok=True, parents=True)
path.touch()
test_paths = [
tmp_path / "template.cif",
tmp_path / "dir_1",
tmp_path / "dir_2",
tmp_path / "dir_3/template_1.cif",
]
extracted_paths = extract_and_validate_custom_templates(test_paths)
assert len(extracted_paths) == 6
def test_extract_and_validate_custom_templates_fails_if_unsupported(tmp_path: Path):
"""Test extract and validate custom templates fails if an unsupported files is passed."""
file = tmp_path / "template.txt"
file.touch()
test_paths = [Path(file)]
with pytest.raises(
typer.BadParameter, match=f"The file '{file}' is not supported."
):
extract_and_validate_custom_templates(test_paths)
def test_extract_and_validate_custom_msass_pass(tmp_path: Path):
"""Test extract and validate custom msas pass."""
test_str_paths = [
tmp_path / "msa.sto",
tmp_path / "dir_1/msa_1.sto",
tmp_path / "dir_1/msa_2.a3m",
tmp_path / "dir_1/dir_11/msa.sto",
tmp_path / "dir_2/msa_1.sto",
tmp_path / "dir_2/msa_2.a3m",
tmp_path / "dir_3/msa_1.sto",
tmp_path / "dir_3/msa_2.a3m",
]
for path in test_str_paths:
path.parent.mkdir(exist_ok=True, parents=True)
path.touch()
test_paths = [
tmp_path / "msa.sto",
tmp_path / "dir_1",
tmp_path / "dir_2",
tmp_path / "dir_3/msa_1.sto",
]
extracted_paths = extract_and_validate_custom_msas(test_paths)
assert len(extracted_paths) == 6
def test_extract_and_validate_custom_msas_fails_if_unsupported(tmp_path: Path):
"""Test extract and validate custom msas fails if an unsupported file is passed."""
file = tmp_path / "msa.txt"
file.touch()
test_paths = [Path(file)]
with pytest.raises(
typer.BadParameter, match=f"The file '{file}' is not supported."
):
extract_and_validate_custom_templates(test_paths)
@pytest.mark.parametrize(
("file", "expected_path"),
[
(Path("initial_guess.cif"), Path("initial_guess.cif")),
(Path("dir_1/initial_guess_1.cif"), Path("dir_1/initial_guess_1.cif")),
(None, None),
],
)
def test_extract_and_validate_initial_guess_path(file: str, expected_path):
"""Test extract and validate initial guess file path."""
validated_path = validate_initial_guess(file)
assert validated_path == expected_path