Skip to content

Commit

Permalink
Add end-to-end test for effects of cells and __init_subclass__
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Oct 19, 2017
1 parent 69740a0 commit 1b5436c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/attr/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


PY2 = sys.version_info[0] == 2
PY36PLUS = sys.version_info[0:2] >= (3, 6)
PYPY = platform.python_implementation() == "PyPy"


Expand Down
23 changes: 22 additions & 1 deletion tests/test_dark_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import attr

from attr._compat import TYPE
from attr._compat import TYPE, PY36PLUS
from attr._make import Attribute, NOTHING
from attr.exceptions import FrozenInstanceError

Expand Down Expand Up @@ -374,3 +374,24 @@ class E(D):
z = attr.ib(default=4)

assert "E(c=100, b=23, a=42, x=2, d=3.14, y=3, z=4)" == repr(E())

@pytest.mark.skipif(
not PY36PLUS,
reason="__init__subclass__ requires Python 3.6+"
)
@pytest.mark.parametrize("slots", [True, False])
def test_init_subclass(self, slots):
"""
super().__init_subclass__ can be called. This is problematic due to
certain cell intricancies around static and class methods.
"""
@attr.s(slots=slots)
class Base:
def __init_subclass__(cls, param, **kw):
super().__init_subclass__(**kw)
cls.param = param

class Vanilla(Base, param="foo"):
pass

assert "foo" == Vanilla().param

0 comments on commit 1b5436c

Please sign in to comment.