def test_sell():
    p = Portfolio()
    p.buy("MSFT", 100, 27.0)
    p.buy("DELL", 100, 17.0)
    p.buy("ORCL", 100, 34.0)
    p.sell("MSFT", 50)
    assert p.cost() == 6450
def test_dont_own_it():
    p = Portfolio()  # What, again!?!?
    p.buy("MSFT", 100, 27.0)  #  |
    p.buy("DELL", 100, 17.0)  #  |
    p.buy("ORCL", 100, 34.0)  #  /
    with pytest.raises(ValueError):
        p.sell("IBM", 1)
예제 #3
0
 def test_sell(self):
     p = Portfolio()
     p.buy("MSFT", 100, 27.0)
     p.buy("DELL", 100, 17.0)
     p.buy("ORCL", 100, 34.0)
     p.sell("MSFT", 50)
     self.assertCostEqual(p, 6450)
예제 #4
0
 def test_not_enough(self):
     p = Portfolio()  # Didn't I just do this?
     p.buy("MSFT", 100, 27.0)
     p.buy("DELL", 100, 17.0)
     p.buy("ORCL", 100, 34.0)
     with self.assertRaises(ValueError):
         p.sell("MSFT", 200)
예제 #5
0
 def test_dont_own_it(self):
     p = Portfolio()  # What, again!?!?
     p.buy("MSFT", 100, 27.0)
     p.buy("DELL", 100, 17.0)
     p.buy("ORCL", 100, 34.0)
     with self.assertRaises(ValueError):
         p.sell("IBM", 1)
def test_not_enough():
    p = Portfolio()  # Didn't I just do this?
    p.buy("MSFT", 100, 27.0)  #  |
    p.buy("DELL", 100, 17.0)  #  |
    p.buy("ORCL", 100, 34.0)  #  /
    with pytest.raises(ValueError):
        p.sell("MSFT", 200)
예제 #7
0
def test_sell():
    p = Portfolio()
    p.buy("MSFT", 100, 27.0)
    p.buy("DELL", 100, 17.0)
    p.buy("ORCL", 100, 34.0)
    p.sell("MSFT", 50)
    assert_cost_equal(p, 6450)
예제 #8
0
def test_dont_own_it():
    p = Portfolio()                 # What, again!?!?
    p.buy("MSFT", 100, 27.0)
    p.buy("DELL", 100, 17.0)
    p.buy("ORCL", 100, 34.0)
    with pytest.raises(ValueError):
        p.sell("IBM", 1)
예제 #9
0
파일: test_port5.py 프로젝트: nedbat/test0
 def test_sell(self):
     p = Portfolio()
     p.buy("MSFT", 100, 27.0)
     p.buy("DELL", 100, 17.0)
     p.buy("ORCL", 100, 34.0)
     p.sell("MSFT", 50)
     self.assertCostEqual(p, 6450)
예제 #10
0
def test_not_enough():
    p = Portfolio()                 # Didn't I just do this?
    p.buy("MSFT", 100, 27.0)
    p.buy("DELL", 100, 17.0)
    p.buy("ORCL", 100, 34.0)
    with pytest.raises(ValueError):
        p.sell("MSFT", 200)
예제 #11
0
class PortfolioSellTest(PortfolioTestCase):
    # Invoked before each test method
    def setUp(self):
        self.p = Portfolio()
        self.p.buy("MSFT", 100, 27.0)
        self.p.buy("DELL", 100, 17.0)
        self.p.buy("ORCL", 100, 34.0)

    def test_sell(self):
        self.p.sell("MSFT", 50)
        self.assertCostEqual(self.p, 6450)

    def test_not_enough(self):
        with self.assertRaises(ValueError):
            self.p.sell("MSFT", 200)

    def test_dont_own_it(self):
        with self.assertRaises(ValueError):
            self.p.sell("IBM", 1)
