~/cs2613/labs/L17Complete Exercise 3.8. This only needs a few lines of code added to your solution to 3.6.
Question for your journal: where should the added error check go, and why?
Here we need to do something new, to write a test that checks for an exception
def test_exception():
with pytest.raises(RuntimeError) as e_info:
prices = parse_csv('Data/prices.csv', select=['name','price'], has_headers=False)
RuntimeError? Why or why not?This is a modified version of Exercise 3.12.
Update your report2.py so that it does not directly import import csv, but rather read_portfolio calls parse_csv from fileparse.py.
Use an appropriate import statement for parse_csv, do not copy
that code into report2.py
make sure that the existing tests continue to pass, along with the following.
def test_prices():
portfolio = read_portfolio('Data/portfolio.csv')
prices = { s['name']: s['price'] for s in portfolio }
assert prices['AA'] == pytest.approx(32.2,abs=0.001)
assert prices['GE'] == pytest.approx(40.37,abs=0.001)
prices?class Stock:
def init(self, name, shares, price):
self.name=name
self.shares=shares
self.price=price
cost and sell to your Stock class so that the following tests pass.def test_cost2():
s = Stock('GOOG', 100, 490.10)
assert s.cost() == pytest.approx(49010.0,0.001)
def test_sell():
s = Stock('GOOG', 100, 490.10)
s.sell(25)
assert s.shares == 75
assert s.cost() == pytest.approx(36757.5, 0.001)
Stock class so that the following test passes.def test_repr():
goog = Stock('GOOG', 100, 490.1)
assert repr(goog) == "Stock('GOOG', 100, 490.1)"