Skip to content

Commit 7e22781

Browse files
author
krsm
committed
adding more tests, using class.
1 parent cdbad58 commit 7e22781

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Unitests/pystest_stdy/bank.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
4+
Simple study related to pytest
5+
6+
"""
7+
8+
9+
class InsufficientAmount(Exception):
10+
pass
11+
12+
13+
class BankAccount(object):
14+
15+
def __init__(self, initial_amount=0):
16+
self.current_balance = initial_amount
17+
18+
def withdrawal_cash(self, amount):
19+
if self.current_balance < amount:
20+
raise InsufficientAmount("Not enough cash to spend!{}".format(amount))
21+
self.current_balance -= amount
22+
23+
def deposit_cash(self, amount):
24+
self.current_balance += amount

Unitests/pystest_stdy/test_bank.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
4+
Simple study related to pytest
5+
6+
"""
7+
8+
import pytest
9+
from Unitests.pystest_stdy.bank import BankAccount, InsufficientAmount
10+
11+
12+
def test_default_initial_amount():
13+
bank_account = BankAccount()
14+
assert bank_account.current_balance == 0
15+
16+
17+
def test_setting_initial_amount():
18+
bank_account = BankAccount(100)
19+
assert bank_account.current_balance == 100
20+
21+
22+
def test_bank_account_deposit_cash():
23+
bank_account = BankAccount(100)
24+
bank_account.deposit_cash(90)
25+
assert bank_account.current_balance == 190
26+
27+
28+
def test_bank_account_withdrawal_cash():
29+
bank_account = BankAccount(100)
30+
bank_account.withdrawal_cash(90)
31+
assert bank_account.current_balance == 10
32+
33+
34+
def test_bank_account_raises_exception():
35+
bank_account = BankAccount()
36+
with pytest.raises(InsufficientAmount):
37+
bank_account.withdrawal_cash(100)

0 commit comments

Comments
 (0)