def test_round_context_override(self):
        import decimal

        x = Money(amount='2.5', currency=self.USD)
        assert x.round(0) == Money(amount=2, currency=self.USD)
        x = Money(amount='3.5', currency=self.USD)
        assert x.round(0) == Money(amount=4, currency=self.USD)

        with decimal.localcontext() as ctx:
            ctx.rounding = decimal.ROUND_HALF_UP
            x = Money(amount='2.5', currency=self.USD)
            assert x.round(0) == Money(amount=3, currency=self.USD)
            x = Money(amount='3.5', currency=self.USD)
            assert x.round(0) == Money(amount=4, currency=self.USD)
    def test_round_context_override(self):
        import decimal

        x = Money(amount='2.5', currency=self.USD)
        assert x.round(0) == Money(amount=2, currency=self.USD)
        x = Money(amount='3.5', currency=self.USD)
        assert x.round(0) == Money(amount=4, currency=self.USD)

        with decimal.localcontext() as ctx:
            ctx.rounding = decimal.ROUND_HALF_UP
            x = Money(amount='2.5', currency=self.USD)
            assert x.round(0) == Money(amount=3, currency=self.USD)
            x = Money(amount='3.5', currency=self.USD)
            assert x.round(0) == Money(amount=4, currency=self.USD)
 def test_round(self):
     x = Money(amount='1234.33569', currency=self.USD)
     assert x.round(-4) == Money(amount='0', currency=self.USD)
     assert x.round(-3) == Money(amount='1000', currency=self.USD)
     assert x.round(-2) == Money(amount='1200', currency=self.USD)
     assert x.round(-1) == Money(amount='1230', currency=self.USD)
     assert x.round(0) == Money(amount='1234', currency=self.USD)
     assert x.round(None) == Money(amount='1234', currency=self.USD)
     assert x.round(1) == Money(amount='1234.3', currency=self.USD)
     assert x.round(2) == Money(amount='1234.34', currency=self.USD)
     assert x.round(3) == Money(amount='1234.336', currency=self.USD)
     assert x.round(4) == Money(amount='1234.3357', currency=self.USD)
 def test_round(self):
     x = Money(amount='1234.33569', currency=self.USD)
     assert x.round(-4) == Money(amount='0', currency=self.USD)
     assert x.round(-3) == Money(amount='1000', currency=self.USD)
     assert x.round(-2) == Money(amount='1200', currency=self.USD)
     assert x.round(-1) == Money(amount='1230', currency=self.USD)
     assert x.round(0) == Money(amount='1234', currency=self.USD)
     assert x.round(None) == Money(amount='1234', currency=self.USD)
     assert x.round(1) == Money(amount='1234.3', currency=self.USD)
     assert x.round(2) == Money(amount='1234.34', currency=self.USD)
     assert x.round(3) == Money(amount='1234.336', currency=self.USD)
     assert x.round(4) == Money(amount='1234.3357', currency=self.USD)
Beispiel #5
0
 def test_round(self):
     x = Money(amount="1234.33569", currency=self.USD)
     assert x.round(-4) == Money(amount="0", currency=self.USD)
     assert x.round(-3) == Money(amount="1000", currency=self.USD)
     assert x.round(-2) == Money(amount="1200", currency=self.USD)
     assert x.round(-1) == Money(amount="1230", currency=self.USD)
     assert x.round(0) == Money(amount="1234", currency=self.USD)
     assert x.round(None) == Money(amount="1234", currency=self.USD)
     assert x.round(1) == Money(amount="1234.3", currency=self.USD)
     assert x.round(2) == Money(amount="1234.34", currency=self.USD)
     assert x.round(3) == Money(amount="1234.336", currency=self.USD)
     assert x.round(4) == Money(amount="1234.3357", currency=self.USD)