Ë
    Bp±jÀ  ã                   óò  — d Z ddlZddlmc mZ ddlZddlZddl	Z	ddl
Z
ddlZddlZej                  j                  ej                  j!                  ej                  j#                  e«      d«      «      ZdZej                  j!                  edd«      Zedfd„Zej.                  j0                  ej.                  j3                  ej                  j5                  e«       d	¬
«       G d„ d«      «       «       Zy)u  
Slow acceptance test: verifies the full train_mlp â†’ validate_strategy pipeline.

Marked @pytest.mark.slow â€” skipped by default in quick test runs.
Run with: /usr/bin/python3 -m pytest tests/test_acceptance_mlp.py -m slow -s

What it checks:
  1. train_mlp.py --smoke produces a valid weights artifact.
  2. The artifact loads, has the expected structure, and feature_cols match FEATURE_COLS.
  3. validate_strategy.py with the artifact's recommended_thresholds runs successfully
     and returns finite (non-NaN, non-None) metrics.
é    Nz..z/usr/bin/python3ÚdatazCOINBASE_BTCUSD-6H.csvi,  c                 ó:   — t        j                  | |dd|¬«      }|S )NT)ÚcwdÚcapture_outputÚtextÚtimeout)Ú
subprocessÚrun)Úcmdr   r   Úresults       új/Users/jameslopez/projects/TradingBot25/.worktrees/mlp-comparable-measurement/tests/test_acceptance_mlp.pyÚ_runr      s"   € Ü�^‰^Ø� T°¸gô€Fð €Mó    zdata CSV not found)Úreasonc                   ó   — e Zd Zd„ Zd„ Zy)ÚTestAcceptanceMLPc                 óf  — t        |dz  «      }t        t        ddt        dd|g«      }|j                  }d}||k(  }|sÝt        j                  d|fd||f«      d	t        j                  «       v st        j                  |«      rt        j                  |«      nd	t        j                  |«      t        j                  |«      d
œz  }t        j                  d|j                  › d|j                  › �«      dz   d|iz  }t        t        j                  |«      «      ‚d x}x}}t         j"                  }|j$                  } ||«      }	|	�s t        j                  d«      dz   dt        j                  «       v st        j                  t         «      rt        j                  t         «      ndt        j                  |«      t        j                  |«      dt        j                  «       v st        j                  |«      rt        j                  |«      ndt        j                  |	«      dœz  }t        t        j                  |«      «      ‚d x}x}}	t'        |«      5 }
t)        j*                  |
«      }d d d «       j,                  }d} ||«      }d}||k(  }|sÕt        j                  d|fd||f«      dt        j                  «       v st        j                  |«      rt        j                  |«      ndt        j                  |«      t        j                  |«      t        j                  |«      t        j                  |«      dœz  }dd|iz  }t        t        j                  |«      «      ‚d x}x}x}x}}g }d}||v }|}|r|d   }t/        |«      }d}||k\  }|}|�sˆt        j                  d|fd||f«      t        j                  |«      dt        j                  «       v st        j                  |«      rt        j                  |«      nddœz  }d d|iz  }|j1                  |«       |r¼t        j                  d!fd"f«      d#t        j                  «       v st        j                  t.        «      rt        j                  t.        «      nd#t        j                  «      t        j                  |«      t        j                  |«      d$œz  }d%d&|iz  }|j1                  |«       t        j2                  |d«      i z  }d'd(|iz  }t        t        j                  |«      «      ‚d x}x}x}x}x}x}x}}|j,                  }d)} ||«      }g d*¢}||k(  }|sýt        j                  d|fd||f«      dt        j                  «       v st        j                  |«      rt        j                  |«      ndt        j                  |«      t        j                  |«      t        j                  |«      t        j                  |«      dœz  }t        j                  d+|j-                  d)«      › �«      d,z   d|iz  }t        t        j                  |«      «      ‚d x}x}x}x}}d-}|j,                  }d.}	i } ||	|«      }||v }|sét        j                  d|fd/||f«      t        j                  |«      dt        j                  «       v st        j                  |«      rt        j                  |«      ndt        j                  |«      t        j                  |	«      t        j                  |«      t        j                  |«      d0œz  }d1d2|iz  }t        t        j                  |«      «      ‚d x}x}x}x}	x}}t4        j"                  j7                  dt8        «       dd3lm}m}  ||«      }|d4   }||k(  }|s¯t        j                  d|fd5||f«      t        j                  |«      d6t        j                  «       v st        j                  |«      rt        j                  |«      nd6d7œz  }t        j                  d8«      d9z   d:|iz  }t        t        j                  |«      «      ‚d x}}|d   D �]6  \  } }!t@        jB                  }t@        jD                  } || «      } ||«      }"|"�s]t        j                  d;«      d<z   d=t        j                  «       v st        j                  t@        «      rt        j                  t@        «      nd=t        j                  |«      d=t        j                  «       v st        j                  t@        «      rt        j                  t@        «      nd=t        j                  |«      d>t        j                  «       v st        j                  | «      rt        j                  | «      nd>t        j                  |«      t        j                  |"«      d?œz  }#t        t        j                  |#«      «      ‚d x}x}x}}"t@        jB                  }t@        jD                  } ||!«      } ||«      }"|"�s]t        j                  d@«      d<z   d=t        j                  «       v st        j                  t@        «      rt        j                  t@        «      nd=t        j                  |«      d=t        j                  «       v st        j                  t@        «      rt        j                  t@        «      nd=t        j                  |«      dAt        j                  «       v st        j                  |!«      rt        j                  |!«      ndAt        j                  |«      t        j                  |"«      d?œz  }#t        t        j                  |#«      «      ‚d x}x}x}}"�Œ9 y # 1 sw Y   �	Œ9xY w)BNúmlp_weights_TEST_6H.jsonútools/train_mlp.pyú--dataú--smokeú--outr   ©ú==©z2%(py2)s
{%(py2)s = %(py0)s.returncode
} == %(py5)sr   ©Úpy0Úpy2Úpy5ztrain_mlp --smoke failed:
Ú
ú
>assert %(py7)sÚpy7zArtifact not writtenzd
>assert %(py7)s
{%(py7)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.path
}.exists
}(%(py5)s)
}ÚosÚout)r   r   Úpy4r   r"   Úversioné   )zI%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get
}(%(py4)s)
} == %(py9)sÚpayload)r   r   r%   Úpy6Úpy9zassert %(py11)sÚpy11Úlayersé   ©Úin)z%(py3)s in %(py5)s)Úpy3r   z%(py7)s)ú>=)z4%(py13)s
{%(py13)s = %(py9)s(%(py11)s)
} >= %(py16)sÚlen)r*   r+   Úpy13Úpy16z%(py18)sÚpy18zassert %(py21)sÚpy21Úarch)é1   é   é   r'   z%Smoke arch should be [49,8,4,1], got z
>assert %(py11)sÚrecommended_thresholdsÚtraining)zT%(py1)s in %(py11)s
{%(py11)s = %(py5)s
{%(py5)s = %(py3)s.get
}(%(py7)s, %(py9)s)
})Úpy1r0   r   r"   r*   r+   zassert %(py13)sr3   )ÚFEATURE_COLSÚload_mlp_artifactÚfeature_cols)z%(py1)s == %(py3)sr>   ©r=   r0   zArtifact feature_cols mismatchú
>assert %(py5)sr   zW contains non-finite valuesz…
>assert %(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.all
}(%(py8)s
{%(py8)s = %(py5)s
{%(py5)s = %(py3)s.isfinite
}(%(py6)s)
})
}ÚnpÚW)r   r   r0   r   r)   Úpy8Úpy10zb contains non-finite valuesÚb)#Ústrr   ÚPYTHONÚDATA_6HÚ
returncodeÚ
@pytest_arÚ_call_reprcompareÚ@py_builtinsÚlocalsÚ_should_repr_global_nameÚ	_safereprÚ_format_assertmsgÚstdoutÚstderrÚAssertionErrorÚ_format_explanationr#   ÚpathÚexistsÚopenÚjsonÚloadÚgetr2   ÚappendÚ_format_boolopÚsysÚinsertÚREPOÚstrategies.strategy_mlp_scoresr>   r?   rC   ÚallÚisfinite)$ÚselfÚtmp_pathr$   r   Ú@py_assert1Ú@py_assert4Ú@py_assert3Ú@py_format6Ú@py_format8Ú@py_assert6Úfr(   Ú@py_assert5Ú@py_assert8Ú@py_assert7Ú@py_format10Ú@py_format12Ú@py_assert2Ú@py_assert0Ú@py_assert10Ú@py_assert12Ú@py_assert15Ú@py_assert14Ú@py_format17Ú@py_format19Ú@py_format20Ú@py_format22Ú@py_format14r>   r?   ÚartÚ@py_format4rD   rG   Ú@py_assert9Ú@py_format11s$                                       r   Ú(test_smoke_train_produces_valid_artifactz:TestAcceptanceMLP.test_smoke_train_produces_valid_artifact$   sJ  € Ü�(Ð7Ñ7Ó8ˆÜ”vÐ3Ø¤¨)°W¸cðCó Dˆà× Ñ ð 	
 Að 	
