Skip to content

Commit

Permalink
validation sorted to date
Browse files Browse the repository at this point in the history
  • Loading branch information
skeating committed Jul 24, 2023
1 parent 99796d3 commit 5166f19
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 225 deletions.
40 changes: 28 additions & 12 deletions deviser/code_files/ValidationFiles.py
Expand Up @@ -110,10 +110,11 @@ def create_rule_structure(self):
global_variables.language)
rules.determine_rules()
self.class_rules += rules.rules
if global_variables.is_package:
number = self.offset + 20200
else:
number = 20200
number = self.offset + 20200 if global_variables.is_sbml else 20100
# if global_variables.is_package:
# number = self.offset + 20200
# else:
# number = 20200
for i in range(0, len(self.plugins)):
rules = ValidationRulesForPlugin.ValidationRulesForPlugin(
self.plugins[i], self.fullname, number,
Expand All @@ -131,6 +132,15 @@ def create_rule_structure(self):
self.pkg_ref)
rules.determine_rules()
self.class_rules += rules.rules
if not global_variables.is_sbml:
for att in self.sbml_classes[i]['attribs']:
if att['type'] == 'lo_element':
rules.rules = []
number += 100
rules.number = number
rules.add_lo_rules()
self.class_rules += rules.rules

number += 100
self.populate_error_list()

Expand Down Expand Up @@ -438,23 +448,20 @@ def is_package(i, text_string, length):
is_package = True
return [is_package, len_word]

@staticmethod
def replace_name(i, text_string, length):
def replace_name(self, i, text_string, length):
in_name = True
return_name_rep = ''
# we dont want to lower the s of SBase
# or name if it starts with the prefix for the language
isSBase = False
while in_name and i < length:
letter = text_string[i]
if i != length-1:
next_letter = text_string[i+1]
else:
next_letter = ' '
if letter == '\\':
isSBase = False
# we dont want to lower the s of SBase
if next_letter == 'S' or next_letter == 's':
test_str = text_string[i+1:i+7]
if test_str.lower() == 'sbase ':
isSBase = True
isSBase = self.is_sbase(text_string, i, next_letter)
if isSBase:
return_name_rep += '\'S'
else:
Expand All @@ -472,6 +479,15 @@ def replace_name(i, text_string, length):
continue
return [i-1, return_name_rep]

def is_sbase(self, text, index, next_letter):
if len(text) < index + 7:
return False
if next_letter == 'S' or next_letter == 's':
test_str = text[index + 1:index + 7]
if test_str.lower() == 'sbase ':
return True
return False

@staticmethod
def replace_uri(i, text_string, length):
in_uri = True
Expand Down
11 changes: 0 additions & 11 deletions deviser/code_files/templates/Error.h
Expand Up @@ -21,17 +21,6 @@ typedef enum
, SBMLNotUTF8 = 10001 /*!< File does not use UTF-8 encoding. */
, SBMLUnrecognizedElement = 10002 /*!< Encountered unrecognized element. */
, SBMLNotSchemaConformant = 10003 /*!< Document does not conform to the SBML_Lang XML schema. */
, SBMLInvalidMathElement = 10201
, SBMLMissing<Annotation>Namespace = 10401 /*!< Missing declaration of the XML namespace for the annotation. */
, SBMLDuplicate<Annotation>Namespaces = 10402 /*!< Multiple annotations using the same XML namespace. */
, SBMLNamespaceIn<Annotation> = 10403 /*!< The SBML_Lang XML namespace cannot be used in an <Annotation> object. */
, SBMLMultiple<Annotation>s = 10404 /*!< Only one <Annotation> object is permitted under a given SBML_Lang object. */
, SBML<Annotation>NotElement = 10405
, SBMLNotesNotInXHTMLNamespace = 10801 /*!< Notes must be placed in the XHTML XML namespace. */
, SBMLNotesContainsXMLDecl = 10802 /*!< XML declarations are not permitted in Notes objects. */
, SBMLNotesContainsDOCTYPE = 10803 /*!< XML DOCTYPE elements are not permitted in Notes objects. */
, SBMLInvalidNotesContent = 10804 /*!< Invalid notes content found. */
, SBMLOnlyOneNotesElementAllowed = 10805 /*!< Only one Notes subobject is permitted on a given SBML_Lang object. */
<add_specific_errors/>
, SBMLUnknownCoreAttribute = 99994 /*!< Encountered an unknown attribute in the SBML_Lang Core namespace. */
, SBMLCodesUpperBound = 99999 /*!< Upper boundary of libSBML-specific diagnostic codes. */
Expand Down
120 changes: 0 additions & 120 deletions deviser/code_files/templates/ErrorTable.h
Expand Up @@ -77,126 +77,6 @@ static const sbmlErrorTableEntry sbmlErrorTable[] =
}
},

