
    Lrdj                    v    d dl mZ d dlZd dlmc mZ d dlZ	d dl
mZ d dlmZ  G d d          Zdd	Zdd
ZdS )    )annotationsN)Decimal)CoinGeckoClientc                  (    e Zd ZddZd Zd Zd ZdS )	Resppayloadbytesc                    || _         d S Nr   )selfr   s     w/home/agent/.hermes/worktrees/FinanceManager-sprint7-postfinance-portfolio-source/tests/unit/test_coingecko_provider.py__init__zResp.__init__
   s    w    c                    | S r    r   s    r   	__enter__zResp.__enter__   s    r   c                    dS )NFr   )r   argss     r   __exit__zResp.__exit__   s    eer   c                    | j         S r   r   r   s    r   readz	Resp.read   s	    4<'r   N)r   r	   )__name__
__module____qualname__r   r   r   r   r   r   r   r   r   	   s7        >>>>$$$+++'''''r   r   returnNonec                    ddig } d!fd	}t          ddd|| j                  }|                    d	d
          }d         }d}||k    }|slt          j        d|fd||f          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}}ddg}| |k    }	|	st          j        d|	fd| |f          dt          j	                    v st          j
        |           rt          j        |           ndt          j        |          dz  }
dd|
iz  }t          t          j        |                    d x}	}|j        }	d}t          |          }|	|k    }|st          j        d|fd|	|f          dt          j	                    v st          j
        |          rt          j        |          ndt          j        |	          dt          j	                    v st          j
        t                    rt          j        t                    ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}	x}x}}|j        }	d}|	|k    }|st          j        d|fd|	|f          dt          j	                    v st          j
        |          rt          j        |          ndt          j        |	          t          j        |          dz  }dd |iz  }t          t          j        |                    d x}	x}}d S )"Nnr      c                    dxx         dz  cc<   d         dk     r#t           j                            | ddd d           t          d          S )Nr            rate limiteds;   {"bitcoin":{"chf":0.00000001,"last_updated_at":1700000000}})urlliberror	HTTPErrorr   )urltimeoutcallss     r   openerzQtest_coingecko_client_retries_429_and_returns_quote_without_float.<locals>.opener   sR    c


a


:>>,((c>4NNNRSSSr   r$   g      ?g      ?)max_retriesinitial_backoff_secondsmax_backoff_secondsr-   sleeperbitcoinCHF==)z%(py1)s == %(py4)s)py1py4zassert %(py6)spy6)z%(py0)s == %(py3)ssleeps)py0py3zassert %(py5)spy5z1E-8)zK%(py2)s
{%(py2)s = %(py0)s.price
} == %(py8)s
{%(py8)s = %(py4)s(%(py6)s)
}quoter   )r:   py2r7   r8   py8zassert %(py10)spy10freshz6%(py2)s
{%(py2)s = %(py0)s.quality_status
} == %(py5)sr:   r>   r<   assert %(py7)spy7r!   )r   appendget_crypto_price
@pytest_ar_call_reprcompare	_safereprAssertionError_format_explanation@py_builtinslocals_should_repr_global_namepricer   quality_status)r9   r-   clientr=   @py_assert0@py_assert3@py_assert2@py_format5@py_format7@py_assert1@py_format4@py_format6@py_assert5@py_assert7@py_format9@py_format11@py_assert4@py_format8r,   s                     @r   Atest_coingecko_client_retries_429_and_returns_quote_without_floatrb      s   !HEFT T T T T T
 C]`ioy  zG  H  H  HF##Iu55E::?::3Z6Z6Z66Z;)&)'&//);/))))))))));/))))))))))))5)))))5))))));)))))))))))')))))'))))))&))))/)))))))))))))))))))))))))))))*7*7**********7************5*****5**********7*****************************r   c                    dd} t          dd| d           }|                    dd          }|j        }d }||u }|st          j        d	|fd
||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}|j        }d}||k    }|st          j        d|fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}d}g }|j        }	|	}|	sd}
|
}||v }|sddt          j                    v st          j        |          rt          j        |          ndt          j        |	          dz  }|                    |           |	s.ddt          j        |
          iz  }|                    |           t          j        |d          i z  }t          j        d|fd||f          t          j        |          |dz  }dd|iz  }t          t          j
        |                    d x}x}x}x}x}	}
d S )Nr!   c                H    t           j                            | ddd d           )Nr%   r&   )r'   r(   r)   )r*   r+   s     r   r-   zOtest_coingecko_client_429_after_retries_returns_stale_not_crash.<locals>.opener!   s     l$$S#~tTJJJr   r#   r   c                    d S r   r   )ss    r   <lambda>zQtest_coingecko_client_429_after_retries_returns_stale_not_crash.<locals>.<lambda>#   s    hl r   )r.   r/   r-   r1   r2   r3   )is)z-%(py2)s
{%(py2)s = %(py0)s.price
} is %(py5)sr=   rC   rD   rE   staler4   rB   429 z*%(py7)s
{%(py7)s = %(py5)s.error_message
})r<   rE   z%(py10)sr@   )in)z%(py1)s in (%(py13)s))r6   py13zassert %(py15)spy15rF   )r   rH   rQ   rI   rJ   rN   rO   rP   rK   rL   rM   rR   error_messagerG   _format_boolop)r-   rS   r=   rY   r`   rU   r[   ra   rT   @py_assert6@py_assert9rV   r_   @py_format12@py_format14@py_format16s                   r   ?test_coingecko_client_429_after_retries_returns_stale_not_crashrv       s   K K K KAf^l^lmmmF##Iu55E;$;$;$55;$*7*7**********7************5*****5**********7***************************///U(/(/(/B/B/5///////////////U/////U//////(/////////////(/////B///////////////////////////5//////5////////////////////////////////////r   )r   r   )
__future__r   builtinsrN   _pytest.assertion.rewrite	assertionrewriterI   urllib.errorr'   decimalr   jarvis_finance.market.providersr   r   rb   rv   r   r   r   <module>r      s    " " " " " "                         ; ; ; ; ; ;( ( ( ( ( ( ( (+ + + + 0 0 0 0 0 0r   