Ð  AÑ%÷ 	
ïé ó	
Ð  A÷ 	
ò 	
ç	�6÷	
ò 	
ïé ð ÷ 	
ñ 	
ç 	�	ð ÷ 	
ò 	
ç 	�	ð !÷ 	
ð 	
ç 	�	ð %&÷ 	
õ 	
ïé ð *¨&¯-©-¨¸¸6¿=¹=¸/ÐJ÷	
÷ 	
ö 	
ïé ÷	
÷ 	
ô �w‰wÐ:ˆw�~‰~Ð:‰~˜cÓ"Ð:Ò"×:Ö:Ð$:×:×:×:×:×:Ó:Œr×:×:Ó:Œr×:×:Ô:ˆw×:×:Ò:ˆ~×:×:×:×:×:Ð:˜c×:×:Ó:˜c×:×:Ô:Ð"×:×:×:×:×:Ô:ä�#ŒY˜!Ü—i‘i “lˆG÷ ð �{‰{Ð*˜9Ð*‰{˜9Ó%Ð*¨Ð*Ð%¨Ñ*×*×*Õ*Ð%¨×*×*×*×*×*Ñ*ˆw×*×*Ó*ˆw×*×*Ô*ˆ{×*×*Ò*˜9×*×*Ò*Ð%×*×*Ò*¨×*×*×*×*×*×*×*ÙBˆxÐBˆx˜7Ð"ÔB¨7°8Ñ+<ÐB¤sÐ+<Ó'=ÐBÀÐBÐ'=ÀÑ'B×B×B×BÐBˆx˜7×B×BÓBˆx×B×B×B×B×BÐB˜7×B×BÓB˜7×B×B×B×B×B×B×BÐ'=À×B×B×B×B×BÑB¤s×B×BÓB¤s×B×BÔBÐ+<×B×BÒBÐ'=×B×BÒBÀ×B×B×B×B×B×B×B×B×B×B×B×B×BÖBØ�{‰{ð 	
˜6ð 	
‰{˜6Ó"ð 	
¢mð 	
Ð" mÑ3÷ 	
ïé ó	
Ð" m÷ 	
ò 	
ç	�6÷	
ò 	
ïé ð ÷ 	
ñ 	
ç 	�	ð ÷ 	
ò 	
ç 	�	ð ÷ 	
ð 	
ç 	�	ð "÷ 	
ð 	
ç 	�	ð #÷ 	
ð 	
ç 	�	ð '4÷ 	
õ 	
ïé ð 4°G·K±KÀÓ4GÐ3HÐI÷	
÷ 	
ö 	
ïé ÷	
÷ 	
ó 	
ð (ÐF¨7¯;©;ÐF°zÐFÀ2ÐF©;°zÀ2Ó+FÐFÐ'Ð+FÐF×F×FÕFÐ'Ð+F×F×FÓFÐ'×F×F×F×F×FÐF¨7×F×FÓF¨7×F×FÔF¨;×F×FÒF°z×F×FÒFÀ2×F×FÒFÐ+F×F×F×F×F×F×F×FÑFä�‰�‰˜œ4Ô ßRÙ Ó$ˆØ�>Ñ"ÐTÐ" lÑ2×T×TÕTÐ" l×T×TÓTÐ"×T×T×T×T×TÐT l×T×TÓT l×T×T×TÑTÐ4T×T×T×T×T×TÖTØ˜•M‰DˆAˆqÜ—6‘6ÐIœ"Ÿ+™+ÐI™+ a›.ÐI‘6˜.Ó)ÐIÒ)×IÖIÐ+I×I×I×I×I×IÓI”2×I×IÓI”2×I×IÔI�6×I×I×I×I×IÐIœ"×I×IÓIœ"×I×IÔI˜+×I×I×I×I×IÐI a×I×IÓI a×I×IÔI˜.×I×IÒIÐ)×I×I×I×I×IÖIÜ—6‘6ÐIœ"Ÿ+™+ÐI™+ a›.ÐI‘6˜.Ó)ÐIÒ)×IÖIÐ+I×I×I×I×I×IÓI”2×I×IÓI”2×I×IÔI�6×I×I×I×I×IÐIœ"×I×IÓIœ"×I×IÔI˜+×I×I×I×I×IÐI a×I×IÓI a×I×IÔI˜.×I×IÒIÐ)×I×I×I×I×I×IÐIñ "÷ ‰Yús   Én&î&n0c                 ó|  ‡— t        |dz  «      }t        t        ddt        dd|g«      }|j                  }d}||k(  }|sÐt        j                  d|fd||f«      d	t        j                  «       v st        j                  |«      rt        j                  |«      nd	t        j                  |«      t        j                  |«      d
œz  }t        j                  d|j                  › �«      dz   d|iz  }t        t        j                  |«      «      ‚d x}x}}t        |«      5 }	t!        j"                  |	«      }
d d d «       
d   d   }||j%                  dd«      |j%                  dd«      |j%                  dd«      |j%                  dd«      |j%                  dd«      |j%                  dd«      ddddœ
}t        |dz  «      }t        |d«      5 }	t!        j&                  ||	«       d d d «       t        t        ddt        ddd |gd!¬"«      }|j                  }d}||k(  }|sÝt        j                  d|fd||f«      d#t        j                  «       v st        j                  |«      rt        j                  |«      nd#t        j                  |«      t        j                  |«      d
œz  }t        j                  d$|j(                  › d%|j                  › �«      dz   d|iz  }t        t        j                  |«      «      ‚d x}x}}|j(                  }d&}||v }|sµt        j                  d'|fd(||f«      t        j                  |«      d)t        j                  «       v st        j                  |«      rt        j                  |«      nd)d*œz  }t        j                  d+|d d, › �«      d-z   d.|iz  }t        t        j                  |«      «      ‚d x}}|j+                  «       D ]B  Šd/‰j-                  «       v sŒt/        ˆfd0„d1D «       «      sŒ+t1        j2                  d2‰› �«       ŒD y # 1 sw Y   �ŒðxY w# 1 sw Y   �ŒOxY w)3Nr   r   r   r   r   r   r   r   Útrain_resultr   ztrain_mlp failed:
r!   r"   r<   r;   Ú!i_long_entry_activation_thresholdg        Ú i_long_exit_activation_thresholdÚ-i_long_exit_activation_confirmation_thresholdÚi_use_long_exit_confirmationg      ð?Úi_use_long_entry_confirmationFÚi_trailing_stop_thresholdg     @�À)
Úmlp_weights_filer…   r†   r‡   rˆ   r‰   rŠ   Úi_regime_windowÚi_regime_entry_min_scoreÚi_mvrv_suppress_bearztest_params.jsonÚwzstrategies/validate_strategy.pyz--strategy_filezstrategy_mlp_scores.pyz--params_fileéx   )r   Úvalidate_resultzvalidate_strategy failed:
r    zTotal Tradesr.   )z%(py1)s in %(py3)sÚout_textrA   z!Expected metrics in output, got:
iÐ  rB   r   Únanc              3   ó&   •K  — | ]  }|‰v –— Œ
 y ­w)N© )Ú.0ÚkwÚlines     €r   Ú	<genexpr>zNTestAcceptanceMLP.test_validate_strategy_runs_with_artifact.<locals>.<genexpr>i   s   øè ø€ Ð,^ÑB]¸B¨R°4¬ZÑB]ùs   ƒ)ÚCalmarÚSharpezP&LzNaN found in metric line: )rH   r   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rT   rU   rV   rY   rZ   r[   r\   ÚdumprS   Ú
splitlinesÚlowerÚanyÚpytestÚfail)re   rf   r$   r„   rg   rh   ri   rj   rk   rm   r(   ÚrecÚparamsÚparams_filer‘   r’   rt   rs   r   r˜   s                      @r   Ú)test_validate_strategy_runs_with_artifactz;TestAcceptanceMLP.test_validate_strategy_runs_with_artifact?   sä  ø€ Ü�(Ð7Ñ7Ó8ˆÜœVÐ%9Ø%¤w°	¸7ÀCðIó Jˆà×&Ñ&ð 	
¨!ð 	
Ð&¨!Ñ+÷ 	
ïé ó	
Ð&¨!÷ 	
ò 	
ç	�6÷	
ò 	
ïé ð ÷ 	
ñ 	
ç 	�	ð ÷ 	
ò 	
ç 	�	ð '÷ 	
ð 	
ç 	�	ð +,÷ 	
õ 	
ïé ð " ,×"5Ñ"5Ð!6Ð7÷	
÷ 	
ö 	
ïé ÷	
÷ 	
ô �#ŒY˜!Ü—i‘i “lˆG÷ à�jÑ!Ð":Ñ;ˆà #Ø14·±Ð9\Ð^aÓ1bØ03·±Ð8ZÐ\_Ó0`Ø=@¿W¹WÐEtÐvyÓ=zØ,/¯G©GÐ4RÐTWÓ,XØ-0¯W©WÐ5TÐV[Ó-\Ø),¯©Ð1LÈcÓ)RØ Ø(/Ø$)ñ
ˆô ˜(Ð%7Ñ7Ó8ˆÜ�+˜sÔ# qÜ�I‰I�f˜aÔ ÷ $ô ÜÐ5Ø”gØÐ7Ø˜[ð	 
ð
 ôˆð ×)Ñ)ð 	
