Clean up interface to passing multiple facets into Engine()
This commit is contained in:
parent
9a461607b9
commit
bd43d001c4
|
@ -208,17 +208,13 @@ class Engine(object):
|
|||
facets = []
|
||||
facet_index_by_id = {} # dict of facets by Facet object id
|
||||
|
||||
def __init__(self, facets=None, mode='row-based'):
|
||||
self.set_facets(facets)
|
||||
self.mode = mode
|
||||
def __init__(self, *facets, **kwargs):
|
||||
self.set_facets(*facets)
|
||||
self.mode = kwargs.get('mode', 'row-based')
|
||||
|
||||
def set_facets(self, facets=None):
|
||||
def set_facets(self, *facets):
|
||||
"""facets may be a Facet or list of Facets."""
|
||||
self.remove_all()
|
||||
if facets is None:
|
||||
facets = []
|
||||
elif not isinstance(facets, list):
|
||||
facets = [facets]
|
||||
for facet in facets:
|
||||
self.add_facet(facet)
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class EngineTest(unittest.TestCase):
|
|||
self.assertEqual(engine.mode, 'record-based')
|
||||
engine.set_facets(BlankFacet)
|
||||
self.assertEqual(engine.mode, 'record-based')
|
||||
engine.set_facets([BlankFacet] * 2)
|
||||
engine.set_facets(BlankFacet, BlankFacet)
|
||||
self.assertEqual(len(engine), 2)
|
||||
|
||||
def test_serialize(self):
|
||||
|
@ -98,7 +98,7 @@ class EngineTest(unittest.TestCase):
|
|||
text_facet1.include('element')
|
||||
text_facet2 = TextFacet('column name 2')
|
||||
text_facet2.include('element 2')
|
||||
engine = Engine([text_facet1, text_facet2])
|
||||
engine = Engine(text_facet1, text_facet2)
|
||||
self.assertEqual(len(engine), 2)
|
||||
self.assertEqual(len(text_facet1.selection), 1)
|
||||
engine.reset_all()
|
||||
|
|
Loading…
Reference in New Issue