Initializes the output constraint by processing the schema and xml documents:
>>> from simo.builder.output.outputconstraint import \
... OutputConstraintDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/output_constraint.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = u'''<output_constraints xmlns="http://www.simo-project.org/simo"
... xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
... xsi:schemaLocation="http://www.simo-project.org/simo
... ../schemas/Output_constraint.xsd">
... <data_level>
... <name>comp_unit</name>
... <var_list>AREA SC</var_list>
... </data_level>
... <data_level>
... <name>stratum</name>
... <var_list>SP Age BA some_exotic_variable</var_list>
... </data_level>
... </output_constraints>'''
>>> passingxml = u'''<output_constraints
... xmlns="http://www.simo-project.org/simo"
... xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
... xsi:schemaLocation="http://www.simo-project.org/simo
... ../schemas/Output_constraint.xsd">
... <data_level>
... <name>comp_unit</name>
... <var_list>AREA SC</var_list>
... </data_level>
... <data_level>
... <name>stratum</name>
... <var_list>SP Age BA</var_list>
... </data_level>
... <data_level>
... <name>tree</name>
... <var_list>*</var_list>
... </data_level>
... </output_constraints>'''
>>> class Lexicon(object):
... def get_level_ind(self, level):
... levels = {'comp_unit':1, 'stratum':2, 'tree':3}
... return levels[level]
... def get_variable_ind(self, level, var, check_active=False):
... #NB! removed while outputconstrains are inactive
... #if check_active:
... if True:
... if var=='some_exotic_variable':
... return (None, None)
... else:
... return (1, 1)
>>> ocd = OutputConstraintDef(typedef)
>>> ocd.schema = schema
>>> try:
... ocd.xml = ('testxml', xml, Lexicon())
... except ValueError, e:
... print e
errors in xml to object conversion
>>> ocd.errors
set(["Variable 'some_exotic_variable' not found at level 'stratum' in
lexicon for output constraint 'testxml'"])
>>> # NB! This is the error which we should get if the checking for
>>> # active variables is used
>>> #set(["Variable 'some_exotic_variable' not found at level 'stratum' in
>>> # lexicon or it's not set to be computed during simulation for output
>>> # constraint 'testxml'"])
>>> ocd.xml = ('passingxml', passingxml, Lexicon())
>>> oc = ocd.obj['passingxml']
>>> oc.variables[('comp_unit', 1)]
[('AREA', 1), ('SC', 1)]
>>> oc.variables[('stratum', 2)]
[('SP', 1), ('Age', 1), ('BA', 1)]
>>> oc.variables[('tree', 3)] is None
True
>>> ocd.errors
set([])
>>> ocd.warnings
[]