def test_attr(): a = Attr() assert isinstance(a.type, AnyType) assert a.default is None assert a.doc == '' assert a.optional is False a = Attr(int, 1, 'A number', optional=True) assert isinstance(a.type, TypeType) assert a.type.type is int assert a.default == 1 assert a.doc == 'A number' assert a.optional is True
def test_attrs(): attrs = Attrs(a=Attr(int, doc='value 1'), b=Attr(float, 3.4), c=Attr(STR, doc='value 2', optional=True), d=Attr(list, [1, 2], doc='value 3', optional=True)) assert attrs.attrs == set(['a', 'b', 'c', 'd']) assert attrs.types['a'].type is int assert attrs.types['b'].type is float assert attrs.types['c'].type is STR[0] assert attrs.types['d'].type is list assert attrs.required == {'a', 'b'} assert attrs.optional == {'c', 'd'} assert attrs.defaults == dict(b=3.4, d=[1, 2]) assert attrs.doc == dict(a='value 1', c='value 2', d='value 3')
class This3(This2): _attrs = dict(b=Attr(This, optional=True))
class ThisTest(Base): _attrs = dict(a=Attr(int), b=Attr(This, optional=True))
class AliasTest(Base): _attrs = dict(a=Attr(list)) _aliases = dict(a=('b', 'c'))
class C(object): _attrs = Attrs(a=Attr(float), e=Attr(set))
class B(A): _attrs = dict(c=Attr(dict), d=Attr(list, default=[1, 2])) _opts = dict(y=3.4, z='abc')
class A(object): _attrs = Attrs(a=Attr(int, doc='value 1'), b=Attr(float, 3.4), c=Attr(STR, doc='value 2', optional=True)) _opts = AttrDict(x=1, y=2.3)