本文整理匯總了Python中ming.base.Object.make_safe方法的典型用法代碼示例。如果您正苦於以下問題:Python Object.make_safe方法的具體用法?Python Object.make_safe怎麽用?Python Object.make_safe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ming.base.Object
的用法示例。
在下文中一共展示了Object.make_safe方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_safe
# 需要導入模塊: from ming.base import Object [as 別名]
# 或者: from ming.base.Object import make_safe [as 別名]
def test_safe(self):
now = datetime.now()
oid = ObjectId()
safe_obj = Object(
a=[1,2,3],
b=dict(a=12),
c=[ 'foo', 1, 1L, 1.0, now,
Decimal('0.3'), None, oid ])
safe_obj.make_safe()
self.assertEqual(safe_obj, dict(
a=[1,2,3], b=dict(a=12),
c=[ 'foo', 1, 1L, 1.0, now,
0.3, None, oid ]))
unsafe_obj = Object(
my_tuple=(1,2,3))
self.assertRaises(AssertionError, unsafe_obj.make_safe)
示例2: test_safe
# 需要導入模塊: from ming.base import Object [as 別名]
# 或者: from ming.base.Object import make_safe [as 別名]
def test_safe(self):
now = datetime.now()
oid = ObjectId()
c = [ 'foo', 1, 1.0, now,
Decimal('0.3'), None, oid ]
if six.PY2:
c = [ 'foo', 1, long(1), 1.0, now,
Decimal('0.3'), None, oid ]
safe_obj = Object(
a=[1,2,3],
b=dict(a=12),
c=c)
safe_obj.make_safe()
expected = Object(
a=[1,2,3], b=dict(a=12),
c=c)
self.assertTrue(expected, safe_obj)
unsafe_obj = Object(
my_tuple=(1,2,3))
self.assertRaises(AssertionError, unsafe_obj.make_safe)