Skip to content

Commit cab8298

Browse files
committed
Updated test with awaits for async functions
1 parent 0533c33 commit cab8298

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

metamist/audit/audit_upload_bucket.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858
def get_sequencing_types():
5959
"""Return the list of sequencing types from the enum table."""
6060
logging.getLogger().setLevel(logging.WARN)
61-
sequencing_types = query(
62-
SEQUENCING_TYPES_QUERY
63-
)
61+
sequencing_types = query(SEQUENCING_TYPES_QUERY)
6462
logging.getLogger().setLevel(logging.INFO)
65-
return sequencing_types['enum']['sequencingType'] # pylint: disable=unsubscriptable-object
63+
return sequencing_types['enum'][ # pylint: disable=unsubscriptable-object
64+
'sequencingType'
65+
]
6666

6767

6868
def audit_upload_bucket(
@@ -214,6 +214,8 @@ async def audit_upload_bucket_async(
214214
raise ValueError(
215215
f'Input sequencing types "{sequencing_types}" must be in the allowed types: {allowed_sequencing_types}'
216216
)
217+
if sequencing_types == ('all',):
218+
sequencing_types = allowed_sequencing_types
217219

218220
if file_types not in (('all',), ('all_reads',)):
219221
if any(ft not in FILE_TYPES_MAP for ft in file_types):

test/test_generic_auditor.py

+8-29
Original file line numberDiff line numberDiff line change
@@ -388,27 +388,11 @@ async def test_query_genome_analyses_crams(self, mock_query):
388388
},
389389
],
390390
},
391-
{
392-
'id': 'CPGbbb',
393-
'type': 'exome',
394-
'analyses': [
395-
{
396-
'id': 2,
397-
'meta': {
398-
'sequencing_type': 'exome',
399-
'sample_ids': [
400-
'CPGbbb',
401-
],
402-
},
403-
'output': 'gs://cpg-dataset-main/exome/cram/CPGaaa.cram',
404-
},
405-
],
406-
},
407391
]
408392
}
409393
]
410394

411-
test_result = auditor.get_analysis_cram_paths_for_dataset_sgs(
395+
test_result = await auditor.get_analysis_cram_paths_for_dataset_sgs(
412396
assay_sg_id_map={1: 'CPGaaa'}
413397
)
414398
expected_result = {'CPGaaa': {1: 'gs://cpg-dataset-main/cram/CPGaaa.cram'}}
@@ -440,11 +424,7 @@ async def test_query_genome_and_exome_analyses_crams(self, mock_query):
440424
'output': 'gs://cpg-dataset-main/cram/CPGaaa.cram',
441425
},
442426
],
443-
}
444-
]
445-
},
446-
{
447-
'sequencingGroups': [
427+
},
448428
{
449429
'id': 'CPGbbb',
450430
'type': 'exome',
@@ -465,7 +445,7 @@ async def test_query_genome_and_exome_analyses_crams(self, mock_query):
465445
},
466446
]
467447

468-
test_result = auditor.get_analysis_cram_paths_for_dataset_sgs(
448+
test_result = await auditor.get_analysis_cram_paths_for_dataset_sgs(
469449
assay_sg_id_map={1: 'CPGaaa', 2: 'CPGbbb'}
470450
)
471451

@@ -507,7 +487,7 @@ async def test_query_broken_analyses_crams(self, mock_query):
507487
}
508488

509489
with self.assertRaises(ValueError):
510-
auditor.get_analysis_cram_paths_for_dataset_sgs(
490+
await auditor.get_analysis_cram_paths_for_dataset_sgs(
511491
assay_sg_id_map={1: 'CPGaaa'}
512492
)
513493

@@ -527,23 +507,22 @@ async def test_query_analyses_crams_warning(self, mock_query):
527507
'id': 1,
528508
'meta': {
529509
'sequencing_type': 'genome',
530-
'sampling_id': 'CPGaaa',
531510
},
532-
'output': 'gs://cpg-dataset-main/cram/CPGaaa.cram',
511+
'output': 'gs://cpg-dataset-main/cram/CPGaaa.notcram',
533512
},
534513
],
535514
}
536515
]
537516
}
538517

539518
with self.assertLogs(level='WARNING') as log:
540-
_ = auditor.get_analysis_cram_paths_for_dataset_sgs(
519+
_ = await auditor.get_analysis_cram_paths_for_dataset_sgs(
541520
assay_sg_id_map={1: 'CPGaaa'}
542521
)
543522
self.assertEqual(len(log.output), 1)
544523
self.assertEqual(len(log.records), 1)
545524
self.assertIn(
546-
'WARNING:root:Analysis 1 invalid output path: gs://cpg-dataset-main/cram/CPG123.notcram',
525+
'WARNING:root:Analysis 1 invalid output path: gs://cpg-dataset-main/cram/CPGaaa.notcram',
547526
log.output[0],
548527
)
549528

@@ -631,7 +610,7 @@ async def test_get_complete_and_incomplete_sgs(
631610
)
632611

633612
expected_result = {
634-
'complete': {'CPGaaa': [1], 'CPGbbb': [2]},
613+
'complete': {'CPGaaa': 1, 'CPGbbb': 2},
635614
'incomplete': ['CPGccc'],
636615
}
637616

0 commit comments

Comments
 (0)