Skip to content

Commit

Permalink
Move factory tests where they belong
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Mar 17, 2024
1 parent 189ab7f commit 1967be0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
23 changes: 23 additions & 0 deletions tests/test_dunders.py
Expand Up @@ -836,6 +836,29 @@ class C:
assert [] == i.a
assert isinstance(i.b, D)

def test_factory_takes_self(self):
"""
If takes_self on factories is True, self is passed.
"""
C = make_class(
"C",
{
"x": attr.ib(
default=Factory((lambda self: self), takes_self=True)
)
},
)

i = C()

assert i is i.x

def test_factory_hashable(self):
"""
Factory is hashable.
"""
assert hash(Factory(None, False)) == hash(Factory(None, False))

def test_validator(self):
"""
If a validator is passed, call it with the preliminary instance, the
Expand Down
23 changes: 0 additions & 23 deletions tests/test_make.py
Expand Up @@ -1336,29 +1336,6 @@ def test_converter_factory_property(self, val, init):
assert c.x == val + 1
assert c.y == 2

def test_factory_takes_self(self):
"""
If takes_self on factories is True, self is passed.
"""
C = make_class(
"C",
{
"x": attr.ib(
default=Factory((lambda self: self), takes_self=True)
)
},
)

i = C()

assert i is i.x

def test_factory_hashable(self):
"""
Factory is hashable.
"""
assert hash(Factory(None, False)) == hash(Factory(None, False))

def test_convert_before_validate(self):
"""
Validation happens after conversion.
Expand Down

0 comments on commit 1967be0

Please sign in to comment.