Skip to content

Commit

Permalink
DEV: add testes unitarios
Browse files Browse the repository at this point in the history
  • Loading branch information
vmeazevedo committed Apr 7, 2024
1 parent c256ab7 commit a41e3f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion myCripto-Monitor.py → myCripto_Monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ def criar_tabela():

console.print(table)
print("==============================================================================")
time.sleep(60)
time.sleep(30)
33 changes: 33 additions & 0 deletions test_myCrypto_Monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest
from unittest.mock import patch
from myCripto_Monitor import monitorar_criptomoeda, criar_tabela

class TestMyCriptoMonitor(unittest.TestCase):

@patch('myCripto_Monitor.loop')
@patch('myCripto_Monitor.locale.currency')
@patch('myCripto_Monitor.calc_porc')
def test_monitorar_criptomoeda(self, mock_calc_porc, mock_currency, mock_loop):
# Configurando mocks
mock_loop.side_effect = [100, 110] # Simula valores retornados pela função loop
mock_currency.return_value = "R$100,00" # Simula o valor retornado pela função locale.currency
mock_calc_porc.return_value = "10%" # Simula o valor retornado pela função calc_porc

# Testando monitorar_criptomoeda
valor, porcentagem, estilo = monitorar_criptomoeda('btc', [1.00])
self.assertEqual(valor, "R$100,00")
self.assertEqual(porcentagem, "10%")
self.assertEqual(estilo, "green")

def test_criar_tabela(self):
# Testando criar_tabela
tabela = criar_tabela()
self.assertEqual(len(tabela.columns), 5)
self.assertEqual(tabela.columns[0].name, "Criptomoeda")
self.assertEqual(tabela.columns[1].name, "Valor")
self.assertEqual(tabela.columns[2].name, "Data/Hora")
self.assertEqual(tabela.columns[3].name, "Status")
self.assertEqual(tabela.columns[4].name, "Porcentagem")

if __name__ == '__main__':
unittest.main()

0 comments on commit a41e3f2

Please sign in to comment.