def parse_required(self, attributes): for attrib in attributes: if 'texname' not in attrib or attrib['texname'] == 'RelAbsVector': attrib['texname'] = attrib['name'] num = len(attributes) if num == 0: return '' elif num == 1: return 'the required attribute {0}'\ .format(strFunctions.wrap_token(attributes[0]['texname'], self.package)) else: required_statement = 'the required attributes {0}'\ .format(strFunctions.wrap_token(attributes[0]['texname'], self.package)) i = 1 while i < num - 1: required_statement += ', {0}'\ .format(strFunctions.wrap_token(attributes[i]['texname'], self.package)) i += 1 required_statement += ' and {0}'\ .format(strFunctions.wrap_token(attributes[i]['texname'], self.package)) return required_statement
def write_core_attribute_rule(self, lo_child=None): if lo_child is None: text = '{0} {1} object may have the optional SBML Level~3 ' \ 'Core attributes {2} and {3}. No other attributes from the ' \ 'SBML Level 3 Core namespaces are permitted on {4} {1}.'\ .format(self.indef_u, self.formatted_name, strFunctions.wrap_token('metaid'), strFunctions.wrap_token('sboTerm'), self.indef) ref = 'SBML Level~3 Version~1 Core, Section~3.2.' sev = 'ERROR' tc = '{0}{1}AllowedCoreAttributes'.format(self.up_package, self.name) lo = False else: lo_name = strFunctions.plural(lo_child['name']) text = 'A {0} object may have the optional SBML Level~3 ' \ 'Core attributes {1} and {2}. No other attributes from the ' \ 'SBML Level 3 Core namespaces are permitted on a {0} object.'\ .format(strFunctions.get_element_name(lo_child), strFunctions.wrap_token('metaid'), strFunctions.wrap_token('sboTerm')) ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' tc = '{0}{1}LO{2}AllowedCoreAttributes'.format(self.up_package, self.name, lo_name) lo = True lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Core attributes allowed on <{0}>.'.format(self.lower_name) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': True, 'object': self.name, 'lo': lo, 'reqd': self.reqd_elem, 'opt': self.opt_elem})
def parse_optional(self, attributes): for attrib in attributes: if 'texname' not in attrib: attrib['texname'] = attrib['name'] num = len(attributes) if num == 0: return '' elif num == 1: return 'the optional attribute {0}' \ .format(strFunctions.wrap_token(attributes[0]['texname'], self.package)) else: optional_statement = 'the optional attributes {0}' \ .format(strFunctions.wrap_token(attributes[0]['texname'], self.package)) i = 1 while i < num - 1: optional_statement += ', {0}' \ .format(strFunctions.wrap_token(attributes[i]['texname'], self.package)) i += 1 optional_statement += ' and {0}' \ .format(strFunctions.wrap_token(attributes[i]['texname'], self.package)) return optional_statement
def write_attibute_paragraph(self, attrib, name): att_name = attrib['texname'] if attrib['type'] == 'lo_element' \ or attrib['type'] == 'inline_lo_element': return elif attrib['type'] == 'element' \ and attrib['element'] != 'RelAbsVector': return else: self.write_line('\paragraph{0}The \\fixttspace\\token{0}{1}{2} ' 'attribute{2}'.format(self.start_b, att_name, self.end_b)) self.skip_line() self.write_line('{0} \{1} has {2} attribute {3} {4}.' .format(strFunctions.get_indefinite(name). capitalize(), name, 'a required' if attrib['reqd'] is True else 'an optional', strFunctions.wrap_token(att_name), strFunctions.wrap_type(attrib['type'], attrib['element'], True))) if attrib['type'] == 'SIdRef': [string_name, a] = strFunctions.get_sid_refs(attrib['element']) self.write_line('This attribute must be the identifier of ' 'an existing \{0} object.'.format(string_name)) self.write_to_do('explain {0}'.format(att_name)) self.skip_line()
def write_attibute_paragraph(self, attrib, name): att_name = attrib['texname'] if attrib['type'] == 'lo_element' \ or attrib['type'] == 'inline_lo_element': return elif attrib['type'] == 'element' \ and attrib['element'] != 'RelAbsVector': return else: self.write_line('\paragraph{0}The \\fixttspace\\token{0}{1}{2} ' 'attribute{2}'.format(self.start_b, att_name, self.end_b)) self.skip_line() self.write_line('{0} \{1} has {2} attribute {3} {4}.' .format(strFunctions.get_indefinite(name). capitalize(), name, 'a required' if attrib['reqd'] is True else 'an optional', strFunctions.wrap_token(att_name), strFunctions.wrap_type(attrib['type'], attrib['element'], True))) if attrib['type'] == 'SIdRef': [string_name, a] = strFunctions.get_sid_refs(attrib['element']) self.write_line('This attribute must be the identifier of ' 'an existing \{0} object.'.format(string_name)) self.write_to_do('explain {0}'.format(att_name)) self.skip_line()
def parse_required(self, attributes): num = len(attributes) if num == 0: return '' elif num == 1: return 'the required attribute {0}'\ .format(strFunctions.wrap_token(attributes[0]['name'], self.package)) else: required_statement = 'the required attributes {0}'\ .format(strFunctions.wrap_token(attributes[0]['name'], self.package)) i = 1 while i < num - 1: required_statement += ', {0}'\ .format(strFunctions.wrap_token(attributes[i]['name'], self.package)) i += 1 required_statement += ' and {0}'\ .format(strFunctions.wrap_token(attributes[i]['name'], self.package)) return required_statement
def parse_required(self, attributes): num = len(attributes) if num == 0: return '' elif num == 1: return 'the required attribute {0}'\ .format(strFunctions.wrap_token(attributes[0]['name'], self.package)) else: required_statement = 'the required attributes {0}'\ .format(strFunctions.wrap_token(attributes[0]['name'], self.package)) i = 1 while i < num - 1: required_statement += ', {0}'\ .format(strFunctions.wrap_token(attributes[i]['name'], self.package)) i += 1 required_statement += ' and {0}'\ .format(strFunctions.wrap_token(attributes[i]['name'], self.package)) return required_statement
def write_reqd_bool_rule(self): text = 'The value of attribute {0} on the \\class{1}SBML{2} object ' \ 'must be of data type \\primtype{1}boolean{2}.' \ .format(strFunctions.wrap_token('required', self.package), self.start_b, self.end_b) ref = 'SBML Level~3 Version~1 Core, Section~4.1.2.' sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'The {0}:required attribute must be Boolean' \ ''.format(self.package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}AttributeRequiredMustBeBoolean'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_reqd_rule(self): text = 'In all SBML documents using the {0}, the ' \ '\\class{1}SBML{2} object must have the {3} attribute.'\ .format(self.full_pkg_command, self.start_b, self.end_b, strFunctions.wrap_token('required', self.package)) ref = 'SBML Level~3 Version~1 Core, Section~4.1.2.' sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Required {0}:required attribute on <sbml>'.format(self.package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}AttributeRequiredMissing'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_reqd_rule(self): text = 'In all SBML documents using the {0}, the ' \ '\\class{1}SBML{2} object must have the {3} attribute.'\ .format(self.full_pkg_command, self.start_b, self.end_b, strFunctions.wrap_token('required', self.package)) ref = 'SBML Level~3 Version~1 Core, Section~4.1.2.' sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Required {0}:required attribute on <sbml>'.format(self.package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}AttributeRequiredMissing'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_reqd_bool_rule(self): text = 'The value of attribute {0} on the \\class{1}SBML{2} object ' \ 'must be of data type \\primtype{1}boolean{2}.' \ .format(strFunctions.wrap_token('required', self.package), self.start_b, self.end_b) ref = 'SBML Level~3 Version~1 Core, Section~4.1.2.' sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'The {0}:required attribute must be Boolean' \ ''.format(self.package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}AttributeRequiredMustBeBoolean'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_metaid_syntax_rule(self): text = 'The value of a {0} must conform to the syntax of ' \ 'the XML Type ID'\ .format(strFunctions.wrap_token('metaid', self.package)) ref = 'SBML Level~3 Version~1 Core, Section~3.1.6.' # ref = '{0} {1}.'\ # .format(self.pkg_ref, # strFunctions.wrap_section('primitive-types', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Invalid SId syntax'.format(self.up_package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}InvalidMetaidSyntax'.format(global_variables.prefix) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_metaid_syntax_rule(self): text = 'The value of a {0} must conform to the syntax of ' \ 'the XML Type ID'\ .format(strFunctions.wrap_token('metaid', self.package)) ref = 'SBML Level~3 Version~1 Core, Section~3.1.6.' # ref = '{0} {1}.'\ # .format(self.pkg_ref, # strFunctions.wrap_section('primitive-types', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Invalid SId syntax'.format(self.up_package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}InvalidMetaidSyntax'.format(global_variables.prefix) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_reqd_value_rule(self): text = 'The value of attribute {0} on the \\class{1}SBML{2} object ' \ 'must be set to \\val{1}{3}{2}.' \ .format(strFunctions.wrap_token('required', self.package), self.start_b, self.end_b, self.reqd_status) ref = '{0} {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section('xml-namespace', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'The {0}:required attribute must be \'{1}\'' \ ''.format(self.package, self.reqd_status) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}AttributeRequiredMustHaveValue'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_reqd_value_rule(self): text = 'The value of attribute {0} on the \\class{1}SBML{2} object ' \ 'must be set to \\val{1}{3}{2}.' \ .format(strFunctions.wrap_token('required', self.package), self.start_b, self.end_b, self.reqd_status) ref = '{0} {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section('xml-namespace', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'The {0}:required attribute must be \'{1}\'' \ ''.format(self.package, self.reqd_status) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}AttributeRequiredMustHaveValue'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_id_syntax_rule(self): text = 'The value of a {0} must conform to the syntax of ' \ 'the \\class{1}SBML{2} data type \\primtype{1}SId{2}'\ .format(strFunctions.wrap_token('id', self.package), self.start_b, self.end_b) ref = 'SBML Level~3 Version~1 Core, Section~3.1.7.' # ref = '{0} {1}.'\ # .format(self.pkg_ref, # strFunctions.wrap_section('primitive-types', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Invalid SId syntax'.format(self.up_package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}IdSyntaxRule'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_id_syntax_rule(self): text = 'The value of a {0} must conform to the syntax of ' \ 'the \\class{1}SBML{2} data type \\primtype{1}SId{2}'\ .format(strFunctions.wrap_token('id', self.package), self.start_b, self.end_b) ref = 'SBML Level~3 Version~1 Core, Section~3.1.7.' # ref = '{0} {1}.'\ # .format(self.pkg_ref, # strFunctions.wrap_section('primitive-types', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Invalid SId syntax'.format(self.up_package) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}IdSyntaxRule'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_attribute_type_rule(self, attribute): att_type = attribute['type'] att_name = strFunctions.upper_first(attribute['name']) name = strFunctions.wrap_token(attribute['name'], self.package) rule_type = 'String' if att_type == 'SId': return elif att_type == 'SIdRef': ref_name = strFunctions.upper_first(attribute['name']) # hack for render if ref_name == 'StartHead' or ref_name == 'EndHead': ref_name = 'LineEnding' text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing \{3} object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, self.formatted_name, ref_name) rule_type = ref_name elif att_type == 'string': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('string')) elif att_type == 'int' or att_type == 'uint': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('integer')) rule_type = 'Integer' if att_type == 'int' else 'UnInteger' elif att_type == 'double': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('double')) rule_type = 'Double' elif att_type == 'bool' or att_type == 'boolean': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('boolean')) rule_type = 'Boolean' elif att_type == 'enum': enum_name = attribute['element'] enums = attribute['parent']['root']['enums'] enum_values = self.parse_enum_values(enum_name, enums) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type {3} and ' \ 'may only take on the allowed values of {3} defined ' \ 'in SBML; that is, the value must be one of the ' \ 'following {4}.'.format(name, self.indef, self.formatted_name, strFunctions.wrap_enum(enum_name), enum_values) rule_type = '{0}Enum'.format(attribute['element']) elif att_type == 'array': text = 'The value of the attribute {0} of {1} {2} object must ' \ 'be an array of values of type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token(attribute['element'])) else: text = 'FIX ME: Encountered an unknown attribute type {0} in ' \ 'ValidationRulesForClass:write_attribute_type_rule'\ .format(att_type) ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Attribute {0} values allowed on <{1}>.' \ ''.format(attribute['name'], self.lower_name) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}{2}MustBe{3}'.format(self.up_package, self.name, att_name, rule_type) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref})
def write_attribute_type_rule(self, attribute, lo=None): if lo: formatted_name = lo['formatted_name'] refname = lo['name'] abbrev = strFunctions.abbrev_lo_name(refname) else: formatted_name = self.formatted_name refname = self.name abbrev = self.name att_type = attribute['type'] att_name = strFunctions.upper_first(attribute['name']) name = strFunctions.wrap_token(attribute['texname'], self.package) rule_type = 'String' if att_type == 'SId': return elif att_type == 'SIdRef': [ref_name, ref_type] = \ strFunctions.get_sid_refs(attribute['element']) # hack for render if ref_name == 'StartHead' or ref_name == 'EndHead': ref_name = 'LineEnding' text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing \{3} object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, formatted_name, ref_name) rule_type = ref_type elif att_type == 'string' or att_type == 'IDREF': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('string')) elif att_type == 'int' or att_type == 'uint': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('integer')) rule_type = 'Integer' if att_type == 'int' else 'UnInteger' elif att_type == 'double': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('double')) rule_type = 'Double' elif att_type == 'boolean' or att_type == 'bool': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('boolean')) rule_type = 'Boolean' elif att_type == 'UnitSId' or att_type == 'UnitSIdRef': text = 'The value of the attribute {0} on {1} {2} must have a ' \ 'taken from the following: the identifier of a ' \ '\\UnitDefinition object in the enclosing \Model, or one ' \ 'of the base units in SBML.'.format(name, self.indef, formatted_name) rule_type = 'Unit' elif att_type == 'enum': enum_name = strFunctions.texify(attribute['element']) enums = attribute['parent']['root']['enums'] enum_values = self.parse_enum_values(attribute['element'], enums) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type {3} and ' \ 'may only take on the allowed values of {3} defined ' \ 'in SBML; that is, the value must be one of the ' \ 'following: {4}.'.format(name, self.indef, formatted_name, strFunctions.wrap_enum(enum_name), enum_values) rule_type = '{0}Enum'.format(attribute['element']) elif att_type == 'array': text = 'The value of the attribute {0} of {1} {2} object must ' \ 'be an array of values of type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token(attribute['element'])) elif att_type == 'element' and attribute['element'] == 'RelAbsVector': text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type \\RelAbsVector ' \ 'i.e. a string encoding optionally an absolute number ' \ 'followed by an optional relative number followed ' \ 'by a \\% sign. Adding spaces between the ' \ 'coordinates is encouraged, but not required.'\ .format(name, self.indef, formatted_name) else: text = 'FIXME: Encountered an unknown attribute type {0} in ' \ 'ValidationRulesForClass'\ .format(att_type) # global_variables.code_returned = \ # global_variables.return_codes['unknown type used'] ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(refname)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = '{0} attribute must be {1}.'.format(att_name, rule_type) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}{2}MustBe{3}'.format(self.up_package, abbrev, att_name, rule_type) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'object': refname, 'attrib': att_name, 'attrib_type': att_type})
def write_attribute_type_rule(self, attribute, lo=None): if lo: formatted_name = lo['formatted_name'] refname = lo['name'] abbrev = strFunctions.abbrev_lo_name(refname) else: formatted_name = self.formatted_name refname = self.name abbrev = self.name att_type = attribute['type'] att_name = strFunctions.upper_first(attribute['name']) name = strFunctions.wrap_token(attribute['texname'], self.package) rule_type = 'String' if att_type == 'SId': return elif att_type == 'SIdRef': [ref_name, ref_type] = \ strFunctions.get_sid_refs(attribute['element']) # hack for render if ref_name == 'StartHead' or ref_name == 'EndHead': ref_name = 'LineEnding' if ref_name == 'SBase': text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing object derived from the \SBase class and defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, self.formatted_name, ref_name) else: text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing \{3} object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, self.formatted_name, ref_name) rule_type = ref_type elif att_type == 'string': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('string')) elif att_type == 'ID': text = 'The attribute {0} on {1} {2} must have a value of XML data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('ID')) elif att_type == 'IDREF': text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the \'metaid\' of an existing \SBase object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, formatted_name) rule_type = 'SBase' elif att_type == 'int' or att_type == 'uint': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}{4}'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('integer'), '.' if att_type == 'int' else ', and must be non negative.') rule_type = 'Integer' if att_type == 'int' else 'NonNegativeInteger' elif att_type == 'double': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('double')) rule_type = 'Double' elif att_type == 'bool' or att_type == 'boolean': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('boolean')) rule_type = 'Boolean' elif att_type == 'UnitSId' or att_type == 'UnitSIdRef': text = 'The value of the attribute {0} on {1} {2} must have a ' \ 'taken from the following: the identifier of a ' \ '\\UnitDefinition object in the enclosing \Model, or one ' \ 'of the base units in SBML.'.format(name, self.indef, formatted_name) rule_type = 'UnitSId' elif att_type == 'enum': enum_name = attribute['element'] enums = attribute['parent']['root']['enums'] enum_values = self.parse_enum_values(enum_name, enums) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type {3} and ' \ 'may only take on the allowed values of {3} defined ' \ 'in SBML; that is, the value must be one of the ' \ 'following {4}.'.format(name, self.indef, self.formatted_name, strFunctions.wrap_enum(enum_name), enum_values) rule_type = '{0}Enum'.format(attribute['element']) elif att_type == 'array': array_type = strFunctions.lower_first(attribute['element']) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'be an array of values of type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token(array_type)) else: text = 'FIX ME: Encountered an unknown attribute type {0} in ' \ 'ValidationRulesForClass:write_attribute_type_rule'\ .format(att_type) add_extended = True if self.package == 'render': add_extended = False ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name, True, add_extended)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = '{0} attribute must be {1}.'.format(att_name, rule_type) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}{2}MustBe{3}'.format(self.up_package, self.name, att_name, rule_type) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'plugin': True, 'object': self.name, 'lo': False, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'attrib': attribute['name'], 'attrib_type': att_type})