Skip to content

Commit

Permalink
Handle call to source_is_human in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jswelling committed Dec 19, 2024
1 parent 8425919 commit fc52cec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
39 changes: 23 additions & 16 deletions tests/test_rule_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from pprint import pprint

from local_rule_tester import calculate_assay_info, wrapped_lookup_json
from local_rule_tester import calculate_assay_info, wrapped_lookup_entity_json
from source_is_human import source_is_human

@pytest.fixture
Expand Down Expand Up @@ -84,17 +84,15 @@ def test_sample_path():
'ubkg_code': 'C200500',
'pipeline-shorthand': 'Salmon'}),
# Disable this test because sample_is_human is not being
# correctly resolved in this version
# ("metadata_SNT594.FZCM.747_SENNET.json",
# {'assaytype': 'scRNAseq-10xGenomics-v3',
# 'contains-pii': False,
# 'dataset-type': 'RNAseq',
# 'description': 'scRNAseq (10x Genomics v3)',
# 'dir-schema': 'rnaseq-v2',
# 'primary': True,
# 'ubkg_code': 'C200850',
# 'vitessce-hints': ()}),
("metadata_SNT594.FZCM.747_SENNET.json",
{'assaytype': 'scRNAseq-10xGenomics-v3',
'contains-pii': False,
'dataset-type': 'RNAseq',
'description': 'scRNAseq (10x Genomics v3)',
'dir-schema': 'rnaseq-v2',
'primary': True,
'ubkg_code': 'C200850',
'vitessce-hints': ()}),
("metadata_HBM263.FTWN.879_visium_rnaseq_hubmap.tsv",
{'assaytype': 'rnaseq-visium-no-probes',
Expand Down Expand Up @@ -153,17 +151,26 @@ def test_rule_match_case(test_sample_path, test_data_fname, expected, tmp_path):
# samples, so we can check source type
parent_sample_ids = payload["parent_sample_id"].split(",")
parent_sample_ids = [elt.strip() for elt in parent_sample_ids]
is_human = source_is_human(parent_sample_ids, wrapped_lookup_json)
is_human = source_is_human(parent_sample_ids,
wrapped_lookup_entity_json)
else:
is_human = True # legacy data is all human
payload["source_is_human"] = is_human
rslt = calculate_assay_info(payload)
rslt = calculate_assay_info(payload, is_human)
assert rslt, f"{test_data_fname} record {idx} failed"
elif str(md_path).endswith('.json'):
with open(md_path) as jsonfile:
payload = json.load(jsonfile)
print(json.dumps(payload))
rslt = calculate_assay_info(payload)
if "parent_sample_id" in payload:
# This sample is new enough to have a value for parent
# samples, so we can check source type
parent_sample_ids = payload["parent_sample_id"].split(",")
parent_sample_ids = [elt.strip() for elt in parent_sample_ids]
is_human = source_is_human(parent_sample_ids,
wrapped_lookup_entity_json)
else:
is_human = True # legacy data is all human
rslt = calculate_assay_info(payload, is_human)
assert rslt, f"{test_data_fname} record failed"
else:
assert False, f"Metadata path {md_path} is not .tsv or .json"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def test_rule_case(test_sample_path, test_data_fname, tmp_path):
print(arg_df)
for idx, row in arg_df.iterrows():
payload = {col: row[col] for col in arg_df.columns}
rslt = calculate_assay_info(payload)
rslt = calculate_assay_info(payload, True)
assert rslt, f"{test_data_fname} record {idx} failed"
elif str(md_path).endswith('.json'):
with open(md_path) as jsonfile:
payload = json.load(jsonfile)
print(json.dumps(payload))
rslt = calculate_assay_info(payload)
rslt = calculate_assay_info(payload, True)
assert rslt, f"{test_data_fname} record failed"
else:
assert False, f"Metadata path {md_path} is not .tsv or .json"
4 changes: 2 additions & 2 deletions tests/test_source_is_human.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from pprint import pprint

from local_rule_tester import wrapped_lookup_json
from local_rule_tester import wrapped_lookup_entity_json
from source_is_human import source_is_human

logging.basicConfig(encoding="utf-8", level=logging.INFO)
Expand All @@ -23,5 +23,5 @@
))
def test_source_is_human(uuid_list, expected_value, tmp_path, caplog):
with caplog.at_level(logging.DEBUG):
val = source_is_human(uuid_list, wrapped_lookup_json)
val = source_is_human(uuid_list, wrapped_lookup_entity_json)
assert val == expected_value

0 comments on commit fc52cec

Please sign in to comment.