Verify amount of arguments passed to Attribute
This commit is contained in:
parent
564fade925
commit
7c85d68de2
|
@ -350,6 +350,8 @@ class Attribute(object):
|
|||
] # we can't use ``attrs`` so we have to cheat a little.
|
||||
|
||||
def __init__(self, **kw):
|
||||
if len(kw) > len(Attribute._attributes):
|
||||
raise TypeError("Too many arguments.")
|
||||
try:
|
||||
for a in Attribute._attributes:
|
||||
setattr(self, a, kw[a])
|
||||
|
|
|
@ -19,7 +19,7 @@ from attr._make import (
|
|||
)
|
||||
|
||||
|
||||
class TestAttr(object):
|
||||
class TestCountingAttr(object):
|
||||
"""
|
||||
Tests for `attr`.
|
||||
"""
|
||||
|
@ -190,12 +190,21 @@ class TestAttribute(object):
|
|||
"""
|
||||
def test_missing_argument(self):
|
||||
"""
|
||||
Raises TypeError if an Argument is missing.
|
||||
Raises `TypeError` if an Argument is missing.
|
||||
"""
|
||||
with pytest.raises(TypeError) as e:
|
||||
Attribute(default=NOTHING, factory=NOTHING, validator=None)
|
||||
Attribute(default=NOTHING, validator=None)
|
||||
assert ("Missing argument 'name'.",) == e.value.args
|
||||
|
||||
def test_too_many_arguments(self):
|
||||
"""
|
||||
Raises `TypeError` if extra arguments are passed.
|
||||
"""
|
||||
with pytest.raises(TypeError) as e:
|
||||
Attribute(name="foo", default=NOTHING,
|
||||
factory=NOTHING, validator=None)
|
||||
assert ("Too many arguments.",) == e.value.args
|
||||
|
||||
|
||||
class TestMakeClass(object):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue