Skip to content

Commit

Permalink
Update tests with asyncio
Browse files Browse the repository at this point in the history
  • Loading branch information
EddieLF committed Sep 25, 2023
1 parent 651f98e commit e566eb2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion metamist/audit/audit_upload_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def audit_upload_bucket_async(
sg_cram_paths = await auditor.get_analysis_cram_paths_for_dataset_sgs(assay_sg_id_map)

# Identify sgs with and without completed crams
sg_completion = auditor.get_complete_and_incomplete_sgs(
sg_completion = await auditor.get_complete_and_incomplete_sgs(
assay_sg_id_map, sg_cram_paths
)

Expand Down
4 changes: 2 additions & 2 deletions metamist/audit/generic_auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ async def analyses_for_sgs_without_crams(self, sgs_without_crams: list[str]):
f'{self.dataset} :: SG {sg_without_cram} missing CRAM but has analysis {completed_analysis}'
)

def get_complete_and_incomplete_sgs(
async def get_complete_and_incomplete_sgs(
self,
assay_sg_id_map: dict[int, str],
sg_cram_paths: dict[str, dict[int, str]],
Expand Down Expand Up @@ -328,7 +328,7 @@ def get_complete_and_incomplete_sgs(
logging.warning(
f'{self.dataset} :: {len(incomplete_sgs)} SGs without CRAMs found: {list(incomplete_sgs)}'
)
self.analyses_for_sgs_without_crams(list(incomplete_sgs))
await self.analyses_for_sgs_without_crams(list(incomplete_sgs))

return {'complete': completed_sgs, 'incomplete': list(incomplete_sgs)}

Expand Down
30 changes: 15 additions & 15 deletions test/test_generic_auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestGenericAuditor(unittest.TestCase):
"""Test the audit helper functions"""

@unittest.mock.patch('metamist.audit.generic_auditor.query')
def test_get_participant_data_for_dataset(self, mock_query):
async def test_get_participant_data_for_dataset(self, mock_query):
"""Only participants with a non-empty samples field should be returned"""
auditor = GenericAuditor(
dataset='dev', sequencing_types=['genome'], file_types=('fastq',)
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_get_participant_data_for_dataset(self, mock_query):
},
]

participant_data = auditor.get_participant_data_for_dataset()
participant_data = await auditor.get_participant_data_for_dataset()

self.assertListEqual(expected_participants, participant_data)

Expand Down Expand Up @@ -361,7 +361,7 @@ def test_get_sequence_mapping_warning_logging(self):
)

@unittest.mock.patch('metamist.audit.generic_auditor.query')
def test_query_genome_analyses_crams(self, mock_query):
async def test_query_genome_analyses_crams(self, mock_query):
"""Test that only the genome analysis crams for a sample map dictionary are returned"""
auditor = GenericAuditor(
dataset='dev', sequencing_types=['genome'], file_types=('fastq',)
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_query_genome_analyses_crams(self, mock_query):
}
]

test_result = auditor.get_analysis_cram_paths_for_dataset_sgs(
test_result = await auditor.get_analysis_cram_paths_for_dataset_sgs(
assay_sg_id_map={1: 'CPG123'}
)
expected_result = {
Expand All @@ -398,7 +398,7 @@ def test_query_genome_analyses_crams(self, mock_query):
self.assertDictEqual(test_result, expected_result)

@unittest.mock.patch('metamist.audit.generic_auditor.query')
def test_query_genome_and_exome_analyses_crams(self, mock_query):
async def test_query_genome_and_exome_analyses_crams(self, mock_query):
"""Test that both the genome and exome analysis crams for a sample map dictionary are returned"""
auditor = GenericAuditor(
dataset='dev', sequencing_types=['genome', 'exome'], file_types=('fastq',)
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_query_genome_and_exome_analyses_crams(self, mock_query):
},
]

test_result = auditor.get_analysis_cram_paths_for_dataset_sgs(
test_result = await auditor.get_analysis_cram_paths_for_dataset_sgs(
assay_sg_id_map={1: 'CPG123', 2: 'CPG456'}
)

Expand All @@ -448,7 +448,7 @@ def test_query_genome_and_exome_analyses_crams(self, mock_query):
self.assertDictEqual(test_result, expected_result)

@unittest.mock.patch('metamist.audit.generic_auditor.query')
def test_query_broken_analyses_crams(self, mock_query):
async def test_query_broken_analyses_crams(self, mock_query):
"""
All analysis crams must have 'sequencing_type' meta field,
ValueError raised if not
Expand Down Expand Up @@ -477,15 +477,15 @@ def test_query_broken_analyses_crams(self, mock_query):
}

with self.assertRaises(ValueError):
auditor.get_analysis_cram_paths_for_dataset_sgs(
await auditor.get_analysis_cram_paths_for_dataset_sgs(
assay_sg_id_map={1: 'CPG123'}
)

@unittest.mock.patch('metamist.audit.generic_auditor.query')
def test_query_analyses_crams_warning(self, mock_query):
async def test_query_analyses_crams_warning(self, mock_query):
"""Warn if the sample_ids field is absent and the sample meta field is used instead"""
auditor = GenericAuditor(
dataset='dev', sequencing_type=['genome'], file_types=('fastq',)
dataset='dev', sequencing_types=['genome'], file_types=('fastq',)
)
mock_query.return_value = {
'sequencingGroups': [
Expand All @@ -506,7 +506,7 @@ def test_query_analyses_crams_warning(self, mock_query):
}

with self.assertLogs(level='WARNING') as log:
_ = auditor.get_analysis_cram_paths_for_dataset_sgs(
_ = await auditor.get_analysis_cram_paths_for_dataset_sgs(
assay_sg_id_map={1: 'CPG123'}
)
self.assertEqual(len(log.output), 1)
Expand All @@ -517,7 +517,7 @@ def test_query_analyses_crams_warning(self, mock_query):
)

@unittest.mock.patch('metamist.audit.generic_auditor.query')
def test_analyses_for_sgs_without_crams(self, mock_query):
async def test_analyses_for_sgs_without_crams(self, mock_query):
"""Log any analyses found for samples without completed CRAMs"""
auditor = GenericAuditor(
dataset='dev', sequencing_types=['genome'], file_types=('fastq',)
Expand Down Expand Up @@ -545,7 +545,7 @@ def test_analyses_for_sgs_without_crams(self, mock_query):

with self.assertLogs(level='WARNING') as log:
# catch the warning logs from here and check below
auditor.analyses_for_sgs_without_crams(sgs_without_crams)
await auditor.analyses_for_sgs_without_crams(sgs_without_crams)

self.assertEqual(len(log.output), 8) # 8 analysis types checked
self.assertEqual(len(log.records), 8)
Expand All @@ -563,7 +563,7 @@ def test_analyses_for_sgs_without_crams(self, mock_query):
@unittest.mock.patch(
'metamist.audit.generic_auditor.GenericAuditor.analyses_for_sgs_without_crams'
)
def test_get_complete_and_incomplete_sgs(
async def test_get_complete_and_incomplete_sgs(
self,
mock_analyses_for_sgs_without_crams,
mock_find_files_in_gcs_buckets_subdirs,
Expand Down Expand Up @@ -592,7 +592,7 @@ def test_get_complete_and_incomplete_sgs(
]
mock_analyses_for_sgs_without_crams.return_value = None

result = auditor.get_complete_and_incomplete_sgs(
result = await auditor.get_complete_and_incomplete_sgs(
assay_sg_id_map=assay_sg_id_map,
sg_cram_paths=sg_cram_paths,
)
Expand Down

0 comments on commit e566eb2

Please sign in to comment.