本文整理汇总了Python中song2.Schema.make方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.make方法的具体用法?Python Schema.make怎么用?Python Schema.make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类song2.Schema
的用法示例。
在下文中一共展示了Schema.make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rewritable
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_rewritable(self):
s = Schema.make(v=String().rewritable())(v='test')
eq_(s['v'], 'test')
s['v'] = 'new value'
eq_(s['v'], 'new value')
s.update(v='new value2')
eq_(s['v'], 'new value2')
s.update({'v' : 'new value3'})
eq_(s['v'], 'new value3')
示例2: test_valid_tuple
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_valid_tuple(self):
s = Schema.make(v=IntArray())(v=(1, 2))
eq_(s['v'], (1, 2))
示例3: test_not_rewritable_direct
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_not_rewritable_direct(self):
s = Schema.make(v=String())(v='test')
s['v'] = 'new value'
示例4: Person
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
from benchmarker import Benchmarker
from song2 import Schema
from song2.types import *
Comment = Schema.make(name=String(), message=String())
Address = Schema.make(country=String(), city=String())
class Person(Schema):
name = String()
age = Int()
hobbies = ArrayOf(str)
comments = ArrayOf(Comment)
address = Nested(Address)
class Person2(Schema):
merge_optional = True
name = String()
age = Int()
hobbies = ArrayOf(str)
comments = ArrayOf(Comment)
address = Nested(Address)
loop = 50000
示例5: test_make_flags
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_make_flags(self):
S = Schema.make(allow_optional=False, merge_optional=True, immutable=False, v=String())
eq_(S.allow_optional, False)
eq_(S.merge_optional, True)
eq_(S.immutable, False)
示例6: test_valid
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_valid(self):
s = Schema.make(v=Int())(v=123)
eq_(s['v'], 123)
示例7: test_invalid
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_invalid(self):
Schema.make(v=Int())(v='test')
示例8: test_valid_dict
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_valid_dict(self):
s = Schema.make(v=StringDict(int))(v={'f1': 1, 'f2' : 2})
eq_(s['v'], {'f1': 1, 'f2' : 2})
示例9: test_invalid_key_type
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_invalid_key_type(self):
Schema.make(v=StringDict(int))(v={0: 1})
示例10: test_invalid_value_type
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_invalid_value_type(self):
Schema.make(v=DictOf(str, int))(v={'f1': 'INVALID'})
示例11: test_valie_is_not_nullable
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_valie_is_not_nullable(self):
Schema.make(v=DictOf(str, int, value_nullable=False))(v={'f1': None})
示例12: test_invalid_element
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_invalid_element(self):
Schema.make(v=IntArray())(v=['test', 1])
示例13: test_default
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_default(self):
s = Schema.make(v=StringValue(default='ok'))()
eq_(s['v'], 'ok')
示例14: test_valie_is_nullable_by_default
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_valie_is_nullable_by_default(self):
s = Schema.make(v=StringDict(int))(v={'f1': None})
eq_(s['v'], {'f1': None})
示例15: test_not_nullable
# 需要导入模块: from song2 import Schema [as 别名]
# 或者: from song2.Schema import make [as 别名]
def test_not_nullable(self):
Schema.make(v=Int())(v=None)