94 lines
2.1 KiB
Python
94 lines
2.1 KiB
Python
from unittest.mock import patch
|
|
|
|
from tcga_downloader.cli import main
|
|
|
|
|
|
@patch(
|
|
"sys.argv",
|
|
[
|
|
"tcga-downloader",
|
|
"query",
|
|
"--project",
|
|
"TCGA-BRCA",
|
|
"--data-type",
|
|
"Gene Expression",
|
|
"--out",
|
|
"/tmp/m.tsv",
|
|
],
|
|
)
|
|
@patch("tcga_downloader.cli.query_files")
|
|
def test_cli_integration_query_full(mock_query, tmp_path, monkeypatch):
|
|
mock_query.return_value = [
|
|
{
|
|
"file_id": "f1",
|
|
"file_name": "file1.tsv",
|
|
"data_type": "Gene Expression",
|
|
"data_format": "TSV",
|
|
"file_size": 1000,
|
|
"md5sum": "a" * 32,
|
|
}
|
|
]
|
|
|
|
out_path = tmp_path / "m.tsv"
|
|
monkeypatch.setattr(
|
|
"sys.argv",
|
|
[
|
|
"tcga-downloader",
|
|
"query",
|
|
"--project",
|
|
"TCGA-BRCA",
|
|
"--data-type",
|
|
"Gene Expression",
|
|
"--out",
|
|
str(out_path),
|
|
],
|
|
)
|
|
|
|
main()
|
|
|
|
assert out_path.exists()
|
|
assert mock_query.called
|
|
|
|
|
|
@patch("tcga_downloader.cli.run_gdc_download")
|
|
def test_cli_integration_download_with_manifest(mock_download, tmp_path):
|
|
manifest_path = tmp_path / "manifest.tsv"
|
|
manifest_path.write_text("file_id\tfile_name\t...\n")
|
|
|
|
mock_download.return_value = None
|
|
|
|
from unittest.mock import patch as patch2
|
|
from tcga_downloader.cli import main
|
|
|
|
with patch2(
|
|
"sys.argv",
|
|
[
|
|
"tcga-downloader",
|
|
"download",
|
|
"--manifest",
|
|
str(manifest_path),
|
|
"--out-dir",
|
|
str(tmp_path / "data"),
|
|
],
|
|
):
|
|
main()
|
|
|
|
assert mock_download.called
|
|
|
|
|
|
def test_cli_config_init_command(tmp_path):
|
|
config_path = tmp_path / "config.json"
|
|
|
|
from unittest.mock import patch
|
|
from tcga_downloader.cli import main
|
|
from tcga_downloader.config import load_config
|
|
|
|
with patch("sys.argv", ["tcga-downloader", "config", "--init", str(config_path)]):
|
|
main()
|
|
|
|
assert config_path.exists()
|
|
|
|
config = load_config(config_path)
|
|
assert config.query.project == "TCGA-BRCA"
|
|
assert config.query.data_type == "Gene Expression"
|