#!/usr/bin/python
#-*- coding: utf-8 -*-

import json
import os
import pytest
import subprocess
from pathlib import Path

from cocomico.pipeline import benchmark_mode , run_mode

# Create a temporary output directory, using pytest fixtures


package_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
cocomico_data_path = os.path.join(package_path, 'src', 'cocomico', 'toys')


json_path_banchmark = os.path.join(*[cocomico_data_path, 'communities.json'])
seed_path = os.path.join(*[cocomico_data_path, 'seeds.sbml'])
sbml_path_runs = os.path.join(*[cocomico_data_path, 'sbml/'])


# Use the fixture in a test by passing its name as a parameter
def test_benchmark_function_compare_expected_values_vs_test_values(output_path_factory):
    output_path=str(output_path_factory)
    print(output_path)
    print("*** Test benchmark mode ***")
    benchmark_mode(json_path_banchmark,seed_path,sbml_path_runs, output_path)
    
    # print(" ****  Begin check creation lp files  ******")
    # # Variable with results we expect for lp files during the pytest on bench and run mode
    # bacteria_lp_O_test=3
    # bacteria_lp_1_test=4
    # bacteria_lp_2_test=2
    # reactant_lp_O_test=43
    # reactant_lp_1_test=59
    # reactant_lp_2_test=30
    # reaction_lp_O_test=42
    # reaction_lp_1_test=58
    # reaction_lp_2_test=30
    # product_lp_O_test=44
    # product_lp_1_test=61
    # product_lp_2_test=32
    # species_lp_O_test=37
    # species_lp_1_test=50
    # species_lp_2_test=25
    # seed_lp=3
    # seed_lp_1_test=3
    # seed_lp_2_test=3

    # #Paths for test lp files generated by py test
    # lp0_path= os.path.join(*[output_path, 'instance_community', 'draft0.lp'])
    # lp1_path= os.path.join(*[output_path, 'instance_community', 'draft1.lp'])
    # lp2_path= os.path.join(*[output_path, 'instance_community', 'draft2.lp'])

    # #Check conformity 
    # assert bacteria_lp_O_test == lcount('bacteria', lp0_path)
    # assert bacteria_lp_1_test == lcount('bacteria', lp1_path)
    # assert bacteria_lp_2_test == lcount('bacteria', lp2_path)

    # assert reactant_lp_O_test == lcount('reactant', lp0_path)
    # assert reactant_lp_1_test == lcount('reactant', lp1_path)
    # assert reactant_lp_2_test == lcount('reactant', lp2_path)

    # assert reaction_lp_O_test == lcount('reaction', lp0_path)
    # assert reaction_lp_1_test == lcount('reaction', lp1_path)
    # assert reaction_lp_2_test == lcount('reaction', lp2_path)

    # assert product_lp_O_test == lcount('product', lp0_path)
    # assert product_lp_1_test == lcount('product', lp1_path)
    # assert product_lp_2_test == lcount('product', lp2_path)

    # assert species_lp_O_test == lcount('species', lp0_path)
    # assert species_lp_1_test == lcount('species', lp1_path)
    # assert species_lp_2_test == lcount('species', lp2_path)

    # assert seed_lp == lcount('seed', lp0_path)
    # assert seed_lp_1_test == lcount('seed', lp1_path)
    # assert seed_lp_2_test == lcount('seed', lp2_path)

    # os.remove(lp0_path)
    # os.remove(lp1_path)
    # os.remove(lp2_path)
    # print(" ****  lp files  created and conformed ******\n")


    ##### New step  #####

    print(" *** Check creation vocab  *** ")

    #Variable with results we expect for vocab files during the pytest on bench and run mode    

    escope0={'M_C_c', 'M_B_c', 'M_A_c', 'M_Y_c'}    
    escope1={'M_P_c', 'M_K_c', 'M_B_c', 'M_N_c', 'M_Z_c', 'M_C_c', 'M_A_c', 'M_Y_c'}    
    escope2={'M_K_c'}   
    cscope0={'M_W_c', 'M_X_c', 'M_Y_c', 'M_Q_c', 'M_M_c', 'M_F_c', 'M_A2_c', 'M_E_c', 'M_A_c', 'M_F2_c', 'M_D_c', 'M_P_c', 'M_G_c', 'M_X1_c', 'M_O_c', 'M_B2_c', 'M_H_c', 'M_C_c', 'M_I_c', 'M_S_c', 'M_V_c', 'M_C2_c', 'M_B_c'}    
    cscope1={'M_W_c', 'M_X_c', 'M_Y_c', 'M_D3_c', 'M_F_c', 'M_E_c', 'M_B3_c', 'M_F2_c', 'M_N_c', 'M_O_c', 'M_I_c', 'M_V_c', 'M_G3_c', 'M_C2_c', 'M_B_c', 'M_Z_c', 'M_K_c', 'M_Q_c', 'M_M_c', 'M_E3_c', 'M_A2_c', 'M_A_c', 'M_F3_c', 'M_D_c', 'M_P_c', 'M_G_c', 'M_A3_c', 'M_X1_c', 'M_H_c', 'M_B2_c', 'M_C_c', 'M_S_c'} 
    cscope2={'M_X_c', 'M_K_c', 'M_G_c', 'M_X1_c', 'M_H_c', 'M_C_c', 'M_I_c', 'M_B3_c', 'M_F2_c', 'M_D_c'}   
    commensalism0=[4]   
    commensalism1=[8]   
    commensalism2=[1]   
    pscope0={'M_Q_c', 'M_A_c', 'M_C2_c', 'M_B2_c', 'M_J_c', 'M_F2_c', 'M_F_c', 'M_M_c', 'M_W_c', 'M_X_c', 'M_B_c', 'M_A2_c', 'M_D_c', 'M_S_c', 'M_Y_c', 'M_I_c', 'M_C_c', 'M_P_c', 'M_G_c', 'M_O_c', 'M_H_c', 'M_V_c'}  
    pscope1={'M_Q_c', 'M_A_c', 'M_C2_c', 'M_B2_c', 'M_J_c', 'M_F2_c', 'M_F_c', 'M_M_c', 'M_W_c', 'M_K_c', 'M_X_c', 'M_B_c', 'M_A2_c', 'M_G3_c', 'M_E3_c', 'M_D_c', 'M_S_c', 'M_N_c', 'M_Y_c', 'M_I_c', 'M_D3_c', 'M_A3_c', 'M_B3_c', 'M_F3_c', 'M_C_c', 'M_P_c', 'M_G_c', 'M_O_c', 'M_Z_c', 'M_H_c', 'M_V_c'}   
    pscope2={'M_D_c', 'M_I_c', 'M_F2_c', 'M_B3_c', 'M_C_c', 'M_G_c', 'M_K_c', 'M_Z_c', 'M_X_c', 'M_H_c'}    
    limiting_subtrate0={'M_A_c', 'M_Y_c', 'M_X1_c', 'M_C_c', 'M_B_c', 'M_E_c', 'M_F_c'} 
    limiting_subtrate1={'M_K_c', 'M_A_c', 'M_Y_c', 'M_X1_c', 'M_C_c', 'M_E_c', 'M_Z_c', 'M_P_c', 'M_N_c', 'M_B_c', 'M_F_c'} 
    limiting_subtrate2={'M_K_c', 'M_X1_c'}  
    scope0={'M_C_c', 'M_S_c', 'M_X_c', 'M_B2_c', 'M_A2_c', 'M_W_c', 'M_A_c', 'M_M_c', 'M_P_c', 'M_D_c', 'M_B_c', 'M_V_c', 'M_F2_c', 'M_I_c', 'M_J_c', 'M_Q_c', 'M_Y_c', 'M_H_c', 'M_F_c', 'M_E_c', 'M_X1_c', 'M_O_c', 'M_C2_c', 'M_G_c'}    
    scope1={'M_F3_c', 'M_N_c', 'M_A2_c', 'M_B2_c', 'M_A_c', 'M_X1_c', 'M_W_c', 'M_M_c', 'M_D_c', 'M_Z_c', 'M_G_c', 'M_I_c', 'M_P_c', 'M_F_c', 'M_K_c', 'M_D3_c', 'M_Y_c', 'M_X_c', 'M_O_c', 'M_E_c', 'M_Q_c', 'M_H_c', 'M_J_c', 'M_F2_c', 'M_A3_c', 'M_G3_c', 'M_B3_c', 'M_S_c', 'M_V_c', 'M_B_c', 'M_C_c', 'M_C2_c', 'M_E3_c'} 
    scope2={'M_G_c', 'M_B3_c', 'M_H_c', 'M_E_c', 'M_I_c', 'M_F_c', 'M_K_c', 'M_F2_c', 'M_C_c', 'M_X1_c', 'M_X_c', 'M_D_c', 'M_Z_c'} 
    scope_reaction0={'R_D_X', 'R_C2_B2rev', 'R_V_Brev', 'R_X_G', 'R_W_B', 'R_D_Xrev', 'R_N_M', 'R_AZ_W', 'R_A_S', 'R_C_C2rev', 'R_F_Mrev', 'R_G_H', 'R_V_B', 'R_M_O', 'R_E_V', 'R_Q_A', 'R_G_Hrev', 'R_A_Srev', 'R_C_C2', 'R_C_PY', 'R_I_H', 'R_F_M', 'R_T_S', 'R_K_H', 'R_W_A2', 'R_A2_B2rev', 'R_F2_Crev', 'R_W_A2rev', 'R_O_P',   'R_X1_F2', 'R_F2_C', 'R_C2_B2', 'R_H_C', 'R_I_Hrev', 'R_X_Grev', 'R_Y_W', 'R_M_Qrev', 'R_Q_Arev', 'R_B_JD', 'R_A2_B2', 'R_O_Prev', 'R_M_Q'}
    scope_reaction1={'R_D3_E3', 'R_H_C', 'R_V_B', 'R_F_M', 'R_B3_Krev', 'R_G3_F3', 'R_K_H', 'R_AZ_W', 'R_D3_E3rev', 'R_E3_F3', 'R_N_D3', 'R_C_C2rev', 'R_C3_N', 'R_X_G', 'R_W_B', 'R_F2_Crev', 'R_A2_B2', 'R_W_A2rev', 'R_X1_F2', 'R_N_D3rev', 'R_C3_K', 'R_A3_Prev', 'R_M_Qrev', 'R_B_JD', 'R_I_Hrev', 'R_A_Srev', 'R_A2_B2rev', 'R_D_X', 'R_Y_W', 'R_X_Grev', 'R_E_V', 'R_D_Xrev', 'R_N_M', 'R_V_Brev', 'R_O_P', 'R_G3_A3', 'R_C_PY', 'R_C2_B2', 'R_A3_P', 'R_I_H', 'R_G3_A3rev', 'R_G_H', 'R_W_A2', 'R_A_S', 'R_M_Q', 'R_Q_Arev', 'R_F_Mrev', 'R_T_S', 'R_C_C2', 'R_X1_ZB3', 'R_B3_K', 'R_G_Hrev', 'R_F2_C', 'R_C2_B2rev', 'R_Q_A', 'R_E3_F3rev', 'R_O_Prev', 'R_M_O'}

    scope_reaction2={'R_G3_A3rev', 'R_G3_A3', 'R_K_H', 'R_D_X', 'R_C3_K', 'R_N_D3', 'R_G3_F3', 'R_X_G', 'R_F2_Crev', 'R_D_Xrev', 'R_D3_E3rev', 'R_A3_P', 'R_B3_K', 'R_X1_F2', 'R_G_H', 'R_E3_F3rev', 'R_F2_C', 'R_H_C', 'R_I_Hrev', 'R_X_Grev', 'R_N_D3rev', 'R_G_Hrev', 'R_X1_ZB3', 'R_B_JD', 'R_D3_E3', 'R_E3_F3', 'R_B3_Krev',   'R_C3_N', 'R_A3_Prev', 'R_I_H'}

    #Paths vocab files
    vocab0_path= os.path.join(*[output_path, 'community_description', 'vocab_com_0.json'])
    vocab1_path= os.path.join(*[output_path, 'community_description', 'vocab_com_1.json'])
    vocab2_path= os.path.join(*[output_path, 'community_description', 'vocab_com_2.json'])


    vocab0 = json.loads(open(vocab0_path, 'r').read())
    vocab1 = json.loads(open(vocab1_path, 'r').read())
    vocab2 = json.loads(open(vocab2_path, 'r').read())

    #Check conformity
    assert set(escope0) == set(vocab0['escope'])
    assert set(escope1)== set(vocab1['escope'])
    assert set(escope2) == set(vocab2['escope'])

    assert set(cscope0) == set(vocab0['cscope'])
    assert set(cscope1)== set(vocab1['cscope'])
    assert set(cscope2) == set(vocab2['cscope'])

    assert commensalism0 == vocab0['commensalism']
    assert commensalism1== vocab1['commensalism']
    assert commensalism2 == vocab2['commensalism']

    assert set(pscope0) == set(vocab0['pscope'])
    assert set(pscope1)== set(vocab1['pscope'])
    assert set(pscope2) == set(vocab2['pscope'])

    assert set(limiting_subtrate0) == set(vocab0['limiting_subtrate'])
    assert set(limiting_subtrate1)== set(vocab1['limiting_subtrate'])
    assert set(limiting_subtrate2) == set(vocab2['limiting_subtrate'])

    assert set(scope0) == set(vocab0['scope'])
    assert set(scope1)== set(vocab1['scope'])
    assert set(scope2) == set(vocab2['scope'])
    

    assert set(scope_reaction0) == set(vocab0['scope_reaction'])
    assert set(scope_reaction1)== set(vocab1['scope_reaction'])
    assert set(scope_reaction2) == set(vocab2['scope_reaction'])

    os.remove(vocab0_path)
    os.remove(vocab1_path)
    os.remove(vocab2_path)
    print(" ****  vocab files  created and conformed ******\n")




    ##### New step  #####




    print(" *** Check creation metrics json files  *** ")
    # Variable with results we expect for metrics files during the pytest on bench and run mode
    # Metrics results community 0
    production_value0=22
    production_value0_community=11
    production_value0_individual=11
    cooperation_score0=10.0
    cooperation_score0_exchanged_metabolites=4
    cooperation_score0_producteur=4.5
    cooperation_score0_consommateur=5.5
    reaction_production0=40
    reaction_production0_community=23
    second_competition_score0=2.6666666666666665
    redondante_limiting0=8
    # Metrics results community 1
    production_value1=31
    production_value1_community=17
    production_value1_individual=14
    cooperation_score1=18.0
    cooperation_score1_exchanged_metabolites=8
    cooperation_score1_producteur=8.5
    cooperation_score1_consommateur=9.5
    reaction_production1=58
    reaction_production1_community=37
    second_competition_score1=3.25
    redondante_limiting1=13
    # Metrics results community 2
    production_value2=10
    production_value2_community=5
    production_value2_individual=5
    cooperation_score2=2
    cooperation_score2_exchanged_metabolites=1
    cooperation_score2_producteur=1
    cooperation_score2_consommateur=1
    reaction_production2=17
    reaction_production2_community=10
    second_competition_score2=1.5
    redondante_limiting2=3

    #Paths metrics files
    metrics0_path= os.path.join(*[output_path, 'community_scores', 'metrics_com_0.json'])
    metrics1_path= os.path.join(*[output_path, 'community_scores', 'metrics_com_1.json'])
    metrics2_path= os.path.join(*[output_path, 'community_scores', 'metrics_com_2.json'])

    metrics0 = json.loads(open(metrics0_path, 'r').read())
    metrics1 = json.loads(open(metrics1_path, 'r').read())
    metrics2 = json.loads(open(metrics2_path, 'r').read())

    #Check conformity
    # assert production_value0 == metrics0['metabolite production value (delta)']
    # assert production_value1== metrics1['metabolite production value (delta)']
    # assert production_value2 == metrics2['metabolite production value (delta)']

    # assert production_value0_community== metrics0['metabolite production value_metric']["added value community"]
    # assert production_value1_community== metrics1['metabolite production value_metric']["added value community"]
    # assert production_value2_community== metrics2['metabolite production value_metric']["added value community"]

    # assert production_value0_individual== metrics0['metabolite production value_metric']["all individual can produce"]
    # assert production_value1_individual== metrics1['metabolite production value_metric']["all individual can produce"]
    # assert production_value2_individual== metrics2['metabolite production value_metric']["all individual can produce"]

    assert cooperation_score0== metrics0['cooP']
    assert cooperation_score1== metrics1['cooP']
    assert cooperation_score2== metrics2['cooP']

    assert cooperation_score0_exchanged_metabolites== metrics0['cooP_metric']["number of exchanged metabolites"]
    assert cooperation_score1_exchanged_metabolites== metrics1['cooP_metric']["number of exchanged metabolites"]
    assert cooperation_score2_exchanged_metabolites== metrics2['cooP_metric']["number of exchanged metabolites"]

    assert cooperation_score0_producteur== metrics0['cooP_metric']["pi producers"]
    assert cooperation_score1_producteur== metrics1['cooP_metric']["pi producers"]
    assert cooperation_score2_producteur== metrics2['cooP_metric']["pi producers"]

    assert cooperation_score0_consommateur== metrics0['cooP_metric']["pi consumers"]
    assert cooperation_score1_consommateur== metrics1['cooP_metric']["pi consumers"]
    assert cooperation_score2_consommateur== metrics2['cooP_metric']["pi consumers"]

    # assert reaction_production0== metrics0['reaction production(rho)']
    # assert reaction_production1== metrics1['reaction production(rho)']
    # assert reaction_production2== metrics2['reaction production(rho)']

    # assert reaction_production0_community== metrics0['reaction production_metric']["added value comunity"]
    # assert reaction_production1_community== metrics1['reaction production_metric']["added value comunity"]
    # assert reaction_production2_community== metrics2['reaction production_metric']["added value comunity"]

    assert round(second_competition_score0)== round(metrics0['comP'])
    assert second_competition_score1== metrics1['comP']
    assert second_competition_score2== metrics2['comP']

    assert redondante_limiting0== metrics0['comP_metric']["total number of limited subtrates"]
    assert redondante_limiting1== metrics1['comP_metric']["total number of limited subtrates"]
    assert redondante_limiting2 == metrics2['comP_metric']["total number of limited subtrates"]

    print(" ****  Metrics files  created and conformed ******\n \n")

    os.remove(metrics0_path)
    os.remove(metrics1_path)
    os.remove(metrics2_path)
    print(" ****  End test Benchmark mode  ******\n \n")