//10201
{
SBMLInvalidMathElement,
"Invalid MathML",
LIBSBML_CAT_MATHML_CONSISTENCY,
LIBSBML_SEV_ERROR,
"All MathML content in SBML_Lang must appear within a <math> element, and the "
"<math> element must be either explicitly or implicitly in the XML "
"namespace \"http://www.w3.org/1998/Math/MathML\".",
{""
}
},

//10401
{
SBMLMissing<Annotation>Namespace,
"Missing declaration of the XML namespace for the annotation",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"Every top-level element within an annotation element must "
"have a namespace declared.",
{""
}
},

//10402
{
SBMLDuplicate<Annotation>Namespaces,
"Multiple annotations using the same XML namespace",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"There cannot be more than one top-level element using a "
"given namespace inside a given annotation element. ",
{""
}
},

//10403
{
SBMLNamespaceIn<Annotation>,
"The SBML_Lang XML namespace cannot be used in an <Annotation> object",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"Top-level elements within an annotation element cannot use any SBML_Lang "
"namespace, whether explicitly or implicitly (by failing "
"to declare any namespace).",
{""
}
},

//10404
{
SBMLMultiple<Annotation>s,
"Only one <Annotation> object is permitted under a given SBML_Lang object",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"A given SBML_Lang object may contain at most one <annotation> element.",
{""
}
},

//10801
{
SBMLNotesNotInXHTMLNamespace,
"Notes must be placed in the XHTML XML namespace",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"The contents of the <notes> element must be explicitly placed in the "
"XHTML XML namespace.",
{""
}
},

//10802
{
SBMLNotesContainsXMLDecl,
"XML declarations are not permitted in Notes objects",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"The contents of the <notes> element must not contain an XML declaration "
"(i.e., a string of the form \"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\" "
"or similar).",
{""
}
},

//10803
{
SBMLNotesContainsDOCTYPE,
"XML DOCTYPE elements are not permitted in Notes objects",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"The contents of the <notes> element must not contain an XML DOCTYPE "
"declaration (i.e., a string beginning with the characters \"<!DOCTYPE\". ",
{""
}
},

//10804
{
SBMLInvalidNotesContent,
"Invalid notes content",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"Invalid contents in a <notes> element. ",
{""
}
},

//10805
{
SBMLOnlyOneNotesElementAllowed,
"Only one Notes subobject is permitted on a given SBML_Lang object",
LIBSBML_CAT_SBML,
LIBSBML_SEV_ERROR,
"A given SBML_Lang object may contain at most one <notes> element. ",
{""
}
},

