attrs/tests/test_dark_magic.py

47 lines
847 B
Python
Raw Normal View History

2015-01-27 16:53:17 +00:00
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
import attr
from attr._make import Attribute, NOTHING
@attr.s
class C1(object):
2015-01-27 22:03:42 +00:00
x = attr.ib()
y = attr.ib()
2015-01-27 16:53:17 +00:00
foo = None
@attr.s()
class C2(object):
2015-01-27 22:03:42 +00:00
x = attr.ib(default_value=foo)
y = attr.ib(default_factory=list)
2015-01-27 16:53:17 +00:00
class TestDarkMagic(object):
"""
Integration tests.
"""
def test_ls(self):
"""
`attr.ls` works.
"""
assert [
Attribute(name="x", default_value=None, default_factory=NOTHING),
Attribute(name="y", default_value=NOTHING, default_factory=list),
] == attr.ls(C2)
def test_to_dict(self):
"""
`attr.to_dict` works.
"""
assert {
"x": 1,
"y": 2,
} == attr.to_dict(C1(x=1, y=2))