def test_run_function_compare_expected_values_vs_test_values(output_path_factory):
    print("*** TEST RUNS MODE ***")
    output_path=str(output_path_factory)
    run_mode(sbml_path_runs,seed_path, output_path)
    
    # print(" ****  Begin check creation lp files  ******")
    # # Variable with results we expect for lp files during the pytest on bench and run mode
    # bacteria_lp_O_test=7
    # reactant_lp_O_test=102
    # reaction_lp_O_test=100
    # product_lp_O_test=105
    # species_lp_O_test=87
    # seed_lp=3
    # #Paths for test lp
    # lp0_path= os.path.join(*[output_path, 'instance_community', 'draft0.lp'])

    # #Check conformity
    # assert bacteria_lp_O_test == lcount('bacteria', lp0_path)
    # assert reactant_lp_O_test == lcount('reactant', lp0_path)
    # assert reaction_lp_O_test == lcount('reaction', lp0_path)
    # assert product_lp_O_test == lcount('product', lp0_path)
    # assert species_lp_O_test == lcount('species', lp0_path)
    # assert seed_lp == lcount('seed', lp0_path)

    # print(" ****  lp files  created and conformed ******\n")

    # os.remove(lp0_path)


    # ##### New step  #####



    # print(" *** Check creation vocab  *** ")

    # #Variable with results we expect for vocab files during the pytest on bench and run mode    
        
    # escope0={'M_K_c', 'M_Y_c', 'M_W_c', 'M_B2_c', 'M_B_c', 'M_H_c', 'M_D_c', 'M_N_c', 'M_P_c', 'M_A_c', 'M_C_c', 'M_Z_c', 'M_I_c', 'M_A2_c', 'M_C2_c', 'M_G_c', 'M_X_c'}

    # cscope0={'M_E_c', 'M_K_c', 'M_M_c', 'M_G_c', 'M_B_c', 'M_F2_c', 'M_H_c', 'M_D_c', 'M_V_c', 'M_G3_c', 'M_Z_c', 'M_A2_c', 'M_X1_c', 'M_Y_c', 'M_A3_c', 'M_Q_c', 'M_S_c', 'M_W_c', 'M_E3_c', 'M_B3_c', 'M_D3_c', 'M_B2_c', 'M_C2_c', 'M_N_c', 'M_A_c', 'M_C_c', 'M_F_c', 'M_I_c', 'M_F3_c', 'M_P_c', 'M_X_c', 'M_O_c'}
    # commensalism0=[17]
    # pscope0={'M_K_c', 'M_S_c', 'M_M_c', 'M_Y_c', 'M_W_c', 'M_E3_c', 'M_B3_c', 'M_B2_c', 'M_O_c', 'M_B_c', 'M_F2_c', 'M_H_c', 'M_D_c', 'M_V_c', 'M_F3_c', 'M_G3_c', 'M_N_c', 'M_P_c', 'M_D3_c', 'M_A_c', 'M_C_c', 'M_F_c', 'M_Z_c', 'M_I_c', 'M_A2_c', 'M_J_c', 'M_C2_c', 'M_G_c', 'M_X_c', 'M_A3_c', 'M_Q_c'}

    # limiting_subtrate0={'M_E_c', 'M_K_c', 'M_X_c', 'M_W_c', 'M_G_c', 'M_B2_c', 'M_B_c', 'M_H_c', 'M_D_c', 'M_N_c', 'M_P_c', 'M_A_c', 'M_C_c', 'M_F_c', 'M_Z_c', 'M_I_c', 'M_A2_c', 'M_C2_c', 'M_X1_c', 'M_Y_c'}
    # scope0={'M_E_c', 'M_K_c', 'M_M_c', 'M_G_c', 'M_B_c', 'M_F2_c', 'M_H_c', 'M_D_c', 'M_V_c', 'M_G3_c', 'M_Z_c', 'M_A2_c', 'M_J_c', 'M_X1_c', 'M_Y_c', 'M_A3_c', 'M_Q_c', 'M_S_c', 'M_W_c', 'M_E3_c', 'M_B3_c', 'M_D3_c', 'M_B2_c', 'M_C2_c', 'M_N_c', 'M_A_c', 'M_C_c', 'M_F_c', 'M_I_c', 'M_F3_c', 'M_P_c', 'M_X_c', 'M_O_c'}

    # scope_reaction0={'R_W_A2rev', 'R_K_H', 'R_I_Hrev', 'R_F_Mrev', 'R_B3_Krev', 'R_A3_P', 'R_C3_K', 'R_Q_A', 'R_W_A2', 'R_Q_Arev', 'R_D3_E3rev', 'R_AZ_W', 'R_C2_B2', 'R_B3_K', 'R_G_H', 'R_X_Grev', 'R_V_Brev', 'R_C_PY', 'R_D3_E3', 'R_B_JD', 'R_V_B', 'R_X1_ZB3', 'R_A2_B2', 'R_F_M', 'R_X1_F2', 'R_T_S', 'R_E_V', 'R_M_Q', 'R_W_B', 'R_C_C2rev', 'R_O_P', 'R_D_X', 'R_C3_N', 'R_O_Prev', 'R_N_D3rev', 'R_E3_F3rev', 'R_M_Qrev', 'R_G_Hrev', 'R_A3_Prev', 'R_A_Srev', 'R_N_M', 'R_A2_B2rev', 'R_Y_W', 'R_C2_B2rev', 'R_F2_Crev', 'R_E3_F3', 'R_N_D3', 'R_G3_F3', 'R_I_H', 'R_D_Xrev', 'R_X_G', 'R_G3_A3', 'R_C_C2', 'R_G3_A3rev', 'R_F2_C', 'R_H_C', 'R_A_S', 'R_M_O'}



    # #Paths for vocab
    # vocab0_path= os.path.join(*[output_path, 'community_description', 'vocab_sbml.json'])
    # vocab0 = json.loads(open(vocab0_path, 'r').read())

 
    # #Check conformity
    # assert set(escope0) == set(vocab0['escope'])
    # assert set(cscope0) == set(vocab0['cscope'])
    # assert commensalism0 == vocab0['commensalism']
    # assert set(pscope0) == set(vocab0['pscope'])
    # assert set(limiting_subtrate0) == set(vocab0['limiting_subtrate'])
    # assert set(scope0) == set(vocab0['scope'])
    # assert set(scope_reaction0) == set(vocab0['scope_reaction'])

    # os.remove(vocab0_path)
    # print(" ****  vocab files  created and conformed ******\n")



    ##### New step  #####



    print(" *** Check creation metrics json files  *** ")

    # Variable with results we expect for metrics files during the pytest on bench and run mode

    # Metrics results community 0
    production_value0=31
    production_value0_community=17
    production_value0_individual=14
    cooperation_score0=65.125
    cooperation_score0_exchanged_metabolites=17
    cooperation_score0_producteur=24.375
    cooperation_score0_consommateur=40.75
    reaction_production0=101
    reaction_production0_community=63
    second_competition_score0=5.999999999999998
    redondante_limiting0=42

    #Path for metric
    metrics0_path= os.path.join(*[output_path, 'community_scores', 'metrics_sbml.json'])
    metrics0 = json.loads(open(metrics0_path, 'r').read())

    #Check conformity
    # assert production_value0 == metrics0['metabolite production value (delta)']
    # assert production_value0_community== metrics0['metabolite production value_metric']["added value community"]
    # assert production_value0_individual== metrics0['metabolite production value_metric']["all individual can produce"]
    assert cooperation_score0== metrics0['cooP']
    assert cooperation_score0_exchanged_metabolites== metrics0['cooP_metric']["number of exchanged metabolites"]
    assert cooperation_score0_producteur== metrics0['cooP_metric']["pi producers"]
    assert cooperation_score0_consommateur== metrics0['cooP_metric']["pi consumers"]
    # assert reaction_production0== metrics0['reaction production(rho)']
    # assert reaction_production0_community== metrics0['reaction production_metric']["added value comunity"]
    assert round(second_competition_score0)== round(metrics0['comP'])
    assert redondante_limiting0== metrics0['comP_metric']["total number of limited subtrates"]

    os.remove(metrics0_path)
    sample_path= os.path.join(*[sbml_path_runs, 'sbml.json'])
    os.remove(sample_path)

    print(" ****  Metrics files  created and conformed ******\n")

    print(" ****  End test Runs mode  ******\n \n")

def lcount(keyword, fname):
    with open(fname, 'r') as fin:
        return sum([1 for line in fin if keyword in line])

@pytest.fixture(scope="session")
def output_path_factory(tmp_path_factory):
    return Path(tmp_path_factory.mktemp("output_dir"))


