Beispiel #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')
Beispiel #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)
Beispiel #3
0
 def test_not_rewritable_direct(self):
   s = Schema.make(v=String())(v='test')
   s['v'] = 'new value'
Beispiel #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:
Beispiel #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')
Beispiel #6
0
 def test_valid(self):
   s = Schema.make(v=Int())(v=123)
   eq_(s['v'], 123)
Beispiel #7
0
 def test_invalid(self):
   Schema.make(v=Int())(v='test')
Beispiel #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})
Beispiel #9
0
 def test_invalid_key_type(self):
   Schema.make(v=StringDict(int))(v={0: 1})
Beispiel #10
0
 def test_invalid_value_type(self):
   Schema.make(v=DictOf(str, int))(v={'f1': 'INVALID'})
Beispiel #11
0
 def test_valie_is_not_nullable(self):
   Schema.make(v=DictOf(str, int, value_nullable=False))(v={'f1': None})
Beispiel #12
0
 def test_invalid_key_type(self):
   Schema.make(v=DictOf(int, int))(v={'INVALID': 1})
Beispiel #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})
Beispiel #14
0
 def test_invalid_element(self):
   Schema.make(v=IntArray())(v=['test', 1])
Beispiel #15
0
 def test_valid_tuple(self):
   s = Schema.make(v=IntArray())(v=(1, 2))
   eq_(s['v'], (1, 2))
Beispiel #16
0
 def test_invalid_value_type(self):
   Schema.make(v=StringDict(int))(v={'f1': 'INVALID'})
Beispiel #17
0
 def test_invalid(self):
   Schema.make(v=StringValue())(v=1234)
Beispiel #18
0
 def test_valie_is_not_nullable(self):
   Schema.make(v=StringDict(int, value_nullable=False))(v={'f1': None})
Beispiel #19
0
 def test_default(self):
   s = Schema.make(v=Int())()
   eq_(s['v'], 0)
Beispiel #20
0
 def test_valie_is_nullable_by_default(self):
   s = Schema.make(v=StringDict(int))(v={'f1': None})
   eq_(s['v'], {'f1': None})
Beispiel #21
0
 def test_not_nullable(self):
   Schema.make(v=Int())(v=None)
Beispiel #22
0
 def test_default(self):
   s = Schema.make(v=String())()
   eq_(s['v'], None)
Beispiel #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
Beispiel #24
0
 def test_valid(self):
   s = Schema.make(v=StringValue())(v='test')
   eq_(s['v'], 'test')
Beispiel #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))
Beispiel #26
0
 def test_not_nullable_by_default(self):
   Schema.make(v=StringValue())()
Beispiel #27
0
 def test_make_with_invalid_property(self):
   Schema.make(v1=String(), v2='INVALID')
Beispiel #28
0
 def test_not_empty_by_default(self):
   Schema.make(v=StringValue())(v='')
Beispiel #29
0
 def test_not_rewritable_by_merge(self):
   s = Schema.make(v=String())(v='test')
   s.update({'v' : 'new value'})
Beispiel #30
0
 def test_default(self):
   s = Schema.make(v=StringValue(default='ok'))()
   eq_(s['v'], 'ok')
Beispiel #31
0
 def test_rewritable_but_invalid_type(self):
   s = Schema.make(v=String().rewritable())(v='test')
   s['v'] = 1
Beispiel #32
0
 def test_valid_list(self):
   s = Schema.make(v=IntArray())(v=[1, 2])
   eq_(s['v'], [1, 2])