Clean up interface to passing multiple facets into Engine()

This commit is contained in:
Paul Makepeace 2011-06-23 09:49:25 +00:00
parent 9a461607b9
commit bd43d001c4
2 changed files with 6 additions and 10 deletions

View File

@ -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)

View File

@ -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()