本文整理汇总了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"))