
    Lrdj                    t    d dl mZ d dlZd dlmc mZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ ddZddZddZdS )    )annotationsN)Path)import_instruments_csv)connect_memory)apply_migrationstmp_pathr   returnNonec                   | dz  }|                     dd           t                      }t          |           t          ||dd          }t          ||dd          }|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}}|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                                          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 S )Ninstruments.csvzasset_class,name,ticker,isin,exchange,currency,country,sector,data_provider_primary,notes
equity,Demo Global AG,DGA,CH0000000001,SIX,CHF,CH,Technology,dummy,Synthetic only
utf-8encodingTcommitsource_filename   ==z0%(py2)s
{%(py2)s = %(py0)s.rows_new
} == %(py5)sfirstpy0py2py5assert %(py7)spy7)z5%(py2)s
{%(py2)s = %(py0)s.rows_existing
} == %(py5)ssecond%SELECT COUNT(*) AS n FROM instrumentsnz%(py1)s == %(py4)spy1py4assert %(py6)spy6)
write_textr   r   r   rows_new
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationrows_existingexecutefetchone)r   pathconnr   r   @py_assert1@py_assert4@py_assert3@py_format6@py_format8@py_assert0@py_assert2@py_format5@py_format7s                 z/home/agent/.hermes/worktrees/FinanceManager-sprint7-postfinance-portfolio-source/tests/unit/test_importers_instruments.py-test_instruments_import_commit_and_idempotentr@   
   s   ''DOO	^    
 DT"4dL]^^^E#D$tM^___F>Q>Q>Q55>Q$1$1$$$$$$$$$$1$$$$$$$$$$$$6$$$$$6$$$$$$$$$$1$$$$$$$$$$$$$$$$$$$$$$$$$$$<<?@@IIKKCPUTUUPTUUUUUUUUUUUPTUUUUUUPUUUUTUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU    c                   | dz  }|                     dd           t                      }t          |           t          ||dd          }|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}}|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                                          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 S )Nr   zasset_class,name,ticker,isin,exchange,currency,country,sector,data_provider_primary,notes
etf,Demo World ETF,DWLD,CH0000000002,SIX,CHF,CH,Diversified,dummy,Synthetic only
r   r   Fr   r   r   r   resultr   r   r   
dry_run_okz.%(py2)s
{%(py2)s = %(py0)s.status
} == %(py5)sr   r    r   r!   r"   r%   r&   )r'   r   r   r   r(   r)   r*   r+   r,   r-   r.   r/   r0   statusr2   r3   r   r4   r5   rC   r6   r7   r8   r9   r:   r;   r<   r=   r>   s                r?   'test_instruments_dry_run_does_not_writerH      s   ''DOO	]    
 DT#D$uN_```F?a?a?a66?a=(L(=L((((((((((=L((((((((((((6(((((6((((((=((((L(((((((((((((((((((((((((((<<?@@IIKKCPUTUUPTUUUUUUUUUUUPTUUUUUUPUUUUTUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUrA   c                   | dz  }|                     dd           t                      }t          |           t          ||dd          }|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}}|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}	|j        d         }|	|v }
|
slt          j        d|
fd|	|f          t          j
        |	          t          j
        |          dz  }dd|iz  }t          t          j        |                    d x}	x}
}d S )Nzbad_instruments.csvzPasset_class,name,ticker,isin,exchange,currency
equity,,DGA,CH0000000001,SIX,CHF
r   r   Tr   r   r   )z3%(py2)s
{%(py2)s = %(py0)s.rows_failed
} == %(py5)srC   r   r   r   failedrE   namer   )in)z%(py1)s in %(py4)sr"   r%   r&   )r'   r   r   r   rows_failedr)   r*   r+   r,   r-   r.   r/   r0   rF   errorsrG   s                r?   2test_instruments_import_collects_validation_errorsrO   -   s   ++DOO	-    
 DT#D$tMbcccF""""""""""""""""""""""""6"""""6"""""""""""""""""""""""""""""""""""""=$H$=H$$$$$$$$$$=H$$$$$$$$$$$$6$$$$$6$$$$$$=$$$$H$$$$$$$$$$$$$$$$$$$$$$$$$$$%V]1%%6%%%%%%%%%%%6%%%%%%6%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%rA   )r   r   r	   r
   )
__future__r   builtinsr+   _pytest.assertion.rewrite	assertionrewriter)   pathlibr   +jarvis_finance.imports.instruments_importerr   jarvis_finance.storage.databaser   !jarvis_finance.storage.migrationsr   r@   rH   rO    rA   r?   <module>rZ      s    " " " " " "                     N N N N N N : : : : : : > > > > > >V V V V$V V V V"& & & & & &rA   