コード例 #1
0
ファイル: test_port5_pytest.py プロジェクト: nedbat/test0
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)
コード例 #2
0
ファイル: test_port5_pytest.py プロジェクト: nedbat/test0
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)
コード例 #3
0
ファイル: test_port5_pytest.py プロジェクト: nedbat/test0
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)
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
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)
コード例 #9
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 p.cost() == 6450
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)