Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Dec 15, 2023
1 parent 13c1e20 commit acfd228
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 70 deletions.
7 changes: 0 additions & 7 deletions tests/apps/demultiplex/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest

from cg.apps.demultiplex.sample_sheet.index import Index
from cg.apps.demultiplex.sample_sheet.sample_models import (
FlowCellSampleBcl2Fastq,
FlowCellSampleBCLConvert,
Expand Down Expand Up @@ -45,12 +44,6 @@ def bcl_convert_samples_similar_index2() -> list[FlowCellSampleBCLConvert]:
return [sample_1, sample_2, sample_3]


@pytest.fixture
def valid_index() -> Index:
"""Return a valid index."""
return Index(name="C07 - UDI0051", sequence="AACAGGTT-ATACCAAG")


@pytest.fixture
def bcl2fastq_sample_sheet_creator(
novaseq_flow_cell_demultiplexed_with_bcl2fastq: FlowCellDirectoryData,
Expand Down
59 changes: 26 additions & 33 deletions tests/apps/demultiplex/test_sample_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_get_index1_override_cycles(
def test_get_index2_override_cycles(
raw_index: str, index2_cycles: int, reverse_cycle: bool, expected_parsed_cycles: str
):
"""Test that the returned index 2 cycles is teh expected for different index configurations."""
"""Test that the returned index 2 cycles is the expected for different index configurations."""
# GIVEN a FlowCellSampleBCLConvert with separated indexes
sample = FlowCellSampleBCLConvert(lane=1, index=raw_index, sample_id="ACC123")
sample.separate_indexes()
Expand All @@ -191,6 +191,8 @@ def test_get_index2_override_cycles(
def test_update_override_cycles():
# TODO: Parametrise this test with different run parameter files and samples
"""."""
# GIVEN a run parameters object

# GIVEN a FlowCellSampleBCLConvert

# WHEN updating the override cycles
Expand Down Expand Up @@ -245,49 +247,40 @@ def test_update_barcode_mismatches_2(


@pytest.mark.parametrize(
"run_parameters_fixture, raw_lims_samples_fixture, sample_model",
"run_parameters_fixture, raw_lims_samples_fixture",
[
("novaseq_x_run_parameters", "novaseq_x_lims_samples", FlowCellSampleBCLConvert),
(
"novaseq_6000_run_parameters_pre_1_5_kits",
"novaseq_6000_pre_1_5_kits_lims_samples",
FlowCellSampleBCLConvert,
),
(
"novaseq_6000_run_parameters_post_1_5_kits",
"novaseq_6000_post_1_5_kits_lims_samples",
FlowCellSampleBCLConvert,
),
("hiseq_x_run_parameters_single_index", "hiseq_x_lims_samples", FlowCellSampleBCLConvert),
("hiseq_x_run_parameters_single_index", "hiseq_x_lims_samples", FlowCellSampleBcl2Fastq),
(
"hiseq_2500_run_parameters_double_index",
"hiseq_2500_lims_samples",
FlowCellSampleBCLConvert,
),
(
"hiseq_2500_run_parameters_double_index",
"hiseq_2500_lims_samples",
FlowCellSampleBcl2Fastq,
),
("novaseq_x_run_parameters", "novaseq_x_lims_samples"),
("novaseq_6000_run_parameters_pre_1_5_kits", "novaseq_6000_pre_1_5_kits_lims_samples"),
("novaseq_6000_run_parameters_post_1_5_kits", "novaseq_6000_post_1_5_kits_lims_samples"),
("hiseq_x_run_parameters_single_index", "hiseq_x_lims_samples"),
("hiseq_2500_run_parameters_double_index", "hiseq_2500_lims_samples"),
],
ids=[
"NovaSeqX",
"NovaSeq6000 pre1.5",
"NovaSeq6000 post1.5",
"HiSeqX BclConvert",
"HiSeqX Bcl2Fastq",
"HiSeq2500 BCLConvert",
"HiSeq2500 Bcl2Fastq",
"HiSeqX",
"HiSeq2500",
],
)
def test_process_sample_for_sample_sheet(
run_parameters_fixture: str, raw_lims_samples_fixture: str, sample_model: Type[FlowCellSample]
def test_process_sample_for_sample_sheet_bcl_convert(
run_parameters_fixture: str, raw_lims_samples_fixture: str, request: pytest.FixtureRequest
):
# TODO: We need a raw FlowCellSampleBcl2Fastq and a raw FlowCellSampleBCLConvert
# TODO: We need a raw FlowCellSampleBCLConvert
"""."""
# GIVEN a run parameters object and a list of samples from a flow cell
# GIVEN a run parameters object and a list of BCLConvert samples from a flow cell
run_parameters: RunParameters = request.getfixturevalue(run_parameters_fixture)
raw_lims_samples: list[FlowCellSampleBCLConvert] = request.getfixturevalue(
raw_lims_samples_fixture
)

# GIVEN a FlowCellSampleBCLConvert
sample: FlowCellSampleBCLConvert = raw_lims_samples[0]

# WHEN processing the sample for a sample sheet
sample.process_sample_for_sample_sheet(run_parameters=run_parameters)

# THEN the sample is processed
assert sample.barcode_mismatches_1
assert sample.barcode_mismatches_2
assert sample.override_cycles
11 changes: 3 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,12 +1396,6 @@ def novaseq_bcl_convert_sample_sheet_path(bcl_convert_flow_cell_dir: Path) -> Pa
return Path(bcl_convert_flow_cell_dir, DemultiplexingDirsAndFiles.SAMPLE_SHEET_FILE_NAME)


@pytest.fixture(scope="session")
def run_parameters_missing_versions_path(run_parameters_dir: Path) -> Path:
"""Return a NovaSeq6000 run parameters file path without software and reagent kit versions."""
return Path(run_parameters_dir, "RunParameters_novaseq_no_software_nor_reagent_version.xml")


@pytest.fixture(scope="session")
def run_parameters_wrong_instrument(run_parameters_dir: Path) -> Path:
"""Return a NovaSeqX run parameters file path with a wrong instrument value."""
Expand Down Expand Up @@ -1483,10 +1477,11 @@ def run_parameters_novaseq_x_different_index(run_parameters_dir: Path) -> RunPar

@pytest.fixture(scope="module")
def run_parameters_missing_versions(
run_parameters_missing_versions_path: Path,
run_parameters_dir: Path,
) -> RunParametersNovaSeq6000:
"""Return a NovaSeq6000 run parameters object without software and reagent kit versions."""
return RunParametersNovaSeq6000(run_parameters_path=run_parameters_missing_versions_path)
path = Path(run_parameters_dir, "RunParameters_novaseq_no_software_nor_reagent_version.xml")
return RunParametersNovaSeq6000(run_parameters_path=path)


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Sequencer: HiSeq2500
Workflow: CUSTOM
Indexes: 17,8
BCL converter: BCLConvert

71 changes: 49 additions & 22 deletions tests/models/demultiplexing/test_run_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from _pytest.fixtures import FixtureRequest
from pydantic import BaseModel

from cg.apps.demultiplex.sample_sheet.sample_sheet_creator import SampleSheetCreatorBCLConvert
from cg.constants.demultiplexing import (
Expand Down Expand Up @@ -75,41 +76,67 @@ def test_run_parameters_init(
assert run_parameters.sequencer == sequencer


class RunParametersScenario(BaseModel):
wrong_run_parameters_path_fixture: str
constructor: Type[RunParameters]
error_msg: str


@pytest.mark.parametrize(
"wrong_run_parameters_path_fixture, constructor, node_name",
"scenario",
[
(
"novaseq_6000_run_parameters_path",
RunParametersHiSeq,
RunParametersXMLNodes.APPLICATION_NAME,
RunParametersScenario(
wrong_run_parameters_path_fixture="novaseq_6000_run_parameters_path",
constructor=RunParametersHiSeq,
error_msg=f"Could not find node {RunParametersXMLNodes.APPLICATION_NAME} in the run parameters file.",
),
RunParametersScenario(
wrong_run_parameters_path_fixture="novaseq_x_run_parameters_path",
constructor=RunParametersHiSeq,
error_msg=f"Could not find node {RunParametersXMLNodes.APPLICATION_NAME} in the run parameters file.",
),
RunParametersScenario(
wrong_run_parameters_path_fixture="novaseq_x_run_parameters_path",
constructor=RunParametersNovaSeq6000,
error_msg=f"The file parsed does not correspond to {RunParametersXMLNodes.NOVASEQ_6000_APPLICATION}",
),
RunParametersScenario(
wrong_run_parameters_path_fixture="hiseq_x_single_index_run_parameters_path",
constructor=RunParametersNovaSeq6000,
error_msg=f"Could not find node {RunParametersXMLNodes.APPLICATION} in the run parameters file.",
),
(
"novaseq_x_run_parameters_path",
RunParametersNovaSeq6000,
RunParametersXMLNodes.APPLICATION,
RunParametersScenario(
wrong_run_parameters_path_fixture="hiseq_x_single_index_run_parameters_path",
constructor=RunParametersNovaSeqX,
error_msg=f"Could not find node {RunParametersXMLNodes.INSTRUMENT_TYPE} in the run parameters file.",
),
(
"hiseq_x_single_index_run_parameters_path",
RunParametersNovaSeqX,
RunParametersXMLNodes.INSTRUMENT_TYPE,
RunParametersScenario(
wrong_run_parameters_path_fixture="novaseq_6000_run_parameters_path",
constructor=RunParametersNovaSeqX,
error_msg=f"Could not find node {RunParametersXMLNodes.INSTRUMENT_TYPE} in the run parameters file.",
),
],
ids=[
"NovaSeq 6000 file, HiSeq constructor",
"NovaSeq X file, HiSeq constructor",
"NovaSeq X file, NovaSeq6000 constructor",
"HiSeq X file, NovaSeq600 constructor",
"HiSeq X file, NovaSeqX constructor",
"NovaSeq6000 constructor, NovaSeqX constructor",
],
)
def test_run_parameters_wrong_file(
wrong_run_parameters_path_fixture: str,
constructor: Type[RunParameters],
node_name: str,
request: FixtureRequest,
):
def test_run_parameters_wrong_file(scenario: RunParametersScenario, request: FixtureRequest):
"""Test that creating a RunParameters object with a wrong file fails."""
# GIVEN a run parameters path from an instrument different from the expected
wrong_run_parameters_path: Path = request.getfixturevalue(wrong_run_parameters_path_fixture)
wrong_run_parameters_path: Path = request.getfixturevalue(
scenario.wrong_run_parameters_path_fixture
)

# WHEN trying to create a RunParameters object with the file
with pytest.raises(RunParametersError) as exc_info:
# THEN a RunParametersError is raised
constructor(run_parameters_path=wrong_run_parameters_path)
assert f"Could not find node {node_name} in the run parameters file" in str(exc_info.value)
scenario.constructor(run_parameters_path=wrong_run_parameters_path)
assert scenario.error_msg in str(exc_info.value)


def test_run_parameters_hiseq_wrong_file(novaseq_6000_run_parameters_path: Path):
Expand Down

0 comments on commit acfd228

Please sign in to comment.