>>> from simo.builder.modelbase.modelbase import ModelbaseDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/parameter_table.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = u'''<parameter_tables xmlns="http://www.simo-project.org/simo"
... xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
... <parameter_table name="regeneration_limits"
... type="parameter_table" desc="...">
... <classifiers>
... <classifier>
... <variable>MAIN_SP</variable>
... <level>comp_unit</level>
... </classifier>
... </classifiers>
... <targets>
... <target>
... <data>
... <variable>upper_dgm</variable>
... <level>comp_unit</level>
... </data>
... </target>
... <target>
... <data>
... <variable>upper_age</variable>
... <level>comp_unit</level>
... </data>
... </target>
... </targets>
... <table>
... <value>1 32 70</value>
... <value>9 21 50</value>
... </table>
... </parameter_table>
... </parameter_tables>'''
>>> mb = ModelbaseDef(typedef)
>>> mb.schema = ('parameter_table', schema)
>>> try:
... mb.xml = ('testxml', xml, None, '', 'parameter_table')
... except ValueError, e:
... e.message
'errors in xml to object conversion'
>>> mb.errors
set(["No lexicon set when adding model for parameter table
collection 'testxml'",
"No lexicon set when validating variable for parameter table
collection 'testxml'"])
>>> class Lexicon(object):
... def __init__(self):
... self.models = {}
... def get_variable_ind(self, level, var, active=False):
... return (1, 1)
... def get_level_ind(self, level):
... return 1
... def add_model(self, mtype, mname):
... if mtype not in self.models:
... self.models[mtype] = set()
... self.models[mtype].add(mname)
>>> mb.xml = ('testxml', xml, Lexicon(), '', 'parameter_table')
>>> mb.errors
set([])
>>> mb.ok
{'testxml': True}
>>> mb.xml['parameter_table']['testxml'][:17]
u'<parameter_tables'
Parameter table definition
Attributes: