How to use the typedload.attrload function in typedload

To help you get started, we’ve selected a few typedload examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ltworf / typedload / tests / test_attrload.py View on Github external
def test_uuid(self):
        import uuid

        @attr.s
        class A:
            a = attr.ib(type=int)
            uuid_value = attr.ib(type=str, init=False)

            def __attrs_post_init__(self):
                self.uuid_value = str(uuid.uuid4())

        assert type(attrload({'a': 1}, A).uuid_value) == str
        assert attrload({'a': 1}, A) != attrload({'a': 1}, A)
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_nestenum(self):
        assert attrload({'hair': 'white'}, DetailedPerson) == DetailedPerson(hair=Hair.WHITE)
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_basicload(self):
        assert attrload({'name': 'gino'}, Person) == Person('gino')
        assert attrload({}, Person) == Person('Turiddu')
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_wrongtype(self):
        try:
            attrload(3, Person)
        except exceptions.TypedloadTypeError:
            pass

        data = {
            'course': 'how to be a corsair',
            'students': [
                {'name': 'Alfio'},
                3
            ]
        }
        try:
            attrload(data, Students)
        except exceptions.TypedloadTypeError as e:
            assert e.trace[-1].annotation[1] == 1
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_wrongtype(self):
        try:
            attrload(3, Person)
        except exceptions.TypedloadTypeError:
            pass

        data = {
            'course': 'how to be a corsair',
            'students': [
                {'name': 'Alfio'},
                3
            ]
        }
        try:
            attrload(data, Students)
        except exceptions.TypedloadTypeError as e:
            assert e.trace[-1].annotation[1] == 1
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_uuid(self):
        import uuid

        @attr.s
        class A:
            a = attr.ib(type=int)
            uuid_value = attr.ib(type=str, init=False)

            def __attrs_post_init__(self):
                self.uuid_value = str(uuid.uuid4())

        assert type(attrload({'a': 1}, A).uuid_value) == str
        assert attrload({'a': 1}, A) != attrload({'a': 1}, A)
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_nested(self):
        assert attrload(
            {
                'course': 'advanced coursing',
                'students': [
                    {'name': 'Alfio'},
                    {'name': 'Carmelo', 'address': 'via mulino'},
                ]
            },
            Students,
        ) == Students('advanced coursing', [
            Person('Alfio'),
            Person('Carmelo', 'via mulino'),
        ])
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_load_metanames(self):
        a = {'va.lue': 12}
        b = a.copy()
        assert attrload(a, Mangle) == Mangle(12)
        assert a == b
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_index(self):
        try:
            attrload(
                {
                    'course': 'advanced coursing',
                    'students': [
                        {'name': 'Alfio'},
                        {'name': 'Carmelo', 'address': 'via mulino'},
                        [],
                    ]
                },
                Students,
            )
        except Exception as e:
            assert e.trace[-2].annotation[1] == 'students'
            assert e.trace[-1].annotation[1] == 2