Coverage for control/cust/factory_table.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Factory to make derived Table classes."""
3from config import Names as N
4from control.utils import factory as baseFactory
6from control.table import Table
7from control.cust.contrib_table import ContribT
8from control.cust.assessment_table import AssessmentT
9from control.cust.review_table import ReviewT
12DERIVEDS = (
13 (N.contrib, ContribT),
14 (N.assessment, AssessmentT),
15 (N.review, ReviewT),
16)
17"""Search space for classes derived from `control.table.Table`."""
20def factory(name):
21 """Look up a derived class by registered name.
23 See `DERIVEDS`.
25 Parameters
26 ----------
27 name: string
28 The name under which the derived class is registered.
30 Returns
31 -------
32 class
33 The derived class if it can be found, otherwise the base class.
34 """
36 return baseFactory(name, Table, DERIVEDS)
39def make(context, name):
40 """Create an object in a registered table class.
42 This function will be stored in that object, so that the new table object
43 is able to create new table objects in its class.
45 !!! hint
46 This is needed when the user wants to insert new records in the table.
48 Parameters
49 ----------
50 context: object
51 The context singleton in which this very function will be stored
52 under attribute `mkTable`.
53 name: string
54 The registered name of the derived table class.
55 """
56 tableObj = factory(name)(context, name)
57 tableObj.mkTable = make
58 return tableObj