File size: 3,248 Bytes
44459bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
"""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
|