Exemplo n.º 1
0
  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')
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 def test_not_rewritable_direct(self):
   s = Schema.make(v=String())(v='test')
   s['v'] = 'new value'
Exemplo n.º 4
0
#!/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

with Benchmarker(loop, width=35) as bench:
Exemplo n.º 5
0
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
from song2 import Schema
from song2.types import *

Address = Schema.make(addr=String(), country=String())
Hobby = Schema.make(name=String(), years=Int())


class Prop(Schema):
    text = StringValue()


class Person(Schema):
    name = String()
    age = Int()
    comments = StringArray()
    hobbies = ArrayOf(Hobby)
    address = Nested(Address)
    try_default = StringValue(default='this is default')
    floatproperty = Float()
    longproperty = Long()
    dynamic_dict = StringDict(Prop)


class Rewritable(Schema):
    rewritable_field = String().rewritable()


class DefaultValue(Schema):
    message = String(default='please enter a message')
Exemplo n.º 6
0
 def test_valid(self):
   s = Schema.make(v=Int())(v=123)
   eq_(s['v'], 123)
Exemplo n.º 7
0
 def test_invalid(self):
   Schema.make(v=Int())(v='test')
Exemplo n.º 8
0
 def test_valid_dict(self):
   s = Schema.make(v=StringDict(int))(v={'f1': 1, 'f2' : 2})
   eq_(s['v'], {'f1': 1, 'f2' : 2})
Exemplo n.º 9
0
 def test_invalid_key_type(self):
   Schema.make(v=StringDict(int))(v={0: 1})
Exemplo n.º 10
0
 def test_invalid_value_type(self):
   Schema.make(v=DictOf(str, int))(v={'f1': 'INVALID'})
Exemplo n.º 11
0
 def test_valie_is_not_nullable(self):
   Schema.make(v=DictOf(str, int, value_nullable=False))(v={'f1': None})
Exemplo n.º 12
0
 def test_invalid_key_type(self):
   Schema.make(v=DictOf(int, int))(v={'INVALID': 1})
Exemplo n.º 13
0
 def test_valid_dict(self):
   s = Schema.make(v=DictOf(str, int))(v={'f1': 1, 'f2' : 2})
   eq_(s['v'], {'f1': 1, 'f2' : 2})
Exemplo n.º 14
0
 def test_invalid_element(self):
   Schema.make(v=IntArray())(v=['test', 1])
Exemplo n.º 15
0
 def test_valid_tuple(self):
   s = Schema.make(v=IntArray())(v=(1, 2))
   eq_(s['v'], (1, 2))
Exemplo n.º 16
0
 def test_invalid_value_type(self):
   Schema.make(v=StringDict(int))(v={'f1': 'INVALID'})
Exemplo n.º 17
0
 def test_invalid(self):
   Schema.make(v=StringValue())(v=1234)
Exemplo n.º 18
0
 def test_valie_is_not_nullable(self):
   Schema.make(v=StringDict(int, value_nullable=False))(v={'f1': None})
Exemplo n.º 19
0
 def test_default(self):
   s = Schema.make(v=Int())()
   eq_(s['v'], 0)
Exemplo n.º 20
0
 def test_valie_is_nullable_by_default(self):
   s = Schema.make(v=StringDict(int))(v={'f1': None})
   eq_(s['v'], {'f1': None})
Exemplo n.º 21
0
 def test_not_nullable(self):
   Schema.make(v=Int())(v=None)
Exemplo n.º 22
0
 def test_default(self):
   s = Schema.make(v=String())()
   eq_(s['v'], None)
Exemplo n.º 23
0
#!/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
Exemplo n.º 24
0
 def test_valid(self):
   s = Schema.make(v=StringValue())(v='test')
   eq_(s['v'], 'test')
Exemplo n.º 25
0
 def test_make(self):
   S = Schema.make(v1=String(), v2=Int())
   ok_(isinstance(S.v1, String))
   ok_(isinstance(S.v2, Int))
   ok_(isinstance(S(), Schema))
Exemplo n.º 26
0
 def test_not_nullable_by_default(self):
   Schema.make(v=StringValue())()
Exemplo n.º 27
0
 def test_make_with_invalid_property(self):
   Schema.make(v1=String(), v2='INVALID')
Exemplo n.º 28
0
 def test_not_empty_by_default(self):
   Schema.make(v=StringValue())(v='')
Exemplo n.º 29
0
 def test_not_rewritable_by_merge(self):
   s = Schema.make(v=String())(v='test')
   s.update({'v' : 'new value'})
Exemplo n.º 30
0
 def test_default(self):
   s = Schema.make(v=StringValue(default='ok'))()
   eq_(s['v'], 'ok')
Exemplo n.º 31
0
 def test_rewritable_but_invalid_type(self):
   s = Schema.make(v=String().rewritable())(v='test')
   s['v'] = 1
Exemplo n.º 32
0
 def test_valid_list(self):
   s = Schema.make(v=IntArray())(v=[1, 2])
   eq_(s['v'], [1, 2])