diff --git a/tests/cli/workflow/mip/conftest.py b/tests/cli/workflow/mip/conftest.py index 81548dd647..e73869d0c9 100644 --- a/tests/cli/workflow/mip/conftest.py +++ b/tests/cli/workflow/mip/conftest.py @@ -14,7 +14,6 @@ from cg.store.api.find_business_data import FindBusinessDataHandler from cg.store.api.status import StatusHandler from cg.store.models import Case -from tests.store.conftest import case_obj from tests.store_helpers import StoreHelpers @@ -192,3 +191,50 @@ def setup_mocks( mocker.patch.object(FindBusinessDataHandler, "are_all_flow_cells_on_disk") FindBusinessDataHandler.are_all_flow_cells_on_disk.return_value = True + + +@pytest.fixture +def scout_panel_output() -> str: + return """##genome_build=37 +##gene_panel=OMIM-AUTO,version=22.0,updated_at=2023-10-17,display_name=OMIM-AUTO +##gene_panel=PANELAPP-GREEN,version=6.0,updated_at=2023-10-19,display_name=PanelApp Green Genes +##contig=1 +##contig=2 +##contig=3 +##contig=4 +##contig=5 +##contig=6 +##contig=7 +##contig=8 +##contig=9 +##contig=10 +##contig=X +##contig=Y +##contig=MT +#chromosome gene_start gene_stop hgnc_id hgnc_symbol +1 568915 569121 44571 MTATP8P1 +1 860260 879955 28706 SAMD11 +2 162164549 162268228 16889 PSMD14 +2 162272605 162282381 11590 TBR1 +3 120315156 120321347 7699 NDUFB4 +3 120347020 120401418 4892 HGD +4 185570767 185616117 26575 PRIMPOL +4 185676749 185747972 3569 ACSL1 +5 473425 524447 11073 SLC9A3 +5 892758 919472 12307 TRIP13 +6 18224099 18265054 2768 DEK +6 19837617 19840915 5363 ID4 +7 44256749 44374176 1461 CAMK2B +7 44646171 44748665 8124 OGDH +8 22993101 23021543 11907 TNFRSF10D +8 23047965 23082639 11904 TNFRSF10A +9 35099888 35103154 14559 STOML2 +9 35161999 35405335 12566 UNC13B +10 23481256 23483181 23734 PTF1A +10 25305587 25315593 26160 THNSL1 +X 154719776 154899605 18308 TMLHE +X 155110956 155173433 11486 VAMP7 +Y 6778727 6959724 18502 TBL1Y +Y 14813160 14972764 12633 USP9Y +MT 577 647 7481 MT-TF +MT 648 1601 7470 MT-RNR1""" diff --git a/tests/cli/workflow/mip/test_cli_mip_base.py b/tests/cli/workflow/mip/test_cli_mip_base.py index 52c3bf6290..ea1f836ec5 100644 --- a/tests/cli/workflow/mip/test_cli_mip_base.py +++ b/tests/cli/workflow/mip/test_cli_mip_base.py @@ -2,6 +2,7 @@ import logging +import mock from _pytest.logging import LogCaptureFixture from click.testing import CliRunner from pytest_mock import MockFixture @@ -83,7 +84,7 @@ def test_spring_decompression_needed_and_start_failed( assert result.exit_code == 0 # THEN it should be announced that spring decompression is needed but fail to start - assert f"Decompression failed to start for" in caplog.text + assert "Decompression failed to start for" in caplog.text def test_spring_decompression_needed_and_cant_start( @@ -120,7 +121,7 @@ def test_spring_decompression_needed_and_cant_start( assert result.exit_code == 0 # THEN it should be announced that spring decompression is needed but fail to start - assert f"Decompression can not be started for" in caplog.text + assert "Decompression can not be started for" in caplog.text def test_decompression_cant_start_and_is_running( @@ -157,7 +158,7 @@ def test_decompression_cant_start_and_is_running( assert result.exit_code == 0 # THEN it should be announced that spring decompression is needed but fail to start - assert f"Decompression is running for" in caplog.text + assert "Decompression is running for" in caplog.text def test_case_needs_to_be_stored( @@ -188,8 +189,14 @@ def test_case_needs_to_be_stored( mocker=mocker, ) - # WHEN MIP analysis is started - result = cli_runner.invoke(start, [case.internal_id, "--dry-run"], obj=mip_dna_context) + # GIVEN that a panel is returned + with mock.patch.object( + mip_dna_context.scout_api, + "export_panels", + return_value=["OMIM-AUTO"], + ): + # WHEN MIP analysis is started + result = cli_runner.invoke(start, [case.internal_id, "--dry-run"], obj=mip_dna_context) # THEN command should run without errors assert result.exit_code == 0 diff --git a/tests/cli/workflow/mip/test_cli_mip_dna_panel.py b/tests/cli/workflow/mip/test_cli_mip_dna_panel.py index b511a67573..c456cf3f0b 100644 --- a/tests/cli/workflow/mip/test_cli_mip_dna_panel.py +++ b/tests/cli/workflow/mip/test_cli_mip_dna_panel.py @@ -1,15 +1,36 @@ """ Test the CLI for mip-dna panel""" +from pathlib import Path + +import mock +from click.testing import CliRunner from cg.cli.workflow.mip_dna.base import panel +from cg.io.txt import read_txt +from cg.meta.workflow.mip import MipAnalysisAPI +from cg.models.cg_config import CGConfig +from tests.conftest import create_process_response + + +def test_panel_file_is_written( + case_id: str, cli_runner: CliRunner, mip_dna_context: CGConfig, scout_panel_output: str +): + analysis_api: MipAnalysisAPI = mip_dna_context.meta_apis["analysis_api"] + # GIVEN a case -def test_cg_workflow_mip_dna_panel(cli_runner, case_id, mip_dna_context): - """Test print the MIP dna panel command to console""" + # GIVEN that the scout command writes the panel to stdout + with mock.patch( + "cg.utils.commands.subprocess.run", + return_value=create_process_response(std_out=scout_panel_output), + ): + # WHEN creating a panel file + cli_runner.invoke(panel, [case_id], obj=mip_dna_context) - # GIVEN a cli function + panel_file = Path(analysis_api.root, case_id, "gene_panels.bed") - # WHEN we run a case in dry run mode - result = cli_runner.invoke(panel, [case_id], obj=mip_dna_context) + # THEN the file should exist + assert panel_file.exists() - # THEN the command should be printed - assert result.exit_code == 0 + # THEN the file should contain the output from scout + file_content: str = read_txt(file_path=panel_file, read_to_string=True) + assert file_content == scout_panel_output diff --git a/tests/conftest.py b/tests/conftest.py index 95331eec99..47e8ae54ff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ from copy import deepcopy from datetime import MAXYEAR, datetime, timedelta from pathlib import Path +from subprocess import CompletedProcess from typing import Any, Generator, Union import pytest @@ -2400,7 +2401,7 @@ def context_config( "tower_pipeline": "taxprofiler", }, "scout": { - "binary_path": "echo", + "binary_path": "bin/scout", "config_path": "scout-stage.yaml", }, "statina": { @@ -3283,6 +3284,18 @@ def flow_cell_encryption_api( return flow_cell_encryption_api +def create_process_response( + return_code: int = 0, args: str = "", std_out: str = "", std_err: str = "" +) -> CompletedProcess: + """Returns a CompletedProcess object with default parameters.""" + return CompletedProcess( + args=args, + returncode=return_code, + stderr=std_err.encode("utf-8"), + stdout=std_out.encode("utf-8"), + ) + + # Downsample @pytest.fixture() def store_with_case_and_sample_with_reads( diff --git a/tests/meta/backup/conftest.py b/tests/meta/backup/conftest.py index 28ba7463e7..51238d1c0c 100644 --- a/tests/meta/backup/conftest.py +++ b/tests/meta/backup/conftest.py @@ -1,6 +1,5 @@ import fnmatch from pathlib import Path -from subprocess import CompletedProcess from typing import Callable import pytest @@ -73,14 +72,3 @@ def archived_flow_cell() -> Path: def archived_key() -> Path: """Path of archived key""" return Path("/path/to/archived/encryption_key.key.gpg") - - -def create_process_response( - return_code: int, args: str = "", std_out: str = "", std_err: str = "" -) -> CompletedProcess: - return CompletedProcess( - args=args, - returncode=return_code, - stderr=std_err.encode("utf-8"), - stdout=std_out.encode("utf-8"), - ) diff --git a/tests/meta/backup/test_meta_pdc.py b/tests/meta/backup/test_meta_pdc.py index 0ea260c7a0..4e095adbed 100644 --- a/tests/meta/backup/test_meta_pdc.py +++ b/tests/meta/backup/test_meta_pdc.py @@ -17,7 +17,7 @@ from cg.models.cg_config import CGConfig from cg.store import Store from cg.store.models import Flowcell -from tests.meta.backup.conftest import create_process_response +from tests.conftest import create_process_response from tests.store_helpers import StoreHelpers diff --git a/tests/store/api/find/test_find_business_data.py b/tests/store/api/find/test_find_business_data.py index f6fe2076d6..93e2c75f35 100644 --- a/tests/store/api/find/test_find_business_data.py +++ b/tests/store/api/find/test_find_business_data.py @@ -15,9 +15,9 @@ Application, ApplicationLimitations, ApplicationVersion, - Customer, Case, CaseSample, + Customer, Flowcell, Invoice, Pool, @@ -286,10 +286,10 @@ def test_are_all_flow_cells_on_disk_when_requested( case_id: str, helpers: StoreHelpers, sample: Sample, + request, ): """Test check if all flow cells for samples on a case is on disk when requested.""" caplog.set_level(logging.DEBUG) - # GIVEN a store with two flow cell helpers.add_flow_cell( store=base_store,