예제 #12
0
파일: test_port6.py 프로젝트: nedbat/test0
class PortfolioSellTest(PortfolioTestCase):
    # Invoked before each test method
    def setUp(self):
        self.p = Portfolio()
        self.p.buy("MSFT", 100, 27.0)
        self.p.buy("DELL", 100, 17.0)
        self.p.buy("ORCL", 100, 34.0)

    def test_sell(self):
        self.p.sell("MSFT", 50)
        self.assertCostEqual(self.p, 6450)

    def test_not_enough(self):
        with self.assertRaises(ValueError):
            self.p.sell("MSFT", 200)

    def test_dont_own_it(self):
        with self.assertRaises(ValueError):
            self.p.sell("IBM", 1)
예제 #13
0
파일: test_port6.py 프로젝트: nedbat/test0
 def test_bad_input(self):
     p = Portfolio()
     with self.assertRaises(TypeError):
         p.buy("IBM")
예제 #14
0
파일: test_port6.py 프로젝트: nedbat/test0
 def test_buy_two_stocks(self):
     p = Portfolio()
     p.buy("IBM", 100, 176.48)
     p.buy("HPQ", 100, 36.15)
     self.assertCostEqual(p, 21263.0)
예제 #15
0
파일: test_port6.py 프로젝트: nedbat/test0
 def test_buy_one_stock(self):
     p = Portfolio()
     p.buy("IBM", 100, 176.48)
     self.assertCostEqual(p, 17648.0)
def simple_portfolio():
    p = Portfolio()
    p.buy("MSFT", 100, 27.0)
    p.buy("DELL", 100, 17.0)
    p.buy("ORCL", 100, 34.0)
    return p
def test_empty():
    p = Portfolio()
    assert p.cost() == 0.0
예제 #18
0
def test_bad_input():
    p = Portfolio()
    with pytest.raises(TypeError):
        p.buy("IBM")
예제 #19
0
def test_buy_one_stock():
    p = Portfolio()
    p.buy("IBM", 100, 176.48)
    assert_cost_equal(p, 17648.0)
예제 #20
0
 def test_empty(self):
     p = Portfolio()
     self.assertCostEqual(p, 0.0)
예제 #21
0
 def setUp(self):
     self.p = Portfolio()
     self.p.buy("MSFT", 100, 27.0)
     self.p.buy("DELL", 100, 17.0)
     self.p.buy("ORCL", 100, 34.0)
예제 #22
0
 def test_bad_input(self):
     p = Portfolio()
     with self.assertRaises(TypeError):
         p.buy("IBM")
예제 #23
0
 def test_bad_input(self):
     p = Portfolio()
     self.assertRaises(TypeError, p.buy, "IBM")
예제 #24
0
파일: test_port6.py 프로젝트: nedbat/test0
 def setUp(self):
     self.p = Portfolio()
     self.p.buy("MSFT", 100, 27.0)
     self.p.buy("DELL", 100, 17.0)
     self.p.buy("ORCL", 100, 34.0)
def test_buy_two_stocks():
    p = Portfolio()
    p.buy("IBM", 100, 176.48)
    p.buy("HPQ", 100, 36.15)
    assert p.cost() == 21263.0
예제 #26
0
def test_buy_two_stocks():
    p = Portfolio()
    p.buy("IBM", 100, 176.48)
    p.buy("HPQ", 100, 36.15)
    assert_cost_equal(p, 21263.0)
def test_buy_one_stock():
    p = Portfolio()
    p.buy("IBM", 100, 176.48)
    assert p.cost() == 17648.0
예제 #28
0
 def test_buy_one_stock(self):
     p = Portfolio()
     p.buy("IBM", 100, 176.48)
     self.assertCostEqual(p, 17648.0)
def test_bad_input():
    p = Portfolio()
    with pytest.raises(TypeError):
        p.buy("IBM")
예제 #30
0
 def test_buy_two_stocks(self):
     p = Portfolio()
     p.buy("IBM", 100, 176.48)
     p.buy("HPQ", 100, 36.15)
     self.assertCostEqual(p, 21263.0)
예제 #31
0
def simple_portfolio():
    p = Portfolio()
    p.buy("MSFT", 100, 27.0)
    p.buy("DELL", 100, 17.0)
    p.buy("ORCL", 100, 34.0)
    return p