forked from dabeaz-course/practical-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stock_pytest.py
More file actions
32 lines (24 loc) · 889 Bytes
/
Copy pathtest_stock_pytest.py
File metadata and controls
32 lines (24 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# test_sotck_pytest.py
import stock
import pytest
@pytest.fixture()
def stock_sample():
return stock.Stock('GOOG', 100, 490.1)
def test_create_stock(stock_sample):
assert stock_sample.name == 'GOOG'
assert stock_sample.shares == 100
assert stock_sample.price == 490.1
def test_stock_cost(stock_sample):
assert stock_sample.cost == 49010.0
def test_stock_raises_if_type_data_shares_is_not_int(stock_sample):
with pytest.raises(TypeError):
stock_sample.shares = '100'
def test_stock_raises_if_type_data_name_is_not_str(stock_sample):
with pytest.raises(TypeError):
stock_sample.name = 100
def test_stock_raises_if_type_data_price_is_not_float(stock_sample):
with pytest.raises(TypeError):
stock_sample.price = 100
def test_selling_shares(stock_sample):
stock_sample.sell(25)
assert stock_sample.shares == 75