示例#1
0
class Data(TypedClass):
    entry_ref1 = f.Ref(Entry)
    entry_ref2 = f.Ref(Entry)
    entry_list = f.List(Entry)
    int1 = f.Int()
    int2 = f.Int()
    int_list = f.List(f.Int)
示例#2
0
class Data(TypedClass):
    f_bool1 = f.Bool()
    f_bool2 = f.Bool()
    f_bool3_opt = f.Bool(required=False)
    f_datetime1 = f.DateTime()
    f_datetime2 = f.DateTime()
    f_decimal1 = f.Decimal()
    f_decimal2 = f.Decimal()
    f_ref1 = f.Ref(Entry)
    f_ref2 = f.Ref(Entry)
    f_ref3_list = f.List(Entry)
示例#3
0
def test_dict_ok():
    f_ref = f.Ref(Entry)
    entry_dict = {'test': 'abc'}
    entry = Entry(**entry_dict)
    v_ref = f_ref.process(name='f_ref', value=entry_dict)

    assert v_ref == entry
示例#4
0
def test_unsupported_instance_error():
    f_ref = f.Ref(Entry)

    error = None
    try:
        f_ref.process(name='f_ref', value=123)
    except TypedClassValidationError as exc:
        error = exc

    assert error
    msg = str(error)
    assert msg == ("f_ref is not instance of "
                   "<class 'typedclass.tests.fields.ref.test_process.Entry'>")
示例#5
0
class Data(TypedClass):
    f_bool = f.Bool()
    f_datetime = f.DateTime()
    f_date = f.Date()
    f_decimal = f.Decimal()
    f_int = f.Int()
    f_float = f.Float()
    f_string = f.String()
    f_list = f.List(f.String)
    f_ref = f.Ref(Entry)
    f_typedmap = f.TypedMap(key=f.String(), value=f.String())
    f_rawmap = f.RawMap()
    f_rawlist = f.RawList()
    f_time = f.Time()
示例#6
0
class Data(TypedClass):
    int = f.Int()
    int_list = f.List(f.Int)

    float = f.Float()
    float_list = f.List(f.Float)

    decimal = f.Decimal()
    decimal_list = f.List(f.Decimal)

    dt = f.DateTime()
    dt_list = f.List(f.DateTime)

    date = f.Date()
    date_list = f.List(f.Date)

    time = f.Time()
    time_list = f.List(f.Time)

    entry_ref = f.Ref(Entry)
    entry_list = f.List(Entry)

    rawmap = f.RawMap()
    rawlist = f.RawList()
示例#7
0
def test_empty_ok():
    f_ref = f.Ref(Entry, required=False)
    v_ref = f_ref.process(name='f_ref', value=None)

    assert v_ref is None
示例#8
0
def test_cls_ok():
    f_ref = f.Ref(Entry)
    entry = Entry(test='abc')
    v_ref = f_ref.process(name='f_ref', value=entry)

    assert v_ref == entry
示例#9
0
def test_empty_ok():
    f_ref = f.Ref(Entry, required=False)
    v_ref = f_ref.simplify(value=None)

    assert v_ref is None
示例#10
0
def test_cls_ok():
    f_ref = f.Ref(Entry)
    entry = Entry(test='abc')
    v_ref = f_ref.simplify(value=entry)

    assert v_ref == {'test': 'abc'}
示例#11
0
class DataCleaned(TypedClass):
    f_bool = f.Bool()
    f_ref = f.Ref(EntryCleaned)
示例#12
0
class DataFull(TypedClass):
    f_bool = f.Bool()
    f_ref = f.Ref(EntryFull)
示例#13
0
class TypedClassHTMLField(TypedClass):
    name = f.String(min_length=1)
    ftype = f.String(min_length=1)
    properties = f.Ref(TypedClassHTMLFieldProperties)
示例#14
0
class Data(TypedClass):
    # base:
    f_bool1 = f.Bool(required=True)
    f_bool2 = f.Bool(required=False, comment='test f_bool2')
    f_bool3 = f.Bool(extra_validators=(_extra_validator, ))

    f_date1 = f.Date(required=True)
    f_date2 = f.Date(required=False, comment='test f_date2')

    f_datetime1 = f.DateTime(required=True)
    f_datetime2 = f.DateTime(required=False, comment='test f_datetime2')

    f_decimal1 = f.Decimal(required=True)
    f_decimal2 = f.Decimal(required=False, comment='test f_decimal2')
    f_decimal3 = f.Decimal(min_value=Decimal('0.0001'),
                           max_value=Decimal('1.234567890'))

    f_int1 = f.Int(required=True)
    f_int2 = f.Int(required=False, comment='test f_int2')
    f_int3 = f.Int(min_value=-999, max_value=999)

    f_float1 = f.Float(required=True)
    f_float2 = f.Float(required=False, comment='test f_float2')
    f_float3 = f.Float(min_value=1.23, max_value=4.56)

    f_string1 = f.String(required=True)
    f_string2 = f.String(required=False, comment='test f_string2')
    f_string3 = f.String(min_length=1, max_length=50, choices=(
        'a',
        'b',
    ))
    f_string4 = f.String(choices=())

    f_time1 = f.Time(required=True)
    f_time2 = f.Time(required=False, comment='test f_time2')

    # special:
    f_list1 = f.List(f.String, required=True)
    f_list2 = f.List(f.String, required=False, comment='test f_list2')
    f_list3 = f.List(Entry1)

    f_ref1 = f.Ref(Entry1, required=True)
    f_ref2 = f.Ref(Entry1, required=False, comment='test f_ref2')

    f_set1 = f.Set(f.String, required=True)
    f_set2 = f.Set(f.String, required=False, comment='test f_set2')
    f_set3 = f.Set(Entry1)

    # map-like:
    f_rawmap1 = f.RawMap(required=True)
    f_rawmap2 = f.RawMap(required=False, comment='test f_rawmap2')

    f_typedmap1 = f.TypedMap(key=f.String(), value=f.String(), required=True)
    f_typedmap2 = f.TypedMap(key=f.String(),
                             value=f.String(),
                             required=False,
                             comment='test f_typedmap2')

    # list-like:
    f_rawlist1 = f.RawList(required=True)
    f_rawlist2 = f.RawList(required=False, comment='test f_rawlist2')