@@ -80,20 +80,6 @@ def mock_get_compounds(name, searchtype, record_type='2d'):
8080
8181@using_pubchempy
8282class OpenFermionPubChemTest (unittest .TestCase ):
83- def _get_geometry_with_retries (self , name ):
84- import urllib .error
85-
86- import pubchempy
87-
88- max_retries = 3
89- delay = 2
90- for attempt in range (max_retries ):
91- try :
92- return geometry_from_pubchem (name )
93- except (pubchempy .PubChemHTTPError , urllib .error .URLError ):
94- if attempt == max_retries - 1 :
95- raise
96- time .sleep (delay )
9783
9884 @patch ('pubchempy.get_compounds' , mock_get_compounds )
9985 def test_water (self ):
@@ -166,59 +152,7 @@ def test_water_2d(self):
166152 with pytest .raises (ValueError , match = 'Incorrect value for the argument structure' ):
167153 _ = geometry_from_pubchem ('water' , structure = 'foo' )
168154
169- @pytest .mark .integration
155+ @pytest .mark .flaky ( retries = 3 , delay = 2 )
170156 def test_geometry_from_pubchem_live_api (self ):
171- water_geometry = self . _get_geometry_with_retries ('water' ) # pragma: no cover
157+ water_geometry = geometry_from_pubchem ('water' ) # pragma: no cover
172158 self .assertEqual (len (water_geometry ), 3 ) # pragma: no cover
173-
174- @patch ('time.sleep' , return_value = None )
175- @patch ('pubchempy.get_compounds' )
176- def test_geometry_from_pubchem_retry_success (self , mock_get_compounds , mock_sleep ):
177- import pubchempy
178-
179- mock_get_compounds .side_effect = [
180- pubchempy .PubChemHTTPError (503 , 'Server Busy' , 'Testing' ),
181- pubchempy .PubChemHTTPError (503 , 'Server Busy' , 'Testing' ),
182- [
183- MockCompound (
184- [
185- {'aid' : 1 , 'number' : 8 , 'element' : 'O' , 'y' : 0 , 'z' : 0 , 'x' : 0 },
186- {
187- 'aid' : 2 ,
188- 'number' : 1 ,
189- 'element' : 'H' ,
190- 'y' : 0.8929 ,
191- 'z' : 0.2544 ,
192- 'x' : 0.2774 ,
193- },
194- {
195- 'aid' : 3 ,
196- 'number' : 1 ,
197- 'element' : 'H' ,
198- 'y' : - 0.2383 ,
199- 'z' : - 0.7169 ,
200- 'x' : 0.6068 ,
201- },
202- ]
203- )
204- ],
205- ]
206-
207- water_geometry = self ._get_geometry_with_retries ('water' )
208-
209- self .assertEqual (len (water_geometry ), 3 )
210- self .assertEqual (mock_get_compounds .call_count , 3 )
211- self .assertEqual (mock_sleep .call_count , 2 )
212-
213- @patch ('time.sleep' , return_value = None )
214- @patch ('pubchempy.get_compounds' )
215- def test_geometry_from_pubchem_retry_failure (self , mock_get_compounds , mock_sleep ):
216- import pubchempy
217-
218- mock_get_compounds .side_effect = pubchempy .PubChemHTTPError (503 , 'Server Busy' , 'Testing' )
219-
220- with self .assertRaises (pubchempy .PubChemHTTPError ):
221- self ._get_geometry_with_retries ('water' )
222-
223- self .assertEqual (mock_get_compounds .call_count , 3 )
224- self .assertEqual (mock_sleep .call_count , 2 )
0 commit comments