Skip to content

Commit

Permalink
construindo test do core
Browse files Browse the repository at this point in the history
  • Loading branch information
hyslan committed Aug 27, 2024
1 parent bc29145 commit 6c28e0b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
11 changes: 11 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ipython = "^8.26.0"
[tool.poetry.group.types.dependencies]
types-openpyxl = "^3.1.5.20240822"
pandas-stubs = "^2.2.2.240807"
types-tqdm = "^4.66.0.20240417"

[tool.poetry.group.test.dependencies]
pytest-mock = "^3.14.0"
Expand Down Expand Up @@ -78,3 +79,6 @@ ignore = ["S603", "S607"]

[tool.ruff]
line-length = 128

[tool.pytest.ini_options]
pythonpath = ["."]
8 changes: 4 additions & 4 deletions python/src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import contextlib
import logging
import time
from typing import tuple

import numpy as np
import pywintypes
Expand Down Expand Up @@ -250,7 +249,7 @@ def consulta_status_ordem(
cod_mun: str,
sessions: win32com.client.CDispatch,
revalorar: bool,
) -> tuple[str, str, str, str, str, str, str, str] | True:
) -> tuple[str, str, str, str, str, str, str, str] | bool:
"""Consulta o status de uma ordem.
Args:
Expand Down Expand Up @@ -426,7 +425,7 @@ def process_precificador(
cod_mun: str,
principal_tse: str,
start_time: float,
) -> True | tuple[list[str], list[str], list[str]]:
) -> bool | tuple[list[str], list[str], list[str]]:
"""Processo de precificação se aplicável.
Args:
Expand Down Expand Up @@ -760,7 +759,8 @@ def val(
limite_execucoes = len(pendentes_array)
# * In case of null Df.
if limite_execucoes == 0:
return
msg = "Nenhuma ordem para ser valorada."
raise ValueError(msg)

try:
sessions: win32com.client.CDispatch = sap.listar_sessoes(n_con)
Expand Down
41 changes: 37 additions & 4 deletions python/test/test_core.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
"""Módulo de testes do módulo core."""

from unittest.mock import MagicMock

import pandas as pd
import pytest

from src.core import val

pendentest_array = pd.DataFrame(["2425188908", "100", "4600041302"], index=[0], columns=["Ordem", "COD_MUNICIPIO", "Contrato"])

@pytest.fixture
def mock_session(mocker) -> MagicMock:
"""Mock session for testing purposes."""
mock_get_object = mocker.patch("src.core.win32com.client.GetObject")
mock_sap_gui = MagicMock()
mock_get_object.return_value.GetScriptingEngine.return_value.Connections = "mock_connections"
return mock_sap_gui


df_test = pd.DataFrame([["2425188908", "100"]], index=[0], columns=["Ordem", "COD_MUNICIPIO"])
pendentes_array = df_test.to_numpy()


def test_core_val(capsys, mock_session: MagicMock) -> None:
"""Teste do módulo core.val.
Args:
----
mock_session (MagicMock): Mock session for testing purposes.
"""
revalorar = False
contrato = "4600041302"
token = ""
n_con = 0
# Test case 1: Valid input
val(pendentes_array, session=mock_session, contrato=contrato, revalorar=revalorar, token=token, n_con=n_con)
# Capturar a Saída
captured = capsys.readouterr()
print(captured.out)

def test_core_val():
val()
# TODO: Implementar testes
# Test case 2: Empty input
msg = "Nenhuma ordem para ser valorada."
with pytest.raises(ValueError, match=msg):
val(pendentes_array=0, session=mock_session, contrato=None, revalorar=False, token="", n_con=0)

0 comments on commit 6c28e0b

Please sign in to comment.