|
21 | 21 | # limitations under the License. |
22 | 22 | """Tests for pubchem.py.""" |
23 | 23 |
|
| 24 | +import json |
24 | 25 | import unittest |
25 | | -from unittest.mock import patch, Mock |
| 26 | +from unittest.mock import Mock, patch |
| 27 | + |
26 | 28 | import numpy |
27 | 29 | import pytest |
28 | | -import json |
| 30 | +from pubchempy import ServerError |
29 | 31 |
|
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 |
31 | 33 | from openfermion.testing.testing_utils import module_importable |
32 | 34 |
|
33 | 35 | using_pubchempy = pytest.mark.skipif( |
@@ -131,9 +133,14 @@ def test_water_2d(self, mock_get_compounds): |
131 | 133 |
|
132 | 134 | @patch('openfermion.chem.pubchem.get_compounds') |
133 | 135 | def test_retry_logic(self, mock_get_compounds): |
134 | | - from pubchempy import ServerError |
135 | | - |
136 | 136 | mock_get_compounds.side_effect = [ServerError('Error'), 'Success'] |
137 | 137 | result = _get_compounds_with_retry('water', '3d') |
138 | 138 | self.assertEqual(result, 'Success') |
139 | 139 | 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