smell: fixes assert in container constructor.
This commit is contained in:
@ -66,8 +66,11 @@ class Service(Option):
|
|||||||
class Container(dict):
|
class Container(dict):
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
assert not len(kwargs), 'only one usage at a time, my dear.'
|
if len(kwargs):
|
||||||
if not (args[0]):
|
raise ValueError(
|
||||||
|
'You can either use {} with one positional argument or with keyword arguments, not both.'
|
||||||
|
)
|
||||||
|
if not args[0]:
|
||||||
return super().__new__(cls)
|
return super().__new__(cls)
|
||||||
if isinstance(args[0], cls):
|
if isinstance(args[0], cls):
|
||||||
return cls
|
return cls
|
||||||
|
|||||||
@ -130,6 +130,20 @@ def test_requires():
|
|||||||
assert svcargs['output'] == vcr.append
|
assert svcargs['output'] == vcr.append
|
||||||
|
|
||||||
|
|
||||||
|
def test_constructor():
|
||||||
|
c1 = Container(foo='foo', bar='bar')
|
||||||
|
assert 2 == len(c1)
|
||||||
|
|
||||||
|
c2 = Container({'foo': 'foo', 'bar': 'bar'})
|
||||||
|
assert 2 == len(c2)
|
||||||
|
|
||||||
|
assert c1['foo'] == c2['foo']
|
||||||
|
assert c1['bar'] == c2['bar']
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
Container({'bar': 'bar'}, foo='foo')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('services', [None, {}])
|
@pytest.mark.parametrize('services', [None, {}])
|
||||||
def test_create_container_empty_values(services):
|
def test_create_container_empty_values(services):
|
||||||
c = create_container(services)
|
c = create_container(services)
|
||||||
|
|||||||
Reference in New Issue
Block a user