¨Qð 	
Ð)¨QÑ.÷ 	
ïé ó	
Ð)¨Q÷ 	
ò 	
ç	�6÷	
ò 	
ïé ð ÷ 	
ñ 	
ç 	�	ð ÷ 	
ò 	
ç 	�	ð *÷ 	
ð 	
ç 	�	ð ./÷ 	
õ 	
ïé ð *¨/×*@Ñ*@Ð)AÀÀO×DZÑDZÐC[Ð\÷	
÷ 	
ö 	
ïé ÷	
÷ 	
ð #×)Ñ)ˆØð 	
ˆ~ Ð)÷ 	
ïé ó	
ˆ~ ÷ 	
ñ 	
ç 	�	ð ÷ 	
ñ 	
ç	�6÷	
ò 	
ïé ð "*÷ 	
ñ 	
ç 	�	ð "*÷ 	
÷ 	
ïé ð 1°¸%¸4°Ð0AÐB÷	
÷ 	
ö 	
ïé ÷	
õ 	
ð ×'Ñ'Ö)ˆDØ˜Ÿ
™
›Ò$¬Ó,^ÑB]Ó,^Õ)^Ü—‘Ð8¸¸Ð?Õ@ñ *÷C ‰Yú÷  $Ñ#ús   Ä P$ÇP1Ð$P.Ð1P;N)Ú__name__Ú
__module__Ú__qualname__r‚   r¥   r•   r   r   r   r   !   s   „ òJó6+Ar   r   )Ú__doc__ÚbuiltinsrN   Ú_pytest.assertion.rewriteÚ	assertionÚrewriterL   rZ   r#   r	   r_   ÚnumpyrC   r    rW   ÚabspathÚjoinÚdirnameÚ__file__ra   rI   rJ   r   ÚmarkÚslowÚskipifrX   r   r•   r   r   Ú<module>r¶      sÏ   ðñ÷ „ ƒÛ 	Û Û 
ã Û à	‡w�w‡��r—w‘w—|‘| B§G¡G§O¡O°HÓ$=¸tÓDÓE€Ø	€Ø
�'‰'�,‰,�t˜VÐ%=Ó
>€ð  ó ð ‡�×ÑØ‡�×Ñ˜Ÿ™Ÿ™ wÓ/Ð/Ð8LÐÓM÷GAð GAó Nó ñGAr   