Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def test_nestenum(self):
assert attrload({'hair': 'white'}, DetailedPerson) == DetailedPerson(hair=Hair.WHITE)
def test_basicload(self):
assert attrload({'name': 'gino'}, Person) == Person('gino')
assert attrload({}, Person) == Person('Turiddu')
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
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
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)
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'),
])
def test_load_metanames(self):
a = {'va.lue': 12}
b = a.copy()
assert attrload(a, Mangle) == Mangle(12)
assert a == b
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