本文整理匯總了Python中money.Money.from_string方法的典型用法代碼示例。如果您正苦於以下問題:Python Money.from_string方法的具體用法?Python Money.from_string怎麽用?Python Money.from_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類money.Money
的用法示例。
在下文中一共展示了Money.from_string方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_price_attribute
# 需要導入模塊: from money import Money [as 別名]
# 或者: from money.Money import from_string [as 別名]
def test_price_attribute(self):
e = SimpleMoneyModel()
e.price = Money(3, "BGN")
self.assertEqual(e.price, Money(3, "BGN"))
e.price = Money.from_string("BGN 5.0")
self.assertEqual(e.price, Money(5, "BGN"))
示例2: to_python
# 需要導入模塊: from money import Money [as 別名]
# 或者: from money.Money import from_string [as 別名]
def to_python(self, value):
if value is None:
return value
if isinstance(value, Money):
return value
elif isinstance(value, Decimal):
return Money(value)
else:
m = self.postgres_money_re.match(value)
if m is not None:
return Money(amount=m.group(1), currency=m.group(2))
else:
return Money.from_string(value)
示例3: test_string_parse_default_currency
# 需要導入模塊: from money import Money [as 別名]
# 或者: from money.Money import from_string [as 別名]
def test_string_parse_default_currency():
value = Money.from_string("100.0")
assert value.amount == Decimal("100.0")
assert value.currency == 'XXX'
assert value.currency == CURRENCY['XXX']
示例4: test_string_parse
# 需要導入模塊: from money import Money [as 別名]
# 或者: from money.Money import from_string [as 別名]
def test_string_parse():
value = Money.from_string("USD 100.0")
assert value.amount == Decimal("100.0")
assert value.currency == 'USD'
assert value.currency == CURRENCY['USD']
示例5: test_price_from_string
# 需要導入模塊: from money import Money [as 別名]
# 或者: from money.Money import from_string [as 別名]
def test_price_from_string(self):
price1 = Money("400", "USD")
price2 = Money.from_string("USD 400")
self.assertEqual(price1, price2)
self.assertEqual(price1.amount, price2.amount)
self.assertEqual(price1.currency, price2.currency)
示例6: test_from_string
# 需要導入模塊: from money import Money [as 別名]
# 或者: from money.Money import from_string [as 別名]
def test_from_string(self):
e = Money.from_string("BGN 5.0")
self.assertEqual(e, Money(5, "BGN"))
e2 = Money.from_string("USD 400")
self.assertEqual(e2, Money(400, "USD"))