本文整理汇总了Python中song2.Schema类的典型用法代码示例。如果您正苦于以下问题:Python Schema类的具体用法?Python Schema怎么用?Python Schema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rewritable
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
def test_valid_tuple(self):
s = Schema.make(v=IntArray())(v=(1, 2))
eq_(s['v'], (1, 2))
示例3: test_not_rewritable_direct
def test_not_rewritable_direct(self):
s = Schema.make(v=String())(v='test')
s['v'] = 'new value'
示例4: Person
#!/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
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
def test_valid(self):
s = Schema.make(v=Int())(v=123)
eq_(s['v'], 123)
示例7: test_invalid
def test_invalid(self):
Schema.make(v=Int())(v='test')
示例8: test_valid_dict
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
def test_invalid_key_type(self):
Schema.make(v=StringDict(int))(v={0: 1})
示例10: test_invalid_value_type
def test_invalid_value_type(self):
Schema.make(v=DictOf(str, int))(v={'f1': 'INVALID'})
示例11: test_valie_is_not_nullable
def test_valie_is_not_nullable(self):
Schema.make(v=DictOf(str, int, value_nullable=False))(v={'f1': None})
示例12: test_invalid_element
def test_invalid_element(self):
Schema.make(v=IntArray())(v=['test', 1])
示例13: test_default
def test_default(self):
s = Schema.make(v=StringValue(default='ok'))()
eq_(s['v'], 'ok')
示例14: test_valie_is_nullable_by_default
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
def test_not_nullable(self):
Schema.make(v=Int())(v=None)