Skip to content

Commit d7d393c

Browse files
committed
Add more test cases to address code coverage
This should address the code coverage failure in the CI checks.
1 parent 25daad5 commit d7d393c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/openfermion/chem/pubchem_test.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
# limitations under the License.
2222
"""Tests for pubchem.py."""
2323

24+
import json
2425
import unittest
25-
from unittest.mock import patch, Mock
26+
from unittest.mock import Mock, patch
27+
2628
import numpy
2729
import pytest
28-
import json
30+
from pubchempy import ServerError
2931

30-
from openfermion.chem.pubchem import geometry_from_pubchem, _get_compounds_with_retry
32+
from openfermion.chem.pubchem import _get_compounds_with_retry, geometry_from_pubchem
3133
from openfermion.testing.testing_utils import module_importable
3234

3335
using_pubchempy = pytest.mark.skipif(
@@ -131,9 +133,14 @@ def test_water_2d(self, mock_get_compounds):
131133

132134
@patch('openfermion.chem.pubchem.get_compounds')
133135
def test_retry_logic(self, mock_get_compounds):
134-
from pubchempy import ServerError
135-
136136
mock_get_compounds.side_effect = [ServerError('Error'), 'Success']
137137
result = _get_compounds_with_retry('water', '3d')
138138
self.assertEqual(result, 'Success')
139139
self.assertEqual(mock_get_compounds.call_count, 2)
140+
141+
@patch('openfermion.chem.pubchem.get_compounds')
142+
def test_retry_logic_exception(self, mock_get_compounds):
143+
mock_get_compounds.side_effect = ServerError('Error')
144+
with pytest.raises(ServerError):
145+
_get_compounds_with_retry('water', '3d')
146+
self.assertEqual(mock_get_compounds.call_count, 3)

0 commit comments

Comments
 (0)