Skip to content

Commit

Permalink
Fixing tests and doing some error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
bergsalex committed Sep 3, 2024
1 parent 3b863ac commit 6f4fd59
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/geneweaver/client/api/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def ensembl_mouse_mapping(
gene_id_type = GeneIdentifier.ENSEMBLE_GENE

if species != Species.MUS_MUSCULUS:
gene_id_type = AON_ID_TYPE_FOR_SPECIES[species]
try:
gene_id_type = AON_ID_TYPE_FOR_SPECIES[species]
except KeyError:
raise ValueError(f"Species {species} is not supported for ortholog mapping")

response = genesets.get_values(access_token, geneset_id, gene_id_type, in_threshold)
if species == Species.MUS_MUSCULUS:
Expand Down
53 changes: 32 additions & 21 deletions tests/unit/api/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
from geneweaver.client.api import mapping
from geneweaver.client.api.aon import OrthologAlgorithms
from geneweaver.core.enum import Species
from geneweaver.core.mapping import AON_ID_TYPE_FOR_SPECIES


SUPPORTED_AON_SP_IDS = [int(species) for species in AON_ID_TYPE_FOR_SPECIES.keys()]


@pytest.mark.parametrize("species_id", [int(species) for species in Species])
@pytest.mark.parametrize("algorithm", [algorithm for algorithm in OrthologAlgorithms])
@patch("geneweaver.client.api.mapping.insert_colon_delimiter", lambda x: x)
@patch("geneweaver.client.api.mapping.genesets.get")
@patch("geneweaver.client.api.mapping.genesets.get_values")
@patch("geneweaver.client.api.mapping.aon.algorithm_id_from_name")
Expand Down Expand Up @@ -45,28 +50,34 @@ def test_ensembl_mouse_mapping(

mock_aon_map_symbols.side_effect = [{"A1": "1", "B1": "2"}, {"A2": "1", "B2": "2"}]

result = mapping.ensembl_mouse_mapping(
"fake_access_token", 123, True, OrthologAlgorithms.HGNC
)
if species_id in SUPPORTED_AON_SP_IDS:
result = mapping.ensembl_mouse_mapping(
"fake_access_token", 123, True, OrthologAlgorithms.HGNC
)
assert mock_genesets_get.call_count == 1
assert mock_genesets_get_values.call_count == 1

assert mock_genesets_get.call_count == 1
assert mock_genesets_get_values.call_count == 1
if species_id == 1:
assert result == [
{"gene_id": "A", "score": "1"},
{"gene_id": "B", "score": "2"},
]
expected_api_calls, expected_mapping_calls = 0, 0

if species_id == 1:
assert result == [
{"gene_id": "A", "score": "1"},
{"gene_id": "B", "score": "2"},
]
expected_api_calls, expected_mapping_calls = 0, 0
else:
assert result == [
{"gene_id": "A2", "score": "1"},
{"gene_id": "B2", "score": "2"},
]
expected_api_calls, expected_mapping_calls = 1, 2

else:
assert result == [
{"gene_id": "A2", "score": "1"},
{"gene_id": "B2", "score": "2"},
]
expected_api_calls, expected_mapping_calls = 1, 2
assert mock_aon_algorithm_id_from_name.call_count == expected_api_calls
assert mock_aon_ortholog_mapping.call_count == expected_api_calls
assert mock_genes_mappings.call_count == expected_api_calls
assert mock_aon_map_symbols.call_count == expected_mapping_calls

assert mock_aon_algorithm_id_from_name.call_count == expected_api_calls
assert mock_aon_ortholog_mapping.call_count == expected_api_calls
assert mock_genes_mappings.call_count == expected_api_calls
assert mock_aon_map_symbols.call_count == expected_mapping_calls
else:
with pytest.raises(ValueError):
mapping.ensembl_mouse_mapping(
"fake_access_token", 123, True, OrthologAlgorithms.HGNC
)

0 comments on commit 6f4fd59

Please sign in to comment.