From fe95bd2c519681f8bbd1d58f81fc0ab67ceb4f5e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2026 17:51:19 +0000 Subject: [PATCH 1/3] Add tests for name2uniprot in pathwaycommons.py Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com> --- tests/test_pathwaycommons.py | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/test_pathwaycommons.py diff --git a/tests/test_pathwaycommons.py b/tests/test_pathwaycommons.py new file mode 100644 index 00000000..dd2f4922 --- /dev/null +++ b/tests/test_pathwaycommons.py @@ -0,0 +1,73 @@ +import pytest +from unittest.mock import patch, MagicMock +from urllib.error import HTTPError +import urllib.request +from bionetgen.atomizer.utils.pathwaycommons import name2uniprot + +def test_name2uniprot_with_organism(): + """Test name2uniprot when organism is provided and response is successful.""" + with patch('urllib.request.urlopen') as mock_urlopen: + mock_response = MagicMock() + mock_response.read.return_value = b'entry name\tid\nEGF_HUMAN\tP01133\nEGF_MOUSE\tP01132\n'.decode('utf-8') + mock_urlopen.return_value = mock_response + + # Use an organism that ends in '9606' to trigger organism query building + result = name2uniprot('EGF', ['taxonomy/9606']) + + # It should parse matching symbols based on `nameStr` ignoring case. + # Since 'EGF' is in 'EGF_HUMAN' and 'EGF_MOUSE', both should be returned. + assert result == ['P01133', 'P01132'] + mock_urlopen.assert_called_once() + +def test_name2uniprot_fallback_no_organism(): + """Test name2uniprot fallback when initial organism query returns no results.""" + with patch('urllib.request.urlopen') as mock_urlopen: + mock_response_1 = MagicMock() + # Empty string response or missing to trigger fallback + mock_response_1.read.return_value = b''.decode('utf-8') + + mock_response_2 = MagicMock() + # Mocking the fallback response + mock_response_2.read.return_value = b'entry name\tid\nEGF2_HUMAN\tP01133\n'.decode('utf-8') + + # urlopen will return mock_response_1 then mock_response_2 on successive calls + mock_urlopen.side_effect = [mock_response_1, mock_response_2] + + result = name2uniprot('EGF2', ['taxonomy/9606']) + + assert result == ['P01133'] + assert mock_urlopen.call_count == 2 + +def test_name2uniprot_no_organism(): + """Test name2uniprot when no organism is provided.""" + with patch('urllib.request.urlopen') as mock_urlopen: + mock_response = MagicMock() + mock_response.read.return_value = b'entry name\tid\nEGF3_HUMAN\tP01133\n'.decode('utf-8') + mock_urlopen.return_value = mock_response + + result = name2uniprot('EGF3', None) + + assert result == ['P01133'] + mock_urlopen.assert_called_once() + +def test_name2uniprot_http_error_with_organism(): + """Test name2uniprot handling of HTTPError when organism is provided.""" + with patch('urllib.request.urlopen') as mock_urlopen: + mock_urlopen.side_effect = HTTPError(url='', code=500, msg='Internal Server Error', hdrs={}, fp=None) + + result = name2uniprot('EGF4', ['taxonomy/9606']) + + # It should catch the error, log it, and return None + assert result is None + mock_urlopen.assert_called_once() + +def test_name2uniprot_http_error_no_organism(): + """Test name2uniprot handling of HTTPError when no organism is provided (fallback).""" + with patch('urllib.request.urlopen') as mock_urlopen: + # Side effect raises error for the query + mock_urlopen.side_effect = HTTPError(url='', code=500, msg='Internal Server Error', hdrs={}, fp=None) + + result = name2uniprot('EGF5', None) + + assert result is None + mock_urlopen.assert_called_once() From 7fc2fbc3f80ef9e7b0ad6f567c5a0d9ba6e51bb9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2026 20:40:35 +0000 Subject: [PATCH 2/3] Apply black formatting to tests/test_pathwaycommons.py Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com> --- tests/test_pathwaycommons.py | 53 +++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/tests/test_pathwaycommons.py b/tests/test_pathwaycommons.py index dd2f4922..6c0e7861 100644 --- a/tests/test_pathwaycommons.py +++ b/tests/test_pathwaycommons.py @@ -4,70 +4,85 @@ import urllib.request from bionetgen.atomizer.utils.pathwaycommons import name2uniprot + def test_name2uniprot_with_organism(): """Test name2uniprot when organism is provided and response is successful.""" - with patch('urllib.request.urlopen') as mock_urlopen: + with patch("urllib.request.urlopen") as mock_urlopen: mock_response = MagicMock() - mock_response.read.return_value = b'entry name\tid\nEGF_HUMAN\tP01133\nEGF_MOUSE\tP01132\n'.decode('utf-8') + mock_response.read.return_value = ( + b"entry name\tid\nEGF_HUMAN\tP01133\nEGF_MOUSE\tP01132\n".decode("utf-8") + ) mock_urlopen.return_value = mock_response # Use an organism that ends in '9606' to trigger organism query building - result = name2uniprot('EGF', ['taxonomy/9606']) + result = name2uniprot("EGF", ["taxonomy/9606"]) # It should parse matching symbols based on `nameStr` ignoring case. # Since 'EGF' is in 'EGF_HUMAN' and 'EGF_MOUSE', both should be returned. - assert result == ['P01133', 'P01132'] + assert result == ["P01133", "P01132"] mock_urlopen.assert_called_once() + def test_name2uniprot_fallback_no_organism(): """Test name2uniprot fallback when initial organism query returns no results.""" - with patch('urllib.request.urlopen') as mock_urlopen: + with patch("urllib.request.urlopen") as mock_urlopen: mock_response_1 = MagicMock() # Empty string response or missing to trigger fallback - mock_response_1.read.return_value = b''.decode('utf-8') + mock_response_1.read.return_value = b"".decode("utf-8") mock_response_2 = MagicMock() # Mocking the fallback response - mock_response_2.read.return_value = b'entry name\tid\nEGF2_HUMAN\tP01133\n'.decode('utf-8') + mock_response_2.read.return_value = ( + b"entry name\tid\nEGF2_HUMAN\tP01133\n".decode("utf-8") + ) # urlopen will return mock_response_1 then mock_response_2 on successive calls mock_urlopen.side_effect = [mock_response_1, mock_response_2] - result = name2uniprot('EGF2', ['taxonomy/9606']) + result = name2uniprot("EGF2", ["taxonomy/9606"]) - assert result == ['P01133'] + assert result == ["P01133"] assert mock_urlopen.call_count == 2 + def test_name2uniprot_no_organism(): """Test name2uniprot when no organism is provided.""" - with patch('urllib.request.urlopen') as mock_urlopen: + with patch("urllib.request.urlopen") as mock_urlopen: mock_response = MagicMock() - mock_response.read.return_value = b'entry name\tid\nEGF3_HUMAN\tP01133\n'.decode('utf-8') + mock_response.read.return_value = ( + b"entry name\tid\nEGF3_HUMAN\tP01133\n".decode("utf-8") + ) mock_urlopen.return_value = mock_response - result = name2uniprot('EGF3', None) + result = name2uniprot("EGF3", None) - assert result == ['P01133'] + assert result == ["P01133"] mock_urlopen.assert_called_once() + def test_name2uniprot_http_error_with_organism(): """Test name2uniprot handling of HTTPError when organism is provided.""" - with patch('urllib.request.urlopen') as mock_urlopen: - mock_urlopen.side_effect = HTTPError(url='', code=500, msg='Internal Server Error', hdrs={}, fp=None) + with patch("urllib.request.urlopen") as mock_urlopen: + mock_urlopen.side_effect = HTTPError( + url="", code=500, msg="Internal Server Error", hdrs={}, fp=None + ) - result = name2uniprot('EGF4', ['taxonomy/9606']) + result = name2uniprot("EGF4", ["taxonomy/9606"]) # It should catch the error, log it, and return None assert result is None mock_urlopen.assert_called_once() + def test_name2uniprot_http_error_no_organism(): """Test name2uniprot handling of HTTPError when no organism is provided (fallback).""" - with patch('urllib.request.urlopen') as mock_urlopen: + with patch("urllib.request.urlopen") as mock_urlopen: # Side effect raises error for the query - mock_urlopen.side_effect = HTTPError(url='', code=500, msg='Internal Server Error', hdrs={}, fp=None) + mock_urlopen.side_effect = HTTPError( + url="", code=500, msg="Internal Server Error", hdrs={}, fp=None + ) - result = name2uniprot('EGF5', None) + result = name2uniprot("EGF5", None) assert result is None mock_urlopen.assert_called_once() From 918016143685aaa6b0cfaa7e22859269edbe47e6 Mon Sep 17 00:00:00 2001 From: akutuva21 Date: Mon, 13 Apr 2026 10:17:02 -0400 Subject: [PATCH 3/3] chore: PR #53 remove forbidden artifacts and run black --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) 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__/