Created
June 7, 2025 16:46
-
-
Save disouzam/f28b6ca60269f5ee436f4e386da7ee43 to your computer and use it in GitHub Desktop.
Exemplo de uso do pytest em exercício do curso de Modelagem Termodinâmica em Python, ofertado pela PUC-Rio, professor Rogério Navarro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
import funcoes.equacoes_estado_gases as eeg | |
case1 = ( | |
1.1832, | |
4.0968e-05, | |
2850016, | |
1e-05, | |
450, | |
10000, | |
2577431, | |
) | |
case2_ZeroIteracoes = ( | |
1.8387931464126321, | |
4.096836227333333e-05, | |
522.4468683497639, | |
1e-05, | |
244.4144144144144, | |
10000, | |
522.4468683497639, | |
) | |
case2_ZeroIteracoes_chute_alterado = ( | |
1.8387931464126321, | |
4.096836227333333e-05, | |
2000, | |
1e-05, | |
244.4144144144144, | |
10000, | |
522.4468683497639, | |
) | |
case3_ZeroIteracoes = ( | |
1.1027692986392794, | |
4.096836227333333e-05, | |
5840181.684586025, | |
1e-05, | |
485.8858858858859, | |
10000, | |
5840181.684586025, | |
) | |
arg_values = [ | |
pytest.param(*case1, id="case1"), | |
pytest.param(*case2_ZeroIteracoes, id="case2_ZeroIteracoes"), | |
pytest.param( | |
*case2_ZeroIteracoes_chute_alterado, id="case2_ZeroIteracoes_chute_alterado" | |
), | |
pytest.param(*case3_ZeroIteracoes, id="case3_ZeroIteracoes"), | |
] | |
@pytest.mark.parametrize( | |
"a,b,initial_pressure_guess,tolerance,temperature,max_iterations,expected_psat_PR", | |
arg_values, | |
) | |
def test_calculate_vle_pressure_and_fugacity( | |
a, | |
b, | |
initial_pressure_guess, | |
tolerance, | |
temperature, | |
max_iterations, | |
expected_psat_PR, | |
): | |
psat_PR = eeg.calculate_vle_pressure_and_fugacity( | |
temperature, | |
a, | |
b, | |
initial_pressure_guess, | |
tolerance=tolerance, | |
max_iterations=max_iterations, | |
) | |
print(f"Expected value: {expected_psat_PR:.4f} - Current answer: {psat_PR:.4f}") | |
assert psat_PR == pytest.approx(expected_psat_PR, abs=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O código do módulo
funcoes.equacoes_estado_gases
é de autoria do professor Rogério Navarro da PUC-Rio e não está disponível nesse Gist. Apenas código de autoria integral minha está apresentado.O curso do professor Rogério Navarro pode ser consultado nessa URL https://ccec.puc-rio.br/site/Folder?nCurso=modelagem-termodinamica-em-python&nInst=CCE