diff --git a/.gitignore b/.gitignore index 39aa9026..f9bf9c80 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ temp_testing/* build dist Issues/rule_keywords/test_DeleteMolecules_changed.bngl +.jules/ +__pycache__/ diff --git a/tests/test_pathwaycommons.py b/tests/test_pathwaycommons.py new file mode 100644 index 00000000..ae7d3bfd --- /dev/null +++ b/tests/test_pathwaycommons.py @@ -0,0 +1,23 @@ +import urllib.request +import urllib.error +from unittest.mock import patch +from bionetgen.atomizer.utils.pathwaycommons import name2uniprot + + +def test_name2uniprot_organism_httperror(): + with patch("urllib.request.urlopen") as mock_urlopen: + # Create an HTTPError instance + # HTTPError requires url, code, msg, hdrs, fp + mock_urlopen.side_effect = urllib.error.HTTPError( + url="http://www.uniprot.org/uniprot/?", + code=500, + msg="Internal Server Error", + hdrs={}, + fp=None, + ) + + # Call the function with an organism to hit the target try/except block + result = name2uniprot("TestGene", ["http://identifiers.org/taxonomy/9606"]) + + # The function should catch the HTTPError and return None + assert result is None