Skip to content

Commit

Permalink
Clase 16: Uso de Coverage para Medir la Cobertura de Pruebas
Browse files Browse the repository at this point in the history
  • Loading branch information
lcmartinezdev committed Aug 29, 2024
1 parent 37344a1 commit 505a0eb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests==2.32.3
Faker==28.0.0
coverage==7.6.1
4 changes: 0 additions & 4 deletions src/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ def get_location(ip):
"region": data["regionName"],
"city": data["cityName"],
}


if __name__ == "__main__":
print(get_location("8.8.8.8"))
8 changes: 6 additions & 2 deletions tests/test_bank_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def test_deposit_increases_balance_by_deposit_amount(self):
new_balance = self.account.deposit(500)
self.assertEqual(new_balance, 1500, "El balance no es igual")

def test_withdraw_decreases_balance_by_withdraw_amount(self):
@patch("src.bank_account.datetime")
def test_withdraw_decreases_balance_by_withdraw_amount(self, mock_datetime):
mock_datetime.now.return_value.hour = 10
new_balance = self.account.withdraw(200)
self.assertEqual(new_balance, 800, "El balance no es igual")

Expand All @@ -37,7 +39,9 @@ def test_withdraw_logs_each_transaction(self):
self.account.deposit(500)
self.assertEqual(self._count_lines(self.account.log_file), 2)

def test_withdraw_raises_error_when_insufficient_funds(self):
@patch("src.bank_account.datetime")
def test_withdraw_raises_error_when_insufficient_funds(self, mock_datetime):
mock_datetime.now.return_value.hour = 10
with self.assertRaises(InsufficientFundsError):
self.account.withdraw(2000)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ def test_divide(self):
result = divide(10, 2)
expected = 5
assert result == expected

def test_divide_by_zero(self):
with self.assertRaises(ValueError):
divide(10, 0)

0 comments on commit 505a0eb

Please sign in to comment.