57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
from .container import Container, switch
|
|
|
|
|
|
def test_container_configuration():
|
|
'''Attributes should be passable to constructor or as class attributes'''
|
|
assert Container(a='b')['a'] == 'b'
|
|
class Test(Container):
|
|
cfg = dict(a='b')
|
|
assert Test()['a'] == 'b'
|
|
|
|
|
|
def test_switch_simple():
|
|
assert Container(a=switch(default='expected'))['a'] == 'expected'
|
|
assert Container(a=switch(noise='noise'))['a'] == None
|
|
fixture = Container(
|
|
'test',
|
|
a=switch(default='noise', test='expected')
|
|
)
|
|
assert fixture['a'] == 'expected'
|
|
assert [*fixture.values()][0] == 'expected'
|
|
assert [*fixture.items()][0][1] == 'expected'
|
|
|
|
|
|
def test_switch_iterable():
|
|
class TContainer(Container):
|
|
cfg = dict(
|
|
a=switch(dev='test')
|
|
)
|
|
assert TContainer()['a'] is None
|
|
assert TContainer('dev')['a'] == 'test'
|
|
assert TContainer('dev', a=[switch(dev='y')])['a'] == ['y']
|
|
assert TContainer('dev', a=[switch(default='y')])['a'] == ['y']
|
|
|
|
|
|
def test_switch_value_list():
|
|
assert Container('test').switch_value(
|
|
[switch(default='noise', test=False)]
|
|
) == [False]
|
|
|
|
assert Container('none').switch_value(
|
|
[switch(noise='noise')]
|
|
) == []
|
|
|
|
|
|
def test_switch_value_dict():
|
|
assert Container('foo').switch_value(
|
|
dict(i=switch(default='expected', noise='noise'))
|
|
) == dict(i='expected')
|
|
|
|
assert Container('test').switch_value(
|
|
dict(i=switch(default='noise', test='expected'))
|
|
) == dict(i='expected')
|
|
|
|
assert Container('none').switch_value(
|
|
dict(i=switch(noise='noise'), j=dict(e=switch(none=1)))
|
|
) == dict(j=dict(e=1))
|