File size: 3,337 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
109
110
111
112
from folding_studio.cli import app
from folding_studio.query import ProtenixQuery
from typer.testing import CliRunner

runner = CliRunner()


def test_protenix_predict_with_invalid_file(tmp_files):
    """Running the command with an unsupported file type should return an error."""
    result = runner.invoke(
        app,
        [
            "predict",
            "protenix",
            str(tmp_files["invalid_source"]),
            "--project-code",
            "TEST_PROJECT",
            "--output",
            tmp_files["output_dir"],
        ],
    )
    assert result.exit_code != 0


def test_protenix_predict_with_valid_fasta_file(
    mock_send_request, mock_download_results, tmp_files
):
    """
    Running the command with a valid FASTA file should
    process successfully and generate the correct payload.
    """
    result = runner.invoke(
        app,
        [
            "predict",
            "protenix",
            str(tmp_files["monomer_fasta"]),
            "--project-code",
            "TEST_PROJECT",
            "--output",
            tmp_files["output_dir"],
            "--seed",
            42,
        ],
    )
    assert result.exit_code == 0, result.output

    # Create the expected query using the same parameters as defaults.
    expected_query = ProtenixQuery.from_file(tmp_files["monomer_fasta"], seed=42)
    mock_send_request.assert_called_once()
    actual_query = mock_send_request.call_args[0][0]
    # Compare payload keys
    payload = actual_query.payload
    expected = expected_query.payload
    assert payload["fasta_files"] == expected["fasta_files"]
    assert payload["use_msa_server"] == expected["use_msa_server"]
    assert payload["seeds"] == expected["seeds"]

    mock_download_results.assert_called_once()


def test_protenix_predict_with_valid_fasta_directory(
    mock_send_request, mock_download_results, tmp_files
):
    """
    Running the command with a directory containing valid FASTA files should
    process successfully and combine all FASTA files into the payload.
    """
    result = runner.invoke(
        app,
        [
            "predict",
            "protenix",
            str(tmp_files["valid_dir"]),
            "--project-code",
            "TEST_PROJECT",
            "--output",
            tmp_files["output_dir"],
        ],
    )
    assert result.exit_code == 0, result.output

    expected_query = ProtenixQuery.from_directory(tmp_files["valid_dir"])
    mock_send_request.assert_called_once()
    actual_query = mock_send_request.call_args[0][0]
    payload = actual_query.payload
    expected = expected_query.payload
    # For directories, the fasta_files dictionary should contain an entry for each FASTA file.
    assert payload["fasta_files"] == expected["fasta_files"]

    mock_download_results.assert_called_once()


def test_proteinx_predict_with_empty_directory(tmp_files):
    """
    Running the command with an empty directory should return an error,
    since no FASTA files are available.
    """
    result = runner.invoke(
        app,
        [
            "protenix",
            "predict",
            str(tmp_files["empty_dir"]),
            "--project-code",
            "TEST_PROJECT",
            "--output",
            tmp_files["output_dir"],
        ],
    )
    assert result.exit_code != 0, result.output