/* --------------------------------------------------------------------------
* Boundary marker. SBML_Lang specific errors.
* ----------------------------------------------------------------------- */
Expand Down
53 changes: 20 additions & 33 deletions deviser/pytest_files/test_other_library/test-code/tsb/TSBError.h
Expand Up @@ -57,39 +57,26 @@ typedef enum
, TSBNotUTF8 = 10001 /*!< File does not use UTF-8 encoding. */
, TSBUnrecognizedElement = 10002 /*!< Encountered unrecognized element. */
, TSBNotSchemaConformant = 10003 /*!< Document does not conform to the TSB XML schema. */
, TSBInvalidMathElement = 10201
, TSBMissingTestAnnotationNamespace = 10401 /*!< Missing declaration of the XML namespace for the annotation. */
, TSBDuplicateTestAnnotationNamespaces = 10402 /*!< Multiple annotations using the same XML namespace. */
, TSBNamespaceInTestAnnotation = 10403 /*!< The TSB XML namespace cannot be used in an TestAnnotation object. */
, TSBMultipleTestAnnotations = 10404 /*!< Only one TestAnnotation object is permitted under a given TSB object. */
, TSBTestAnnotationNotElement = 10405
, TSBNotesNotInXHTMLNamespace = 10801 /*!< Notes must be placed in the XHTML XML namespace. */
, TSBNotesContainsXMLDecl = 10802 /*!< XML declarations are not permitted in Notes objects. */
, TSBNotesContainsDOCTYPE = 10803 /*!< XML DOCTYPE elements are not permitted in Notes objects. */
, TSBInvalidNotesContent = 10804 /*!< Invalid notes content found. */
, TSBOnlyOneNotesElementAllowed = 10805 /*!< Only one Notes subobject is permitted on a given TSB object. */
, TsbNSUndeclared = 10101
, TsbElementNotInNs = 10102
, TsbDuplicateComponentId = 10301
, TsbIdSyntaxRule = 10302
, TSBInvalidMetaidSyntax = 10303
, InvalidNamespaceOnTSB = 20101
, AllowedAttributes = 20102
, TSBEmptyListElement = 20103
, TsbDocumentAllowedCoreAttributes = 20201
, TsbDocumentAllowedCoreElements = 20202
, TsbDocumentAllowedAttributes = 20203
, TsbDocumentAllowedElements = 20204
, TsbDocumentLevelMustBeNonNegativeInteger = 20205
, TsbDocumentVersionMustBeNonNegativeInteger = 20206
, TsbDocumentLOCommentsAllowedCoreElements = 20207
, TsbDocumentLOCommentsAllowedCoreAttributes = 20208
, TsbCommentAllowedCoreAttributes = 20301
, TsbCommentAllowedCoreElements = 20302
, TsbCommentAllowedAttributes = 20303
, TsbCommentContributorMustBeString = 20304
, TsbCommentNumberMustBeDouble = 20305
, TsbCommentPointMustBeString = 20306
, TSBNSUndeclared = 10101
, TSBElementNotInNs = 10102
, TSBInvalidMetaidSyntax = 10201
, TSBNoAnnotationNS = 10301
, TSBRepeatAnnotationNS = 10302
, TSBOnlyOneAnnotation = 10303
, NotesInXHTML = 10401
, XMLDeclNotes = 10402
, DOCTYPEInNotes = 10403
, TSBOnlyOneNotes = 10404
, TSBTSBDocumentAllowedAttributes = 20101
, TSBTSBDocumentAllowedElements = 20102
, TSBTSBDocumentLevelMustBeNonNegativeInteger = 20103
, TSBTSBDocumentVersionMustBeNonNegativeInteger = 20104
, TSBTSBDocumentLOCommentAllowedCoreElements = 20201
, TSBTSBDocumentLOCommentsAllowedCoreAttributes = 20202
, TSBCommentAllowedAttributes = 20301
, TSBCommentContributorMustBeString = 20302
, TSBCommentNumberMustBeDouble = 20303
, TSBCommentPointMustBeString = 20304
, TSBUnknownCoreAttribute = 99994 /*!< Encountered an unknown attribute in the TSB Core namespace. */
, TSBCodesUpperBound = 99999 /*!< Upper boundary of libTSB-specific diagnostic codes. */
} TSBErrorCode_t;
Expand Down
4 changes: 2 additions & 2 deletions deviser/pytest_files/test_other_library/test_utils.py
Expand Up @@ -245,10 +245,10 @@ def compare_code(class_name, end):
return compare_files(correct_file, temp_file)

def compare_code_headers(class_name):
return compare_code(class_name, ".h")
return compare_code(class_name, ".h") if not class_name == '' else 0

def compare_code_impl(class_name):
return compare_code(class_name, ".cpp")
return compare_code(class_name, ".cpp") if not class_name == '' else 0

def compare_code_cmake(class_name):
return compare_code(class_name, ".cmake")
Expand Down

0 comments on commit 5166f19

Please sign in to comment.