File tree 2 files changed +61
-0
lines changed
2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments