-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #448 from MannLabs/fix_fasta_in_cli
Fix fasta in cli
- Loading branch information
Showing
3 changed files
with
129 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,119 @@ | ||
#!python -m unittest tests.test_utils | ||
"""This module provides unit tests for alphadia.cli.""" | ||
|
||
# builtin | ||
import unittest | ||
from unittest.mock import MagicMock, mock_open, patch | ||
|
||
# local | ||
import yaml | ||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
from alphadia.cli import _get_config_from_args, _get_from_args_or_config, run | ||
|
||
# TODO add tests for _get_raw_path_list_from_args_and_config | ||
|
||
|
||
def test_get_config_from_args(): | ||
"""Test the _get_config_from_args function correctly merges configs.""" | ||
mock_args = MagicMock(config="config.yaml", config_dict='{"key3": "value3"}') | ||
|
||
yaml_content = {"key1": "value1", "key2": "value2"} | ||
mock_yaml = yaml.dump(yaml_content) | ||
|
||
with patch("builtins.open", mock_open(read_data=mock_yaml)): | ||
result = _get_config_from_args(mock_args) | ||
|
||
assert result == {"key1": "value1", "key2": "value2", "key3": "value3"} | ||
|
||
|
||
def test_get_from_args_or_config_returns_value_from_args(): | ||
"""Test that the function returns the value from the args when it is not None.""" | ||
args = MagicMock(output="cli_output") | ||
config = {"output_directory": "config_output"} | ||
|
||
# when | ||
result = _get_from_args_or_config( | ||
args, config, args_key="output", config_key="output_directory" | ||
) | ||
|
||
assert result == "cli_output" | ||
|
||
|
||
def test_get_from_args_or_config_returns_value_from_config_when_args_none(): | ||
"""Test that the function returns the value from the config when the args value is None.""" | ||
args = MagicMock(output=None) | ||
config = {"output_directory": "config_output"} | ||
|
||
# when | ||
result = _get_from_args_or_config( | ||
args, config, args_key="output", config_key="output_directory" | ||
) | ||
|
||
assert result == "config_output" | ||
|
||
|
||
@patch("alphadia.cli.parser.parse_known_args") | ||
@patch("builtins.print") | ||
@patch("alphadia.cli.SearchPlan") | ||
def test_cli_unknown_args( | ||
mock_search_plan, | ||
mock_print, | ||
mock_parse_known_args, | ||
): | ||
mock_parse_known_args.return_value = (MagicMock, ["unknown_arg"]) | ||
|
||
# when | ||
run() | ||
|
||
mock_print.assert_called_once_with("Unknown arguments: ['unknown_arg']") | ||
mock_search_plan.assert_not_called() | ||
|
||
|
||
@patch("alphadia.cli.parser.parse_known_args") | ||
@patch("alphadia.cli.reporting.init_logging") | ||
@patch("alphadia.cli.SearchPlan") | ||
def test_cli_minimal_args(mock_search_plan, mock_init_logging, mock_parse_known_args): | ||
"""Test the run function of the CLI with minimal arguments maps correctly to SearchPlan.""" | ||
mock_args = MagicMock(config=None, version=None, output="/output") | ||
mock_parse_known_args.return_value = (mock_args, []) | ||
|
||
# when | ||
run() | ||
|
||
mock_search_plan.assert_called_once_with( | ||
"/output", | ||
{}, | ||
{ | ||
# TODO raw_paths missing here | ||
"library_path": mock_args.library, | ||
"fasta_paths": mock_args.fasta, | ||
"quant_directory": mock_args.quant_dir, | ||
}, | ||
) | ||
|
||
mock_init_logging.assert_called_once_with("/output") | ||
|
||
|
||
@patch("alphadia.cli.parser.parse_known_args") | ||
@patch("alphadia.cli.reporting.init_logging") | ||
@patch("alphadia.cli.SearchPlan") | ||
def test_cli_minimal_args_all_none( | ||
mock_search_plan, mock_init_logging, mock_parse_known_args | ||
): | ||
"""Test the run function of the CLI with minimal arguments maps correctly to SearchPlan if nothing given.""" | ||
mock_args = MagicMock( | ||
config=None, | ||
version=None, | ||
output="/output", | ||
fasta=None, | ||
library=None, | ||
quant_dir=None, | ||
) | ||
mock_parse_known_args.return_value = (mock_args, []) | ||
|
||
# when | ||
run() | ||
|
||
mock_search_plan.assert_called_once_with( | ||
"/output", | ||
{}, | ||
{}, | ||
) | ||
|
||
mock_init_logging.assert_called_once_with("/output") |