From c66e5b418298073329f39eb0fb2e330d49f8f443 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 24 May 2023 11:26:04 +0100 Subject: [PATCH 01/37] update template --- .../test-code/tsb/TSBBase.h | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.h b/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.h index 4874ccd9..9ec8cc56 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.h +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.h @@ -62,7 +62,6 @@ #include #include -class Model; class List; @@ -72,6 +71,7 @@ class XMLNamespaces; class XMLOutputStream; class XMLToken; + LIBTSB_CPP_NAMESPACE_BEGIN class TSBDocument; @@ -263,7 +263,7 @@ class LIBTSB_EXTERN TSBBase * @see unsetNotes() * @see SyntaxChecker::hasExpectedXHTMLSyntax(@if java XMLNode@endif) */ - const XMLNode* getNotes() const; + const XMLNode* getNotes() const; /** @@ -357,7 +357,7 @@ class LIBTSB_EXTERN TSBBase * @see appendTestAnnotation(const std::string& annotation) * @see unsetTestAnnotation() */ - const XMLNode* getTestAnnotation () const; + const XMLNode* getTestAnnotation () const; /** @@ -414,7 +414,7 @@ class LIBTSB_EXTERN TSBBase * @see getLevel() * @see getVersion() */ - virtual const XMLNamespaces* getNamespaces() const ; + virtual const XMLNamespaces* getNamespaces() const ; /** @@ -431,7 +431,7 @@ class LIBTSB_EXTERN TSBBase * @see getLevel() * @see getVersion() */ - virtual XMLNamespaces* getNamespaces(); + virtual XMLNamespaces* getNamespaces(); /** @@ -788,7 +788,7 @@ class LIBTSB_EXTERN TSBBase * @see appendTestAnnotation(const std::string& annotation) * @see unsetTestAnnotation() */ - virtual int setTestAnnotation ( XMLNode* annotation); + virtual int setTestAnnotation (XMLNode* annotation); /** @@ -876,7 +876,7 @@ class LIBTSB_EXTERN TSBBase * @see appendTestAnnotation(const std::string& annotation) * @see unsetTestAnnotation() */ - virtual int appendTestAnnotation (const XMLNode* annotation); + virtual int appendTestAnnotation (const XMLNode* annotation); /** @@ -977,7 +977,7 @@ class LIBTSB_EXTERN TSBBase * @see removeTopLevelTestAnnotationElement(const std::string elementName, const std::string elementURI) * @see replaceTopLevelTestAnnotationElement(const std::string&) */ - int replaceTopLevelTestAnnotationElement(const XMLNode* annotation); + int replaceTopLevelTestAnnotationElement(const XMLNode* annotation); /** @@ -1051,7 +1051,7 @@ class LIBTSB_EXTERN TSBBase * @see unsetNotes() * @see SyntaxChecker::hasExpectedXHTMLSyntax(@if java XMLNode@endif) */ - int setNotes(const XMLNode* notes); + int setNotes(const XMLNode* notes); /** @@ -1148,7 +1148,7 @@ class LIBTSB_EXTERN TSBBase * @see unsetNotes() * @see SyntaxChecker::hasExpectedXHTMLSyntax(@if java XMLNode@endif) */ - int appendNotes(const XMLNode* notes); + int appendNotes(const XMLNode* notes); /** @@ -1259,7 +1259,7 @@ class LIBTSB_EXTERN TSBBase * @copydetails doc_returns_success_code * @li @tsbconstant{LIBTSB_OPERATION_SUCCESS, OperationReturnValues_t} */ - int setNamespaces( XMLNamespaces* xmlns); + int setNamespaces(XMLNamespaces* xmlns); /** @@ -1558,7 +1558,7 @@ class LIBTSB_EXTERN TSBBase /** * Reads (initializes) this TSB object by reading from XMLInputStream. */ - void read ( XMLInputStream& stream); + void read (XMLInputStream& stream); /** @endcond */ @@ -1566,7 +1566,7 @@ class LIBTSB_EXTERN TSBBase /** * Writes (serializes) this TSB object by writing it to XMLOutputStream. */ - virtual void write ( XMLOutputStream& stream) const; + virtual void write (XMLOutputStream& stream) const; /** @endcond */ @@ -1582,7 +1582,7 @@ class LIBTSB_EXTERN TSBBase * ... * @endif@~ */ - virtual void writeElements ( XMLOutputStream& stream) const; + virtual void writeElements (XMLOutputStream& stream) const; /** @endcond */ @@ -1800,7 +1800,7 @@ class LIBTSB_EXTERN TSBBase * @return the TSB object corresponding to next XMLToken in the * XMLInputStream or @c NULL if the token was not recognized. */ - virtual TSBBase* createObject ( XMLInputStream& stream); + virtual TSBBase* createObject (XMLInputStream& stream); /** @@ -1817,7 +1817,7 @@ class LIBTSB_EXTERN TSBBase * @return @c true if the level, version and namespace values of this * TSB object correspond to a valid set of values, @c false otherwise. */ - bool hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns); + bool hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns); /** @@ -1826,7 +1826,7 @@ class LIBTSB_EXTERN TSBBase * * @return true if the subclass read from the stream, false otherwise. */ - virtual bool readOtherXML ( XMLInputStream& stream); + virtual bool readOtherXML (XMLInputStream& stream); /** @@ -1896,8 +1896,8 @@ class LIBTSB_EXTERN TSBBase * XMLAttributes set into their specific fields. Be sure to call your * parents implementation of this method as well. */ - virtual void readAttributes (const XMLAttributes& attributes, - const ExpectedAttributes& expectedAttributes); + virtual void readAttributes (const XMLAttributes& attributes, + const ExpectedAttributes& expectedAttributes); /** @@ -1914,7 +1914,7 @@ class LIBTSB_EXTERN TSBBase * Be sure to implement wirteXMLNS() function to write xmlns attributes. * */ - virtual void writeAttributes ( XMLOutputStream& stream) const; + virtual void writeAttributes (XMLOutputStream& stream) const; /** @@ -1923,7 +1923,7 @@ class LIBTSB_EXTERN TSBBase * (if any) to the XMLOutputStream. * */ - virtual void writeXMLNS ( XMLOutputStream& stream) const; + virtual void writeXMLNS (XMLOutputStream& stream) const; /** @@ -1937,7 +1937,7 @@ class LIBTSB_EXTERN TSBBase * Checks that the given default namespace in the given element is valid. * If the given default namespace is not valid, an error is logged. */ - void checkDefaultNamespace(const XMLNamespaces* xmlns, + void checkDefaultNamespace(const XMLNamespaces* xmlns, const std::string& elementName, const std::string& prefix = ""); /** @@ -1952,13 +1952,13 @@ class LIBTSB_EXTERN TSBBase * If the xhtml does not conform to the specification of valid xhtml within * an tsb document, an error is logged. */ - void checkXHTML(const XMLNode *); + void checkXHTML(const XMLNode *); /** * Checks that the math ml ns has been declared */ - const std::string checkMathMLNamespace(const XMLToken elem); + const std::string checkMathMLNamespace(const XMLToken elem); /** * Sets the XML namespace to which this element belongs to. @@ -2012,8 +2012,8 @@ class LIBTSB_EXTERN TSBBase std::string mMetaId; std::string mId; - XMLNode* mNotes; - XMLNode* mTestAnnotation; + XMLNode* mNotes; + XMLNode* mTestAnnotation; TSBDocument* mTSB; TSBNamespaces* mTSBNamespaces; void* mUserData; @@ -2054,7 +2054,7 @@ class LIBTSB_EXTERN TSBBase * Stores the location (line and column) and any XML namespaces (for * roundtripping) declared on this TSB (XML) element. */ - void setTSBBaseFields (const XMLToken& element); + void setTSBBaseFields (const XMLToken& element); /** @@ -2062,7 +2062,7 @@ class LIBTSB_EXTERN TSBBase * * @return true if read an element from the stream */ - bool readTestAnnotation ( XMLInputStream& stream); + bool readTestAnnotation (XMLInputStream& stream); /** @@ -2070,7 +2070,7 @@ class LIBTSB_EXTERN TSBBase * * @return true if read a element from the stream */ - bool readNotes ( XMLInputStream& stream); + bool readNotes (XMLInputStream& stream); /** @endcond */ @@ -2136,12 +2136,6 @@ TSBBase_getParentTSBObject (TSBBase_t *sb); * Returns the ancestor TSBBase_t structure of the given TSBBase_t * structure that corresponds to the given type. * - * This function allows any structure to determine its exact - * location/function within a model. For example a - * StoichiometryMath_t structure has ancestors of type SpeciesReference_t, - * TSBListOf_t(Products/Reactants), Reaction_t, TSBListOfReactions_t and Model_t; - * any of which can be accessed via this function. - * * @param sb the TSBBase_t structure * @param type the typecode (int) of the structure to be returned * From 29fd5bab74960466bcac4e93c843af66dfd4e069 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 24 May 2023 12:37:08 +0100 Subject: [PATCH 02/37] small changes to target file --- deviser/code_files/templates/SBase.h | 97 ++++++++++------------------ 1 file changed, 34 insertions(+), 63 deletions(-) diff --git a/deviser/code_files/templates/SBase.h b/deviser/code_files/templates/SBase.h index 36e442ac..48d7d800 100644 --- a/deviser/code_files/templates/SBase.h +++ b/deviser/code_files/templates/SBase.h @@ -2,19 +2,14 @@ #define SBase_h -#include -#include - -#include - -#include +#include +#include +#include #include #include #include +#include -#include -#include -#include #include @@ -29,9 +24,6 @@ #include -LIBSBML_CPP_NAMESPACE_BEGIN - -class Model; class List; @@ -41,7 +33,6 @@ class XMLNamespaces; class XMLOutputStream; class XMLToken; -LIBSBML_CPP_NAMESPACE_END LIBSBML_CPP_NAMESPACE_BEGIN @@ -209,7 +200,7 @@ class LIBSBML_EXTERN SBase * @see unset() * @see SyntaxChecker::hasExpectedXHTMLSyntax(@if java XMLNode@endif) */ - XMLNode* get(); + XMLNode* get(); /** @@ -235,7 +226,7 @@ class LIBSBML_EXTERN SBase * @see unset() * @see SyntaxChecker::hasExpectedXHTMLSyntax(@if java XMLNode@endif) */ - const XMLNode* get() const; + const XMLNode* get() const; /** @@ -306,7 +297,7 @@ class LIBSBML_EXTERN SBase * @see append(const std::string& annotation) * @see unset() */ - XMLNode* get (); + XMLNode* get (); /** @@ -329,7 +320,7 @@ class LIBSBML_EXTERN SBase * @see append(const std::string& annotation) * @see unset() */ - const XMLNode* get () const; + const XMLNode* get () const; /** @@ -386,7 +377,7 @@ class LIBSBML_EXTERN SBase * @see getLevel() * @see getVersion() */ - virtual const XMLNamespaces* getNamespaces() const ; + virtual const XMLNamespaces* getNamespaces() const ; /** @@ -403,7 +394,7 @@ class LIBSBML_EXTERN SBase * @see getLevel() * @see getVersion() */ - virtual XMLNamespaces* getNamespaces(); + virtual XMLNamespaces* getNamespaces(); /** @@ -760,7 +751,7 @@ class LIBSBML_EXTERN SBase * @see append(const std::string& annotation) * @see unset() */ - virtual int set (XMLNode* annotation); + virtual int set (XMLNode* annotation); /** @@ -848,7 +839,7 @@ class LIBSBML_EXTERN SBase * @see append(const std::string& annotation) * @see unset() */ - virtual int append (const XMLNode* annotation); + virtual int append (const XMLNode* annotation); /** @@ -949,7 +940,7 @@ class LIBSBML_EXTERN SBase * @see removeTopLevelElement(const std::string elementName, const std::string elementURI) * @see replaceTopLevelElement(const std::string&) */ - int replaceTopLevelElement(const XMLNode* annotation); + int replaceTopLevelElement(const XMLNode* annotation); /** @@ -1023,7 +1014,7 @@ class LIBSBML_EXTERN SBase * @see unset() * @see SyntaxChecker::hasExpectedXHTMLSyntax(@if java XMLNode@endif) */ - int set(const XMLNode* notes); + int set(const XMLNode* notes); /** @@ -1120,7 +1111,7 @@ class LIBSBML_EXTERN SBase * @see unset() * @see SyntaxChecker::hasExpectedXHTMLSyntax(@if java XMLNode@endif) */ - int append(const XMLNode* notes); + int append(const XMLNode* notes); /** @@ -1231,7 +1222,7 @@ class LIBSBML_EXTERN SBase * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} */ - int setNamespaces(XMLNamespaces* xmlns); + int setNamespaces(XMLNamespaces* xmlns); /** @@ -1530,7 +1521,7 @@ class LIBSBML_EXTERN SBase /** * Reads (initializes) this SBML_Lang object by reading from XMLInputStream. */ - void read (XMLInputStream& stream); + void read (XMLInputStream& stream); /** @endcond */ @@ -1538,7 +1529,7 @@ class LIBSBML_EXTERN SBase /** * Writes (serializes) this SBML_Lang object by writing it to XMLOutputStream. */ - virtual void write (XMLOutputStream& stream) const; + virtual void write (XMLOutputStream& stream) const; /** @endcond */ @@ -1554,7 +1545,7 @@ class LIBSBML_EXTERN SBase * ... * @endif@~ */ - virtual void writeElements (XMLOutputStream& stream) const; + virtual void writeElements (XMLOutputStream& stream) const; /** @endcond */ @@ -1772,7 +1763,7 @@ class LIBSBML_EXTERN SBase * @return the SBML_Lang object corresponding to next XMLToken in the * XMLInputStream or @c NULL if the token was not recognized. */ - virtual SBase* createObject (XMLInputStream& stream); + virtual SBase* createObject (XMLInputStream& stream); /** @@ -1789,7 +1780,7 @@ class LIBSBML_EXTERN SBase * @return @c true if the level, version and namespace values of this * SBML_Lang object correspond to a valid set of values, @c false otherwise. */ - bool hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns); + bool hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns); /** @@ -1798,7 +1789,7 @@ class LIBSBML_EXTERN SBase * * @return true if the subclass read from the stream, false otherwise. */ - virtual bool readOtherXML (XMLInputStream& stream); + virtual bool readOtherXML (XMLInputStream& stream); /** @@ -1868,8 +1859,8 @@ class LIBSBML_EXTERN SBase * XMLAttributes set into their specific fields. Be sure to call your * parents implementation of this method as well. */ - virtual void readAttributes (const XMLAttributes& attributes, - const ExpectedAttributes& expectedAttributes); + virtual void readAttributes (const XMLAttributes& attributes, + const ExpectedAttributes& expectedAttributes); /** @@ -1886,7 +1877,7 @@ class LIBSBML_EXTERN SBase * Be sure to implement wirteXMLNS() function to write xmlns attributes. * */ - virtual void writeAttributes (XMLOutputStream& stream) const; + virtual void writeAttributes (XMLOutputStream& stream) const; /** @@ -1895,7 +1886,7 @@ class LIBSBML_EXTERN SBase * (if any) to the XMLOutputStream. * */ - virtual void writeXMLNS (XMLOutputStream& stream) const; + virtual void writeXMLNS (XMLOutputStream& stream) const; /** @@ -1909,7 +1900,7 @@ class LIBSBML_EXTERN SBase * Checks that the given default namespace in the given element is valid. * If the given default namespace is not valid, an error is logged. */ - void checkDefaultNamespace(const XMLNamespaces* xmlns, + void checkDefaultNamespace(const XMLNamespaces* xmlns, const std::string& elementName, const std::string& prefix = ""); /** @@ -1924,13 +1915,13 @@ class LIBSBML_EXTERN SBase * If the xhtml does not conform to the specification of valid xhtml within * an sbml document, an error is logged. */ - void checkXHTML(const XMLNode *); + void checkXHTML(const XMLNode *); /** * Checks that the math ml ns has been declared */ - const std::string checkMathMLNamespace(const XMLToken elem); + const std::string checkMathMLNamespace(const XMLToken elem); /** * Sets the XML namespace to which this element belongs to. @@ -1984,8 +1975,8 @@ class LIBSBML_EXTERN SBase std::string mMetaId; std::string mId; - XMLNode* m; - XMLNode* m; + XMLNode* m; + XMLNode* m; SBMLDocument* mSBML; SBMLNamespaces* mSBMLNamespaces; void* mUserData; @@ -2026,7 +2017,7 @@ class LIBSBML_EXTERN SBase * Stores the location (line and column) and any XML namespaces (for * roundtripping) declared on this SBML_Lang (XML) element. */ - void setSBaseFields (const XMLToken& element); + void setSBaseFields (const XMLToken& element); /** @@ -2034,7 +2025,7 @@ class LIBSBML_EXTERN SBase * * @return true if read an element from the stream */ - bool read (XMLInputStream& stream); + bool read (XMLInputStream& stream); /** @@ -2042,7 +2033,7 @@ class LIBSBML_EXTERN SBase * * @return true if read a element from the stream */ - bool read (XMLInputStream& stream); + bool read (XMLInputStream& stream); /** @endcond */ @@ -2108,12 +2099,6 @@ SBase_getParentSBMLObject (SBase_t *sb); * Returns the ancestor SBase_t structure of the given SBase_t * structure that corresponds to the given type. * - * This function allows any structure to determine its exact - * location/function within a model. For example a - * StoichiometryMath_t structure has ancestors of type SpeciesReference_t, - * ListOf_t(Products/Reactants), Reaction_t, ListOfReactions_t and Model_t; - * any of which can be accessed via this function. - * * @param sb the SBase_t structure * @param type the typecode (int) of the structure to be returned * @@ -2522,20 +2507,6 @@ int SBase_unset (SBase_t *sb); -/** - * Returns the Model_t structure in which the given instance is located. - * - * @param sb the SBase_t structure - * - * @return the parent Model_t strucdture of the given structure. - * - * @memberof SBase_t - */ -LIBSBML_EXTERN -const Model_t * -SBase_getModel (const SBase_t *sb); - - /** * Returns the SBML_Lang Level of the overall SBML_Lang document. * From cfe85a23ef49ec9d9f92b799fe080d812032c7ab Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 24 May 2023 16:01:09 +0100 Subject: [PATCH 03/37] for lib tsb dont need ml --- deviser/code_files/OtherLibraryFiles.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deviser/code_files/OtherLibraryFiles.py b/deviser/code_files/OtherLibraryFiles.py index bd78ce20..0431846c 100644 --- a/deviser/code_files/OtherLibraryFiles.py +++ b/deviser/code_files/OtherLibraryFiles.py @@ -428,9 +428,9 @@ def print_document_errors(self, fileout): docname = SF.remove_prefix(doc['name'], remove_package=False, remove_doc_prefix=True) libname = SF.get_library_suffix(gv.library_name) - if not libname.endswith('ml'): - libname = libname + 'ml' - fileout.copy_line_verbatim((10 * '') + 'if ( errorId == {0}{1}Allowed' +# if not libname.endswith('ml'): +# libname = libname + 'ml' + fileout.copy_line_verbatim((10 * ' ') + 'if ( errorId == {0}{1}Allowed' 'CoreAttributes\n'.format(libname, docname)) level = False version = False From 243c5e42e79f096478164d3c1980cb66203188bf Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 24 May 2023 16:01:33 +0100 Subject: [PATCH 04/37] update template --- .../test-code/tsb/TSBBase.cpp | 200 +++++++++--------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp b/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp index a1d44c79..ad24ae59 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp @@ -183,12 +183,12 @@ TSBBase::TSBBase(const TSBBase& orig) , mURI(orig.mURI) { if(orig.mNotes != NULL) - this->mNotes = new XMLNode(*const_cast(orig).getNotes()); + this->mNotes = new XMLNode(*const_cast(orig).getNotes()); else this->mNotes = NULL; if(orig.mTestAnnotation != NULL) - this->mTestAnnotation = new XMLNode(*const_cast(orig).mTestAnnotation); + this->mTestAnnotation = new XMLNode(*const_cast(orig).mTestAnnotation); else this->mTestAnnotation = NULL; @@ -226,14 +226,14 @@ TSBBase& TSBBase::operator=(const TSBBase& rhs) delete this->mNotes; if(rhs.mNotes != NULL) - this->mNotes = new XMLNode(*const_cast(rhs).getNotes()); + this->mNotes = new XMLNode(*const_cast(rhs).getNotes()); else this->mNotes = NULL; delete this->mTestAnnotation; if(rhs.mTestAnnotation != NULL) - this->mTestAnnotation = new XMLNode(*const_cast(rhs).mTestAnnotation); + this->mTestAnnotation = new XMLNode(*const_cast(rhs).mTestAnnotation); else this->mTestAnnotation = NULL; @@ -289,14 +289,14 @@ TSBBase::getId() const /* * @return the notes of this TSB object. */ - XMLNode* +XMLNode* TSBBase::getNotes() { return mNotes; } -const XMLNode* +const XMLNode* TSBBase::getNotes() const { return mNotes; @@ -309,28 +309,28 @@ TSBBase::getNotes() const std::string TSBBase::getNotesString() { - return XMLNode::convertXMLNodeToString(mNotes); + return XMLNode::convertXMLNodeToString(mNotes); } std::string TSBBase::getNotesString() const { - return XMLNode::convertXMLNodeToString(mNotes); + return XMLNode::convertXMLNodeToString(mNotes); } /* * @return the annotation of this TSB object. */ - XMLNode* +XMLNode* TSBBase::getTestAnnotation () { return mTestAnnotation; } -const XMLNode* +const XMLNode* TSBBase::getTestAnnotation () const { return const_cast(this)->getTestAnnotation(); @@ -343,14 +343,14 @@ TSBBase::getTestAnnotation () const std::string TSBBase::getTestAnnotationString () { - return XMLNode::convertXMLNodeToString(getTestAnnotation()); + return XMLNode::convertXMLNodeToString(getTestAnnotation()); } std::string TSBBase::getTestAnnotationString () const { - return XMLNode::convertXMLNodeToString(getTestAnnotation()); + return XMLNode::convertXMLNodeToString(getTestAnnotation()); } @@ -428,7 +428,7 @@ TSBBase::unsetUserData() /* * @return the Namespaces associated with this TSB object */ - XMLNamespaces* +XMLNamespaces* TSBBase::getNamespaces() { if (mTSB != NULL) @@ -438,7 +438,7 @@ TSBBase::getNamespaces() } -const XMLNamespaces* +const XMLNamespaces* TSBBase::getNamespaces() const { if (mTSB != NULL) @@ -662,7 +662,7 @@ TSBBase::setId (const std::string& sid) * Sets the annotation of this TSB object to a copy of annotation. */ int -TSBBase::setTestAnnotation ( XMLNode* annotation) +TSBBase::setTestAnnotation (XMLNode* annotation) { if (annotation == NULL) { @@ -695,17 +695,17 @@ TSBBase::setTestAnnotation (const std::string& annotation) return LIBTSB_OPERATION_SUCCESS; } - XMLNode* annt_xmln; + XMLNode* annt_xmln; // you might not have a document !! if (getTSBDocument() != NULL) { - XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); - annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); + XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); + annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); } else { - annt_xmln = XMLNode::convertStringToXMLNode(annotation); + annt_xmln = XMLNode::convertStringToXMLNode(annotation); } if(annt_xmln != NULL) @@ -723,7 +723,7 @@ TSBBase::setTestAnnotation (const std::string& annotation) * adding additional information. */ int -TSBBase::appendTestAnnotation (const XMLNode* annotation) +TSBBase::appendTestAnnotation (const XMLNode* annotation) { int success = LIBTSB_OPERATION_FAILED; unsigned int duplicates = 0; @@ -731,14 +731,14 @@ TSBBase::appendTestAnnotation (const XMLNode* annotation) if(annotation == NULL) return LIBTSB_OPERATION_SUCCESS; - XMLNode* new_annotation = NULL; + XMLNode* new_annotation = NULL; const string& name = annotation->getName(); // check for annotation tags and add if necessary if (name != "testAnnotation") { - XMLToken ann_t = XMLToken( XMLTriple("testAnnotation", "", ""), XMLAttributes()); - new_annotation = new XMLNode(ann_t); + XMLToken ann_t = XMLToken(XMLTriple("testAnnotation", "", ""), XMLAttributes()); + new_annotation = new XMLNode(ann_t); new_annotation->addChild(*annotation); } else @@ -787,7 +787,7 @@ TSBBase::appendTestAnnotation (const XMLNode* annotation) } else { - XMLNode *copy = mTestAnnotation->clone(); + XMLNode *copy = mTestAnnotation->clone(); success = setTestAnnotation(copy); delete copy; } @@ -813,15 +813,15 @@ int TSBBase::appendTestAnnotation (const std::string& annotation) { int success = LIBTSB_OPERATION_FAILED; - XMLNode* annt_xmln; + XMLNode* annt_xmln; if (getTSBDocument() != NULL) { - XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); - annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); + XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); + annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); } else { - annt_xmln = XMLNode::convertStringToXMLNode(annotation); + annt_xmln = XMLNode::convertStringToXMLNode(annotation); } if(annt_xmln != NULL) @@ -858,7 +858,7 @@ TSBBase::removeTopLevelTestAnnotationElement(const std::string elementName, // check uri matches if (elementURI.empty() == false) { - XMLNode child = mTestAnnotation->getChild(index); + XMLNode child = mTestAnnotation->getChild(index); std::string prefix = child.getPrefix(); if (prefix.empty() == false @@ -910,10 +910,10 @@ TSBBase::removeTopLevelTestAnnotationElement(const std::string elementName, int -TSBBase::replaceTopLevelTestAnnotationElement(const XMLNode* annotation) +TSBBase::replaceTopLevelTestAnnotationElement(const XMLNode* annotation) { int success = LIBTSB_OPERATION_FAILED; - XMLNode * replacement = NULL; + XMLNode * replacement = NULL; if (annotation->getName() == "testAnnotation") { if (annotation->getNumChildren() != 1) @@ -947,15 +947,15 @@ int TSBBase::replaceTopLevelTestAnnotationElement(const std::string& annotation) { int success = LIBTSB_OPERATION_FAILED; - XMLNode* annt_xmln; + XMLNode* annt_xmln; if (getTSBDocument() != NULL) { - XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); - annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); + XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); + annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); } else { - annt_xmln = XMLNode::convertStringToXMLNode(annotation); + annt_xmln = XMLNode::convertStringToXMLNode(annotation); } if(annt_xmln != NULL) @@ -973,7 +973,7 @@ TSBBase::replaceTopLevelTestAnnotationElement(const std::string& annotation) * Sets the notes of this TSB object to a copy of notes. */ int -TSBBase::setNotes(const XMLNode* notes) +TSBBase::setNotes(const XMLNode* notes) { if (mNotes == notes) { @@ -993,13 +993,13 @@ TSBBase::setNotes(const XMLNode* notes) if (name == "notes") { - mNotes = static_cast< XMLNode*>( notes->clone() ); + mNotes = static_cast( notes->clone() ); } else { - XMLToken notes_t = XMLToken( XMLTriple("notes", "", ""), - XMLAttributes()); - mNotes = new XMLNode(notes_t); + XMLToken notes_t = XMLToken(XMLTriple("notes", "", ""), + XMLAttributes()); + mNotes = new XMLNode(notes_t); // The root node of the given XMLNode tree can be an empty XMLNode // (i.e. neither start, end, nor text XMLNode) if the given notes was @@ -1041,17 +1041,17 @@ TSBBase::setNotes(const std::string& notes, bool addXHTMLMarkup) } else { - XMLNode* notes_xmln; + XMLNode* notes_xmln; // you might not have a document !! if (getTSBDocument() != NULL) { - XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); - notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); + XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); + notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); } else { - notes_xmln = XMLNode::convertStringToXMLNode(notes); + notes_xmln = XMLNode::convertStringToXMLNode(notes); } if (notes_xmln != NULL) @@ -1064,11 +1064,11 @@ TSBBase::setNotes(const std::string& notes, bool addXHTMLMarkup) && notes_xmln->isText() == true) { //create a parent node of xhtml type p - XMLAttributes blank_att = XMLAttributes(); - XMLTriple triple = XMLTriple("p", "http://www.w3.org/1999/xhtml", ""); - XMLNamespaces xmlns = XMLNamespaces(); + XMLAttributes blank_att = XMLAttributes(); + XMLTriple triple = XMLTriple("p", "http://www.w3.org/1999/xhtml", ""); + XMLNamespaces xmlns = XMLNamespaces(); xmlns.add("http://www.w3.org/1999/xhtml", ""); - XMLNode *xmlnode = new XMLNode( XMLToken(triple, blank_att, xmlns)); + XMLNode *xmlnode = new XMLNode(XMLToken(triple, blank_att, xmlns)); // create a text node from the text given xmlnode->addChild(*notes_xmln); @@ -1098,7 +1098,7 @@ TSBBase::setNotes(const std::string& notes, bool addXHTMLMarkup) * adding additional information. */ int -TSBBase::appendNotes(const XMLNode* notes) +TSBBase::appendNotes(const XMLNode* notes) { int success = LIBTSB_OPERATION_FAILED; if(notes == NULL) @@ -1127,7 +1127,7 @@ TSBBase::appendNotes(const XMLNode* notes) typedef enum { _ANotesHTML, _ANotesBody, _ANotesAny } _NotesType; _NotesType addedNotesType = _ANotesAny; - XMLNode addedNotes; + XMLNode addedNotes; //------------------------------------------------------------ // @@ -1238,7 +1238,7 @@ TSBBase::appendNotes(const XMLNode* notes) if (getLevel() > 2 || (getLevel() == 2 && getVersion() > 1)) { - XMLNode tmpNotes( XMLTriple("notes","",""), XMLAttributes()); + XMLNode tmpNotes(XMLTriple("notes","",""), XMLAttributes()); if (addedNotesType == _ANotesAny) { @@ -1263,7 +1263,7 @@ TSBBase::appendNotes(const XMLNode* notes) //------------------------------------------------------------ _NotesType curNotesType = _ANotesAny; - XMLNode& curNotes = *mNotes; + XMLNode& curNotes = *mNotes; // curNotes.getChild(0) must be "html", "body", or any XHTML // element that would be permitted within a "body" element . @@ -1272,7 +1272,7 @@ TSBBase::appendNotes(const XMLNode* notes) if (cname == "html") { - XMLNode& curHTML = curNotes.getChild(0); + XMLNode& curHTML = curNotes.getChild(0); // // checks the curHTML if the html tag contains "head" and "body" tags // which must be located in this order, otherwise nothing will be done. @@ -1312,14 +1312,14 @@ TSBBase::appendNotes(const XMLNode* notes) if (curNotesType == _ANotesHTML) { - XMLNode& curHTML = curNotes.getChild(0); - XMLNode& curBody = curHTML.getChild(1); + XMLNode& curHTML = curNotes.getChild(0); + XMLNode& curBody = curHTML.getChild(1); if (addedNotesType == _ANotesHTML) { // adds the given html tag to the current html tag - XMLNode& addedBody = addedNotes.getChild(1); + XMLNode& addedBody = addedNotes.getChild(1); for (i=0; i < addedBody.getNumChildren(); i++) { @@ -1347,9 +1347,9 @@ TSBBase::appendNotes(const XMLNode* notes) { // adds the given html tag to the current body tag - XMLNode addedHTML(addedNotes); - XMLNode& addedBody = addedHTML.getChild(1); - XMLNode& curBody = curNotes.getChild(0); + XMLNode addedHTML(addedNotes); + XMLNode& addedBody = addedHTML.getChild(1); + XMLNode& curBody = curNotes.getChild(0); for (i=0; i < curBody.getNumChildren(); i++) { @@ -1365,7 +1365,7 @@ TSBBase::appendNotes(const XMLNode* notes) // adds the given body or other tag (permitted in the body) to the current // body tag - XMLNode& curBody = curNotes.getChild(0); + XMLNode& curBody = curNotes.getChild(0); for (i=0; i < addedNotes.getNumChildren(); i++) { @@ -1381,8 +1381,8 @@ TSBBase::appendNotes(const XMLNode* notes) { // adds the given html tag to the current any tag permitted in the body. - XMLNode addedHTML(addedNotes); - XMLNode& addedBody = addedHTML.getChild(1); + XMLNode addedHTML(addedNotes); + XMLNode& addedBody = addedHTML.getChild(1); for (i=0; i < curNotes.getNumChildren(); i++) { @@ -1397,7 +1397,7 @@ TSBBase::appendNotes(const XMLNode* notes) { // adds the given body tag to the current any tag permitted in the body. - XMLNode addedBody(addedNotes); + XMLNode addedBody(addedNotes); for (i=0; i < curNotes.getNumChildren(); i++) { @@ -1445,16 +1445,16 @@ TSBBase::appendNotes(const std::string& notes) return LIBTSB_OPERATION_SUCCESS; } - XMLNode* notes_xmln; + XMLNode* notes_xmln; // you might not have a document !! if (getTSBDocument() != NULL) { - XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); - notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); + XMLNamespaces* xmlns = getTSBDocument()->getNamespaces(); + notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); } else { - notes_xmln = XMLNode::convertStringToXMLNode(notes); + notes_xmln = XMLNode::convertStringToXMLNode(notes); } if(notes_xmln != NULL) @@ -1578,7 +1578,7 @@ TSBBase::getAncestorOfType(int type) const * @param xmlns the namespaces to set */ int -TSBBase::setNamespaces( XMLNamespaces* xmlns) +TSBBase::setNamespaces(XMLNamespaces* xmlns) { if (xmlns == NULL) { @@ -1650,7 +1650,7 @@ TSBBase::unsetNotes () int TSBBase::unsetTestAnnotation () { - XMLNode* empty = NULL; + XMLNode* empty = NULL; return setTestAnnotation(empty); } @@ -1708,7 +1708,7 @@ bool TSBBase::hasValidLevelVersionNamespaceCombination() { int typecode = getTypeCode(); - XMLNamespaces *xmlns = getNamespaces(); + XMLNamespaces *xmlns = getNamespaces(); return hasValidLevelVersionNamespaceCombination(typecode, xmlns); } @@ -1806,7 +1806,7 @@ TSBBase::matchesCoreTSBNamespace(const TSBBase * sb) const bool -TSBBase::hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns) +TSBBase::hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns) { @@ -1900,7 +1900,7 @@ char* TSBBase::toTSB () { ostringstream os; - XMLOutputStream stream(os, "UTF-8", false); + XMLOutputStream stream(os, "UTF-8", false); write(stream); @@ -2104,11 +2104,11 @@ TSBBase::getObject(const std::string& objectName, unsigned int index) * Reads (initializes) this TSB object by reading from XMLInputStream. */ void -TSBBase::read ( XMLInputStream& stream) +TSBBase::read (XMLInputStream& stream) { if ( !stream.peek().isStart() ) return; - const XMLToken element = stream.next(); + const XMLToken element = stream.next(); int position = 0; setTSBBaseFields( element ); @@ -2128,7 +2128,7 @@ TSBBase::read ( XMLInputStream& stream) // need to check that any prefix on the tsbns also occurs on element // remembering the horrible situation where the tsbns might be declared // with more than one prefix - XMLNamespaces * xmlns = this->getTSBNamespaces()->getNamespaces(); + XMLNamespaces * xmlns = this->getTSBNamespaces()->getNamespaces(); if (xmlns != NULL) { int i = xmlns->getIndexByPrefix(element.getPrefix()); @@ -2188,7 +2188,7 @@ TSBBase::read ( XMLInputStream& stream) checkDefaultNamespace(mTSBNamespaces->getNamespaces(), element.getName()); if (!element.getPrefix().empty()) { - XMLNamespaces * prefixedNS = new XMLNamespaces(); + XMLNamespaces * prefixedNS = new XMLNamespaces(); prefixedNS->add(element.getURI(), element.getPrefix()); checkDefaultNamespace(prefixedNS, element.getName(), element.getPrefix()); delete prefixedNS; @@ -2209,7 +2209,7 @@ TSBBase::read ( XMLInputStream& stream) } setElementText(text); - const XMLToken& next = stream.peek(); + const XMLToken& next = stream.peek(); // Re-check stream.isGood() because stream.peek() could hit something. if ( !stream.isGood() ) break; @@ -2264,7 +2264,7 @@ TSBBase::setElementText(const std::string &text) * Writes (serializes) this TSB object by writing it to XMLOutputStream. */ void -TSBBase::write ( XMLOutputStream& stream) const +TSBBase::write (XMLOutputStream& stream) const { stream.startElement( getElementName(), getPrefix() ); @@ -2285,7 +2285,7 @@ TSBBase::write ( XMLOutputStream& stream) const * implementation of this method as well. */ void -TSBBase::writeElements ( XMLOutputStream& stream) const +TSBBase::writeElements (XMLOutputStream& stream) const { if ( mNotes != NULL ) stream << *mNotes; @@ -2303,7 +2303,7 @@ TSBBase::writeElements ( XMLOutputStream& stream) const * XMLInputStream or @c NULL if the token was not recognized. */ TSBBase* -TSBBase::createObject ( XMLInputStream& stream) +TSBBase::createObject (XMLInputStream& stream) { return NULL; } @@ -2320,7 +2320,7 @@ TSBBase::createObject ( XMLInputStream& stream) * @return true if the subclass read from the stream, false otherwise. */ bool -TSBBase::readOtherXML ( XMLInputStream& stream) +TSBBase::readOtherXML (XMLInputStream& stream) { bool read = false; return read; @@ -2333,7 +2333,7 @@ TSBBase::readOtherXML ( XMLInputStream& stream) * @return true if read an element from the stream */ bool -TSBBase::readTestAnnotation ( XMLInputStream& stream) +TSBBase::readTestAnnotation (XMLInputStream& stream) { const string& name = stream.peek().getName(); @@ -2350,7 +2350,7 @@ TSBBase::readTestAnnotation ( XMLInputStream& stream) } delete mTestAnnotation; - mTestAnnotation = new XMLNode(stream); + mTestAnnotation = new XMLNode(stream); checkTestAnnotation(); return true; } @@ -2365,7 +2365,7 @@ TSBBase::readTestAnnotation ( XMLInputStream& stream) * @return true if read a element from the stream */ bool -TSBBase::readNotes ( XMLInputStream& stream) +TSBBase::readNotes (XMLInputStream& stream) { const string& name = stream.peek().getName(); @@ -2381,13 +2381,13 @@ TSBBase::readNotes ( XMLInputStream& stream) } delete mNotes; - mNotes = new XMLNode(stream); + mNotes = new XMLNode(stream); // // checks if the given default namespace (if any) is a valid // TSB namespace // - const XMLNamespaces &xmlns = mNotes->getNamespaces(); + const XMLNamespaces &xmlns = mNotes->getNamespaces(); checkDefaultNamespace(&xmlns,"notes"); return true; @@ -2556,10 +2556,10 @@ TSBBase::addExpectedAttributes(ExpectedAttributes& attributes) * parents implementation of this method as well. */ void -TSBBase::readAttributes (const XMLAttributes& attributes, - const ExpectedAttributes& expectedAttributes) +TSBBase::readAttributes (const XMLAttributes& attributes, + const ExpectedAttributes& expectedAttributes) { - const_cast< XMLAttributes&>(attributes).setErrorLog(getErrorLog()); + const_cast(attributes).setErrorLog(getErrorLog()); const unsigned int level = getLevel (); const unsigned int version = getVersion(); @@ -2623,7 +2623,7 @@ TSBBase::getPrefix() const { std::string prefix = ""; - const XMLNamespaces *xmlns = getNamespaces(); + const XMLNamespaces *xmlns = getNamespaces(); string uri = getURI(); if(xmlns && mTSB) { @@ -2642,7 +2642,7 @@ TSBBase::getTSBPrefix() const { std::string prefix = ""; - const XMLNamespaces *xmlns = getNamespaces(); + const XMLNamespaces *xmlns = getNamespaces(); if (xmlns == NULL) return getPrefix(); @@ -2687,7 +2687,7 @@ TSBBase::getRootElement() * of this method as well. */ void -TSBBase::writeAttributes ( XMLOutputStream& stream) const +TSBBase::writeAttributes (XMLOutputStream& stream) const { string tsbPrefix = getTSBPrefix(); if ( !mMetaId.empty() ) @@ -2706,7 +2706,7 @@ TSBBase::writeAttributes ( XMLOutputStream& stream) const * */ void -TSBBase::writeXMLNS ( XMLOutputStream& stream) const +TSBBase::writeXMLNS (XMLOutputStream& stream) const { // do nothing. } @@ -2764,7 +2764,7 @@ int TSBBase::removeFromParentAndDelete() /** @cond doxygenLibtsbInternal */ const std::string -TSBBase::checkMathMLNamespace(const XMLToken elem) +TSBBase::checkMathMLNamespace(const XMLToken elem) { std::string prefix = ""; unsigned int match = 0; @@ -2810,7 +2810,7 @@ TSBBase::checkMathMLNamespace(const XMLToken elem) /** @cond doxygenLibtsbInternal */ void -TSBBase::checkDefaultNamespace(const XMLNamespaces* xmlns, +TSBBase::checkDefaultNamespace(const XMLNamespaces* xmlns, const std::string& elementName, const std::string& prefix) { @@ -2860,12 +2860,12 @@ TSBBase::checkTestAnnotation() // checks if the given default namespace (if any) is a valid // TSB namespace // - const XMLNamespaces &xmlns = mTestAnnotation->getNamespaces(); + const XMLNamespaces &xmlns = mTestAnnotation->getNamespaces(); checkDefaultNamespace(&xmlns,"testAnnotation"); while (nNodes < mTestAnnotation->getNumChildren()) { - XMLNode topLevel = mTestAnnotation->getChild(nNodes); + XMLNode topLevel = mTestAnnotation->getChild(nNodes); // the top level must be an element (so it should be a start) if (topLevel.isStart() == false) @@ -2961,7 +2961,7 @@ TSBBase::checkTestAnnotation() * an tsb document, an error is logged. */ void -TSBBase::checkXHTML(const XMLNode * xhtml) +TSBBase::checkXHTML(const XMLNode * xhtml) { if (xhtml == NULL) return; @@ -3054,14 +3054,14 @@ TSBBase::checkCompatibility(const TSBBase * object) const * roundtripping) declared on this TSB (XML) element. */ void -TSBBase::setTSBBaseFields (const XMLToken& element) +TSBBase::setTSBBaseFields (const XMLToken& element) { mLine = element.getLine (); mColumn = element.getColumn(); if (element.getNamespaces().getLength() > 0) { - XMLNamespaces tmpxmlns(element.getNamespaces()); + XMLNamespaces tmpxmlns(element.getNamespaces()); setNamespaces(&tmpxmlns); } else From f80afd80918bcfa053244c0d5e2adebb34f49b0a Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 24 May 2023 16:02:05 +0100 Subject: [PATCH 05/37] small changes to target --- deviser/code_files/templates/SBase.cpp | 294 +++++++++---------------- 1 file changed, 103 insertions(+), 191 deletions(-) diff --git a/deviser/code_files/templates/SBase.cpp b/deviser/code_files/templates/SBase.cpp index 27bcc52d..1a8fdc40 100644 --- a/deviser/code_files/templates/SBase.cpp +++ b/deviser/code_files/templates/SBase.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include @@ -148,12 +147,12 @@ SBase::SBase(const SBase& orig) , mURI(orig.mURI) { if(orig.m != NULL) - this->m = new XMLNode(*const_cast(orig).get()); + this->m = new XMLNode(*const_cast(orig).get()); else this->m = NULL; if(orig.m != NULL) - this->m = new XMLNode(*const_cast(orig).m); + this->m = new XMLNode(*const_cast(orig).m); else this->m = NULL; @@ -191,14 +190,14 @@ SBase& SBase::operator=(const SBase& rhs) delete this->m; if(rhs.m != NULL) - this->m = new XMLNode(*const_cast(rhs).get()); + this->m = new XMLNode(*const_cast(rhs).get()); else this->m = NULL; delete this->m; if(rhs.m != NULL) - this->m = new XMLNode(*const_cast(rhs).m); + this->m = new XMLNode(*const_cast(rhs).m); else this->m = NULL; @@ -254,14 +253,14 @@ SBase::getId() const /* * @return the notes of this SBML_Lang object. */ -XMLNode* +XMLNode* SBase::get() { return m; } -const XMLNode* +const XMLNode* SBase::get() const { return m; @@ -274,28 +273,28 @@ SBase::get() const std::string SBase::getString() { - return XMLNode::convertXMLNodeToString(m); + return XMLNode::convertXMLNodeToString(m); } std::string SBase::getString() const { - return XMLNode::convertXMLNodeToString(m); + return XMLNode::convertXMLNodeToString(m); } /* * @return the annotation of this SBML_Lang object. */ -XMLNode* +XMLNode* SBase::get () { return m; } -const XMLNode* +const XMLNode* SBase::get () const { return const_cast(this)->get(); @@ -308,14 +307,14 @@ SBase::get () const std::string SBase::getString () { - return XMLNode::convertXMLNodeToString(get()); + return XMLNode::convertXMLNodeToString(get()); } std::string SBase::getString () const { - return XMLNode::convertXMLNodeToString(get()); + return XMLNode::convertXMLNodeToString(get()); } @@ -393,7 +392,7 @@ SBase::unsetUserData() /* * @return the Namespaces associated with this SBML_Lang object */ -XMLNamespaces* +XMLNamespaces* SBase::getNamespaces() { if (mSBML != NULL) @@ -403,7 +402,7 @@ SBase::getNamespaces() } -const XMLNamespaces* +const XMLNamespaces* SBase::getNamespaces() const { if (mSBML != NULL) @@ -597,10 +596,6 @@ SBase::setMetaId (const std::string& metaid) mMetaId.erase(); return LIBSBML_OPERATION_SUCCESS; } - else if (!(SyntaxChecker::isValidXMLID(metaid))) - { - return LIBSBML_INVALID_ATTRIBUTE_VALUE; - } else { mMetaId = metaid; @@ -619,10 +614,6 @@ SBase::setId (const std::string& sid) mId.erase(); return LIBSBML_OPERATION_SUCCESS; } - else if (!(SyntaxChecker::isValidXMLID(sid))) - { - return LIBSBML_INVALID_ATTRIBUTE_VALUE; - } else { mId = sid; @@ -635,7 +626,7 @@ SBase::setId (const std::string& sid) * Sets the annotation of this SBML_Lang object to a copy of annotation. */ int -SBase::set (XMLNode* annotation) +SBase::set (XMLNode* annotation) { if (annotation == NULL) { @@ -668,17 +659,17 @@ SBase::set (const std::string& annotation) return LIBSBML_OPERATION_SUCCESS; } - XMLNode* annt_xmln; + XMLNode* annt_xmln; // you might not have a document !! if (getSBMLDocument() != NULL) { - XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); - annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); + XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); + annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); } else { - annt_xmln = XMLNode::convertStringToXMLNode(annotation); + annt_xmln = XMLNode::convertStringToXMLNode(annotation); } if(annt_xmln != NULL) @@ -696,7 +687,7 @@ SBase::set (const std::string& annotation) * adding additional information. */ int -SBase::append (const XMLNode* annotation) +SBase::append (const XMLNode* annotation) { int success = LIBSBML_OPERATION_FAILED; unsigned int duplicates = 0; @@ -704,14 +695,14 @@ SBase::append (const XMLNode* annotation) if(annotation == NULL) return LIBSBML_OPERATION_SUCCESS; - XMLNode* new_annotation = NULL; + XMLNode* new_annotation = NULL; const string& name = annotation->getName(); // check for annotation tags and add if necessary if (name != ) { - XMLToken ann_t = XMLToken(XMLTriple(, "", ""), XMLAttributes()); - new_annotation = new XMLNode(ann_t); + XMLToken ann_t = XMLToken(XMLTriple(, "", ""), XMLAttributes()); + new_annotation = new XMLNode(ann_t); new_annotation->addChild(*annotation); } else @@ -760,7 +751,7 @@ SBase::append (const XMLNode* annotation) } else { - XMLNode *copy = m->clone(); + XMLNode *copy = m->clone(); success = set(copy); delete copy; } @@ -786,15 +777,15 @@ int SBase::append (const std::string& annotation) { int success = LIBSBML_OPERATION_FAILED; - XMLNode* annt_xmln; + XMLNode* annt_xmln; if (getSBMLDocument() != NULL) { - XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); - annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); + XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); + annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); } else { - annt_xmln = XMLNode::convertStringToXMLNode(annotation); + annt_xmln = XMLNode::convertStringToXMLNode(annotation); } if(annt_xmln != NULL) @@ -831,7 +822,7 @@ SBase::removeTopLevelElement(const std::string elementName, // check uri matches if (elementURI.empty() == false) { - XMLNode child = m->getChild(index); + XMLNode child = m->getChild(index); std::string prefix = child.getPrefix(); if (prefix.empty() == false @@ -883,10 +874,10 @@ SBase::removeTopLevelElement(const std::string elementName, int -SBase::replaceTopLevelElement(const XMLNode* annotation) +SBase::replaceTopLevelElement(const XMLNode* annotation) { int success = LIBSBML_OPERATION_FAILED; - XMLNode * replacement = NULL; + XMLNode * replacement = NULL; if (annotation->getName() == ) { if (annotation->getNumChildren() != 1) @@ -920,15 +911,15 @@ int SBase::replaceTopLevelElement(const std::string& annotation) { int success = LIBSBML_OPERATION_FAILED; - XMLNode* annt_xmln; + XMLNode* annt_xmln; if (getSBMLDocument() != NULL) { - XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); - annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); + XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); + annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns); } else { - annt_xmln = XMLNode::convertStringToXMLNode(annotation); + annt_xmln = XMLNode::convertStringToXMLNode(annotation); } if(annt_xmln != NULL) @@ -946,7 +937,7 @@ SBase::replaceTopLevelElement(const std::string& annotation) * Sets the notes of this SBML_Lang object to a copy of notes. */ int -SBase::set(const XMLNode* notes) +SBase::set(const XMLNode* notes) { if (m == notes) { @@ -966,13 +957,13 @@ SBase::set(const XMLNode* notes) if (name == "notes") { - m = static_cast<XMLNode*>( notes->clone() ); + m = static_cast( notes->clone() ); } else { - XMLToken notes_t = XMLToken(XMLTriple("notes", "", ""), - XMLAttributes()); - m = new XMLNode(notes_t); + XMLToken notes_t = XMLToken(XMLTriple("notes", "", ""), + XMLAttributes()); + m = new XMLNode(notes_t); // The root node of the given XMLNode tree can be an empty XMLNode // (i.e. neither start, end, nor text XMLNode) if the given notes was @@ -996,13 +987,6 @@ SBase::set(const XMLNode* notes) } } - if (!SyntaxChecker::hasExpectedXHTMLSyntax(m, NULL)) - { - delete m; - m = NULL; - return LIBSBML_INVALID_OBJECT; - } - return LIBSBML_OPERATION_SUCCESS; } @@ -1021,17 +1005,17 @@ SBase::set(const std::string& notes, bool addXHTMLMarkup) } else { - XMLNode* notes_xmln; + XMLNode* notes_xmln; // you might not have a document !! if (getSBMLDocument() != NULL) { - XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); - notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); + XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); + notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); } else { - notes_xmln = XMLNode::convertStringToXMLNode(notes); + notes_xmln = XMLNode::convertStringToXMLNode(notes); } if (notes_xmln != NULL) @@ -1044,11 +1028,11 @@ SBase::set(const std::string& notes, bool addXHTMLMarkup) && notes_xmln->isText() == true) { //create a parent node of xhtml type p - XMLAttributes blank_att = XMLAttributes(); - XMLTriple triple = XMLTriple("p", "http://www.w3.org/1999/xhtml", ""); - XMLNamespaces xmlns = XMLNamespaces(); + XMLAttributes blank_att = XMLAttributes(); + XMLTriple triple = XMLTriple("p", "http://www.w3.org/1999/xhtml", ""); + XMLNamespaces xmlns = XMLNamespaces(); xmlns.add("http://www.w3.org/1999/xhtml", ""); - XMLNode *xmlnode = new XMLNode(XMLToken(triple, blank_att, xmlns)); + XMLNode *xmlnode = new XMLNode(XMLToken(triple, blank_att, xmlns)); // create a text node from the text given xmlnode->addChild(*notes_xmln); @@ -1078,7 +1062,7 @@ SBase::set(const std::string& notes, bool addXHTMLMarkup) * adding additional information. */ int -SBase::append(const XMLNode* notes) +SBase::append(const XMLNode* notes) { int success = LIBSBML_OPERATION_FAILED; if(notes == NULL) @@ -1107,7 +1091,7 @@ SBase::append(const XMLNode* notes) typedef enum { _AHTML, _ABody, _AAny } _Type; _Type addedType = _AAny; - XMLNode added; + XMLNode added; //------------------------------------------------------------ // @@ -1218,7 +1202,7 @@ SBase::append(const XMLNode* notes) if (getLevel() > 2 || (getLevel() == 2 && getVersion() > 1)) { - XMLNode tmp(XMLTriple("notes","",""), XMLAttributes()); + XMLNode tmp(XMLTriple("notes","",""), XMLAttributes()); if (addedType == _AAny) { @@ -1232,14 +1216,6 @@ SBase::append(const XMLNode* notes) tmp.addChild(added); } - if (!SyntaxChecker::hasExpectedXHTMLSyntax(&tmp, NULL)) - { - return LIBSBML_INVALID_OBJECT; - } - } - - - if ( m != NULL ) { //------------------------------------------------------------ // @@ -1248,7 +1224,7 @@ SBase::append(const XMLNode* notes) //------------------------------------------------------------ _Type curType = _AAny; - XMLNode& cur = *m; + XMLNode& cur = *m; // cur.getChild(0) must be "html", "body", or any XHTML // element that would be permitted within a "body" element . @@ -1257,7 +1233,7 @@ SBase::append(const XMLNode* notes) if (cname == "html") { - XMLNode& curHTML = cur.getChild(0); + XMLNode& curHTML = cur.getChild(0); // // checks the curHTML if the html tag contains "head" and "body" tags // which must be located in this order, otherwise nothing will be done. @@ -1297,14 +1273,14 @@ SBase::append(const XMLNode* notes) if (curType == _AHTML) { - XMLNode& curHTML = cur.getChild(0); - XMLNode& curBody = curHTML.getChild(1); + XMLNode& curHTML = cur.getChild(0); + XMLNode& curBody = curHTML.getChild(1); if (addedType == _AHTML) { // adds the given html tag to the current html tag - XMLNode& addedBody = added.getChild(1); + XMLNode& addedBody = added.getChild(1); for (i=0; i < addedBody.getNumChildren(); i++) { @@ -1332,9 +1308,9 @@ SBase::append(const XMLNode* notes) { // adds the given html tag to the current body tag - XMLNode addedHTML(added); - XMLNode& addedBody = addedHTML.getChild(1); - XMLNode& curBody = cur.getChild(0); + XMLNode addedHTML(added); + XMLNode& addedBody = addedHTML.getChild(1); + XMLNode& curBody = cur.getChild(0); for (i=0; i < curBody.getNumChildren(); i++) { @@ -1350,7 +1326,7 @@ SBase::append(const XMLNode* notes) // adds the given body or other tag (permitted in the body) to the current // body tag - XMLNode& curBody = cur.getChild(0); + XMLNode& curBody = cur.getChild(0); for (i=0; i < added.getNumChildren(); i++) { @@ -1366,8 +1342,8 @@ SBase::append(const XMLNode* notes) { // adds the given html tag to the current any tag permitted in the body. - XMLNode addedHTML(added); - XMLNode& addedBody = addedHTML.getChild(1); + XMLNode addedHTML(added); + XMLNode& addedBody = addedHTML.getChild(1); for (i=0; i < cur.getNumChildren(); i++) { @@ -1382,7 +1358,7 @@ SBase::append(const XMLNode* notes) { // adds the given body tag to the current any tag permitted in the body. - XMLNode addedBody(added); + XMLNode addedBody(added); for (i=0; i < cur.getNumChildren(); i++) { @@ -1430,16 +1406,16 @@ SBase::append(const std::string& notes) return LIBSBML_OPERATION_SUCCESS; } - XMLNode* notes_xmln; + XMLNode* notes_xmln; // you might not have a document !! if (getSBMLDocument() != NULL) { - XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); - notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); + XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces(); + notes_xmln = XMLNode::convertStringToXMLNode(notes,xmlns); } else { - notes_xmln = XMLNode::convertStringToXMLNode(notes); + notes_xmln = XMLNode::convertStringToXMLNode(notes); } if(notes_xmln != NULL) @@ -1563,7 +1539,7 @@ SBase::getAncestorOfType(int type) const * @param xmlns the namespaces to set */ int -SBase::setNamespaces(XMLNamespaces* xmlns) +SBase::setNamespaces(XMLNamespaces* xmlns) { if (xmlns == NULL) { @@ -1635,7 +1611,7 @@ SBase::unset () int SBase::unset () { - XMLNode* empty = NULL; + XMLNode* empty = NULL; return set(empty); } @@ -1701,7 +1677,7 @@ bool SBase::hasValidLevelVersionNamespaceCombination() { int typecode = getTypeCode(); - XMLNamespaces *xmlns = getNamespaces(); + XMLNamespaces *xmlns = getNamespaces(); return hasValidLevelVersionNamespaceCombination(typecode, xmlns); } @@ -1799,7 +1775,7 @@ SBase::matchesCoreSBMLNamespace(const SBase * sb) const bool -SBase::hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns) +SBase::hasValidLevelVersionNamespaceCombination(int typecode, XMLNamespaces *xmlns) { @@ -1893,11 +1869,11 @@ char* SBase::toSBML () { ostringstream os; - XMLOutputStream stream(os, "UTF-8", false); + XMLOutputStream stream(os, "UTF-8", false); write(stream); - return safe_strdup( os.str().c_str() ); + return sbml_safe_strdup( os.str().c_str() ); } @@ -2097,11 +2073,11 @@ SBase::getObject(const std::string& objectName, unsigned int index) * Reads (initializes) this SBML_Lang object by reading from XMLInputStream. */ void -SBase::read (XMLInputStream& stream) +SBase::read (XMLInputStream& stream) { if ( !stream.peek().isStart() ) return; - const XMLToken element = stream.next(); + const XMLToken element = stream.next(); int position = 0; setSBaseFields( element ); @@ -2121,7 +2097,7 @@ SBase::read (XMLInputStream& stream) // need to check that any prefix on the sbmlns also occurs on element // remembering the horrible situation where the sbmlns might be declared // with more than one prefix - XMLNamespaces * xmlns = this->getSBMLNamespaces()->getNamespaces(); + XMLNamespaces * xmlns = this->getSBMLNamespaces()->getNamespaces(); if (xmlns != NULL) { int i = xmlns->getIndexByPrefix(element.getPrefix()); @@ -2178,7 +2154,7 @@ SBase::read (XMLInputStream& stream) checkDefaultNamespace(mSBMLNamespaces->getNamespaces(), element.getName()); if (!element.getPrefix().empty()) { - XMLNamespaces * prefixedNS = new XMLNamespaces(); + XMLNamespaces * prefixedNS = new XMLNamespaces(); prefixedNS->add(element.getURI(), element.getPrefix()); checkDefaultNamespace(prefixedNS, element.getName(), element.getPrefix()); delete prefixedNS; @@ -2199,7 +2175,7 @@ SBase::read (XMLInputStream& stream) } setElementText(text); - const XMLToken& next = stream.peek(); + const XMLToken& next = stream.peek(); // Re-check stream.isGood() because stream.peek() could hit something. if ( !stream.isGood() ) break; @@ -2254,7 +2230,7 @@ SBase::setElementText(const std::string &text) * Writes (serializes) this SBML_Lang object by writing it to XMLOutputStream. */ void -SBase::write (XMLOutputStream& stream) const +SBase::write (XMLOutputStream& stream) const { stream.startElement( getElementName(), getPrefix() ); @@ -2275,7 +2251,7 @@ SBase::write (XMLOutputStream& stream) const * implementation of this method as well. */ void -SBase::writeElements (XMLOutputStream& stream) const +SBase::writeElements (XMLOutputStream& stream) const { if ( m != NULL ) stream << *m; @@ -2293,7 +2269,7 @@ SBase::writeElements (XMLOutputStream& stream) const * XMLInputStream or @c NULL if the token was not recognized. */ SBase* -SBase::createObject (XMLInputStream& stream) +SBase::createObject (XMLInputStream& stream) { return NULL; } @@ -2310,7 +2286,7 @@ SBase::createObject (XMLInputStream& stream) * @return true if the subclass read from the stream, false otherwise. */ bool -SBase::readOtherXML (XMLInputStream& stream) +SBase::readOtherXML (XMLInputStream& stream) { bool read = false; return read; @@ -2323,7 +2299,7 @@ SBase::readOtherXML (XMLInputStream& stream) * @return true if read an element from the stream */ bool -SBase::read (XMLInputStream& stream) +SBase::read (XMLInputStream& stream) { const string& name = stream.peek().getName(); @@ -2340,7 +2316,7 @@ SBase::read (XMLInputStream& stream) } delete m; - m = new XMLNode(stream); + m = new XMLNode(stream); check(); return true; } @@ -2355,7 +2331,7 @@ SBase::read (XMLInputStream& stream) * @return true if read a element from the stream */ bool -SBase::read (XMLInputStream& stream) +SBase::read (XMLInputStream& stream) { const string& name = stream.peek().getName(); @@ -2371,13 +2347,13 @@ SBase::read (XMLInputStream& stream) } delete m; - m = new XMLNode(stream); + m = new XMLNode(stream); // // checks if the given default namespace (if any) is a valid // SBML_Lang namespace // - const XMLNamespaces &xmlns = m->getNamespaces(); + const XMLNamespaces &xmlns = m->getNamespaces(); checkDefaultNamespace(&xmlns,"notes"); return true; @@ -2546,10 +2522,10 @@ SBase::addExpectedAttributes(ExpectedAttributes& attributes) * parents implementation of this method as well. */ void -SBase::readAttributes (const XMLAttributes& attributes, - const ExpectedAttributes& expectedAttributes) +SBase::readAttributes (const XMLAttributes& attributes, + const ExpectedAttributes& expectedAttributes) { - const_cast<XMLAttributes&>(attributes).setErrorLog(getErrorLog()); + const_cast(attributes).setErrorLog(getErrorLog()); const unsigned int level = getLevel (); const unsigned int version = getVersion(); @@ -2601,15 +2577,6 @@ SBase::readAttributes (const XMLAttributes& attributes, logEmptyString("metaid", level, version, SBMLTypeCode_toString(getTypeCode())); } - - if (isSetMetaId()) - { - if (!SyntaxChecker::isValidXMLID(mMetaId)) - { - logError(SBMLInvalidMetaidSyntax, getLevel(), getVersion(), "The metaid '" + mMetaId + "' does not conform to the syntax."); - } - } - } @@ -2622,7 +2589,7 @@ SBase::getPrefix() const { std::string prefix = ""; - const XMLNamespaces *xmlns = getNamespaces(); + const XMLNamespaces *xmlns = getNamespaces(); string uri = getURI(); if(xmlns && mSBML) { @@ -2641,7 +2608,7 @@ SBase::getSBMLPrefix() const { std::string prefix = ""; - const XMLNamespaces *xmlns = getNamespaces(); + const XMLNamespaces *xmlns = getNamespaces(); if (xmlns == NULL) return getPrefix(); @@ -2686,7 +2653,7 @@ SBase::getRootElement() * of this method as well. */ void -SBase::writeAttributes (XMLOutputStream& stream) const +SBase::writeAttributes (XMLOutputStream& stream) const { string sbmlPrefix = getSBMLPrefix(); if ( !mMetaId.empty() ) @@ -2705,7 +2672,7 @@ SBase::writeAttributes (XMLOutputStream& stream) const * */ void -SBase::writeXMLNS (XMLOutputStream& stream) const +SBase::writeXMLNS (XMLOutputStream& stream) const { // do nothing. } @@ -2763,7 +2730,7 @@ int SBase::removeFromParentAndDelete() /** @cond doxygenLibsbmlInternal */ const std::string -SBase::checkMathMLNamespace(const XMLToken elem) +SBase::checkMathMLNamespace(const XMLToken elem) { std::string prefix = ""; unsigned int match = 0; @@ -2809,7 +2776,7 @@ SBase::checkMathMLNamespace(const XMLToken elem) /** @cond doxygenLibsbmlInternal */ void -SBase::checkDefaultNamespace(const XMLNamespaces* xmlns, +SBase::checkDefaultNamespace(const XMLNamespaces* xmlns, const std::string& elementName, const std::string& prefix) { @@ -2859,12 +2826,12 @@ SBase::check() // checks if the given default namespace (if any) is a valid // SBML_Lang namespace // - const XMLNamespaces &xmlns = m->getNamespaces(); + const XMLNamespaces &xmlns = m->getNamespaces(); checkDefaultNamespace(&xmlns,); while (nNodes < m->getNumChildren()) { - XMLNode topLevel = m->getChild(nNodes); + XMLNode topLevel = m->getChild(nNodes); // the top level must be an element (so it should be a start) if (topLevel.isStart() == false) @@ -2960,7 +2927,7 @@ SBase::check() * an sbml document, an error is logged. */ void -SBase::checkXHTML(const XMLNode * xhtml) +SBase::checkXHTML(const XMLNode * xhtml) { if (xhtml == NULL) return; @@ -2998,61 +2965,6 @@ SBase::checkXHTML(const XMLNode * xhtml) logError(errorDOC); } } - - XMLNamespaces* toplevelNS = (mSBML) ? mSBML->getNamespaces() : NULL; - - /* - * namespace declaration is variable - * if a whole html tag has been used - * or a whole body tag then namespace can be implicitly declared - */ - unsigned int children = xhtml->getNumChildren(); - - if (children > 1) - { - for (i=0; i < children; i++) - { - if (SyntaxChecker::isAllowedElement(xhtml->getChild(i))) - { - if (!SyntaxChecker::hasDeclaredNS(xhtml->getChild(i), - toplevelNS)) - { - logError(errorNS); - } - } - else - { - logError(errorELEM); - } - } - } - else - { - /* only one element which can be html or body with either implicit/explicit - * namespace declaration - * OR could be one of the listed elements. - */ - - const string& top_name = xhtml->getChild(0).getName(); - - if (top_name != "html" && top_name != "body" - && !SyntaxChecker::isAllowedElement(xhtml->getChild(0))) - { - logError(errorELEM); - } - else - { - if (!SyntaxChecker::hasDeclaredNS(xhtml->getChild(0), toplevelNS)) - { - logError(errorNS); - } - if (top_name == "html" - && !SyntaxChecker::isCorrectHTMLNode(xhtml->getChild(0))) - { - logError(errorELEM); - } - } - } } /** @endcond */ /** @cond doxygenLibsbmlInternal */ @@ -3107,14 +3019,14 @@ SBase::checkCompatibility(const SBase * object) const * roundtripping) declared on this SBML_Lang (XML) element. */ void -SBase::setSBaseFields (const XMLToken& element) +SBase::setSBaseFields (const XMLToken& element) { mLine = element.getLine (); mColumn = element.getColumn(); if (element.getNamespaces().getLength() > 0) { - XMLNamespaces tmpxmlns(element.getNamespaces()); + XMLNamespaces tmpxmlns(element.getNamespaces()); setNamespaces(&tmpxmlns); } else @@ -3217,7 +3129,7 @@ char* SBase_getString (SBase_t *sb) { return (sb != NULL && sb->isSet()) ? - safe_strdup(sb->getString().c_str()) : NULL; + sbml_safe_strdup(sb->getString().c_str()) : NULL; } @@ -3234,7 +3146,7 @@ char* SBase_getString (SBase_t *sb) { return (sb != NULL && sb->isSet()) ? - safe_strdup(sb->getString().c_str()) : NULL; + sbml_safe_strdup(sb->getString().c_str()) : NULL; } From 748b679500312f2668827df31a597eaa6dc7658f Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 25 May 2023 11:25:45 +0100 Subject: [PATCH 06/37] add bit taken out by mistake --- deviser/code_files/templates/SBase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deviser/code_files/templates/SBase.cpp b/deviser/code_files/templates/SBase.cpp index 1a8fdc40..6b2c7da4 100644 --- a/deviser/code_files/templates/SBase.cpp +++ b/deviser/code_files/templates/SBase.cpp @@ -1215,7 +1215,9 @@ SBase::append(const XMLNode* notes) { tmp.addChild(added); } + } + if (m != NULL) { //------------------------------------------------------------ // From d7f1d7ca5b35d09ddf758c53d723f49e80164bd6 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 25 May 2023 11:26:16 +0100 Subject: [PATCH 07/37] whitespace changes --- .../test_other_library/test-code/tsb/TSBBase.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp b/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp index ad24ae59..479ade35 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBBase.cpp @@ -1251,10 +1251,9 @@ TSBBase::appendNotes(const XMLNode* notes) { tmpNotes.addChild(addedNotes); } - } - + } - if ( mNotes != NULL ) + if (mNotes != NULL) { //------------------------------------------------------------ // @@ -2999,7 +2998,6 @@ TSBBase::checkXHTML(const XMLNode * xhtml) logError(errorDOC); } } - } /** @endcond */ /** @cond doxygenLibtsbInternal */ From 81544ebd0170d829d5c41ee7cf8f42f3d804d416 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 25 May 2023 13:39:15 +0100 Subject: [PATCH 08/37] update template --- deviser/code_files/templates/ConstructorException.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deviser/code_files/templates/ConstructorException.h b/deviser/code_files/templates/ConstructorException.h index 9ef7cbc5..9aa1fd98 100644 --- a/deviser/code_files/templates/ConstructorException.h +++ b/deviser/code_files/templates/ConstructorException.h @@ -1,7 +1,7 @@ #ifndef SBML_CONSTRUCTOR_EXCEPTION_H #define SBML_CONSTRUCTOR_EXCEPTION_H -#include +#include #include #ifdef __cplusplus From 068827a66ba4c54a40fa3a53e949e9d8655b71ca Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 25 May 2023 13:45:24 +0100 Subject: [PATCH 09/37] update templates --- deviser/code_files/templates/Reader.cpp | 6 +++--- deviser/code_files/templates/Reader.h | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/deviser/code_files/templates/Reader.cpp b/deviser/code_files/templates/Reader.cpp index 7cda7626..49880028 100644 --- a/deviser/code_files/templates/Reader.cpp +++ b/deviser/code_files/templates/Reader.cpp @@ -180,7 +180,7 @@ SBMLReader::readInternal (const char* content, bool isFile) { SBMLDocument* d = new SBMLDocument(); - if (isFile && content != NULL && (util_file_exists(content) == false)) + if (isFile && content != NULL && (sbml_util_file_exists(content) == false)) { d->getErrorLog()->logError(XMLFileUnreadable); } @@ -232,7 +232,7 @@ SBMLReader::readInternal (const char* content, bool isFile) { d->getErrorLog()->logError(MissingXMLEncoding); } - else if (strcmp_insensitive(stream.getEncoding().c_str(), "UTF-8") != 0) + else if (sbml_strcmp_insensitive(stream.getEncoding().c_str(), "UTF-8") != 0) { d->getErrorLog()->logError(SBMLNotUTF8); } @@ -241,7 +241,7 @@ SBMLReader::readInternal (const char* content, bool isFile) { d->getErrorLog()->logError(BadXMLDecl); } - else if (strcmp_insensitive(stream.getVersion().c_str(), "1.0") != 0) + else if (sbml_strcmp_insensitive(stream.getVersion().c_str(), "1.0") != 0) { d->getErrorLog()->logError(BadXMLDecl); } diff --git a/deviser/code_files/templates/Reader.h b/deviser/code_files/templates/Reader.h index 9c1ca262..dab882c2 100644 --- a/deviser/code_files/templates/Reader.h +++ b/deviser/code_files/templates/Reader.h @@ -2,11 +2,8 @@ #define SBMLReader_h -#include -#include - -#include - +#include +#include #ifdef __cplusplus From 41b13eb26e89c341d899bf79047bd01dd0805751 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 25 May 2023 13:58:23 +0100 Subject: [PATCH 10/37] whitespace change --- .../test_other_library/test-code/tsb/TSBNamespaces.h | 1 + 1 file changed, 1 insertion(+) diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBNamespaces.h b/deviser/pytest_files/test_other_library/test-code/tsb/TSBNamespaces.h index 76e0520e..e4b5c6cd 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/TSBNamespaces.h +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBNamespaces.h @@ -45,6 +45,7 @@ #include #include + #include #include From b78efef086500a7393fa286f38c107261481c963 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 25 May 2023 14:16:58 +0100 Subject: [PATCH 11/37] Update templates --- deviser/code_files/templates/Error.h | 2 +- deviser/code_files/templates/ErrorLog.h | 4 ++-- deviser/code_files/templates/Namespaces.cpp | 4 ++-- deviser/code_files/templates/Namespaces.h | 9 ++++----- deviser/code_files/templates/Writer.cpp | 4 ++-- deviser/code_files/templates/Writer.h | 4 ++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/deviser/code_files/templates/Error.h b/deviser/code_files/templates/Error.h index bc429fde..0acdb23a 100644 --- a/deviser/code_files/templates/Error.h +++ b/deviser/code_files/templates/Error.h @@ -1,7 +1,7 @@ #ifndef SBMLError_h #define SBMLError_h -#include +#include #include diff --git a/deviser/code_files/templates/ErrorLog.h b/deviser/code_files/templates/ErrorLog.h index 1b736c51..78c481fc 100644 --- a/deviser/code_files/templates/ErrorLog.h +++ b/deviser/code_files/templates/ErrorLog.h @@ -4,8 +4,8 @@ #include -#include -#include +#include +#include #include diff --git a/deviser/code_files/templates/Namespaces.cpp b/deviser/code_files/templates/Namespaces.cpp index e0abe1dd..33560e13 100644 --- a/deviser/code_files/templates/Namespaces.cpp +++ b/deviser/code_files/templates/Namespaces.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include /** @cond doxygenIgnored */ @@ -400,7 +400,7 @@ LIBSBML_EXTERN char * SBMLNamespaces_getSBMLNamespaceURI(unsigned int level, unsigned int version) { - return safe_strdup(SBMLNamespaces::getSBMLNamespaceURI(level, version).c_str()); + return sbml_safe_strdup(SBMLNamespaces::getSBMLNamespaceURI(level, version).c_str()); } diff --git a/deviser/code_files/templates/Namespaces.h b/deviser/code_files/templates/Namespaces.h index 5ecf2c42..864ae254 100644 --- a/deviser/code_files/templates/Namespaces.h +++ b/deviser/code_files/templates/Namespaces.h @@ -1,13 +1,12 @@ #ifndef SBMLNamespaces_h #define SBMLNamespaces_h - #include -#include - +#include -#include -#include + +#include +#include #ifdef __cplusplus namespace LIBSBML_CPP_NAMESPACE diff --git a/deviser/code_files/templates/Writer.cpp b/deviser/code_files/templates/Writer.cpp index daaadf4e..f4de1497 100644 --- a/deviser/code_files/templates/Writer.cpp +++ b/deviser/code_files/templates/Writer.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include @@ -237,7 +237,7 @@ SBMLWriter::writeToString (const SBMLDocument* d) ostringstream stream; writeSBML(d, stream); - return safe_strdup( stream.str().c_str() ); + return sbml_safe_strdup( stream.str().c_str() ); } std::string diff --git a/deviser/code_files/templates/Writer.h b/deviser/code_files/templates/Writer.h index dbdeea2d..4095513c 100644 --- a/deviser/code_files/templates/Writer.h +++ b/deviser/code_files/templates/Writer.h @@ -2,8 +2,8 @@ #define SBMLWriter_h -#include -#include +#include +#include #ifdef __cplusplus From 06a59d6f72eb466a5cf1190e6048332b528b12af Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 25 May 2023 14:17:36 +0100 Subject: [PATCH 12/37] Just testing templates --- .../test_other_library/test_other_library.py | 123 ++++++++++-------- 1 file changed, 67 insertions(+), 56 deletions(-) diff --git a/deviser/pytest_files/test_other_library/test_other_library.py b/deviser/pytest_files/test_other_library/test_other_library.py index 8b12f064..ad87d920 100644 --- a/deviser/pytest_files/test_other_library/test_other_library.py +++ b/deviser/pytest_files/test_other_library/test_other_library.py @@ -29,74 +29,85 @@ def teardown(): shutil.rmtree(temp_dir) -@pytest.mark.parametrize('name, num, class_name, test_case, list_of', [ - ('test_sedml', 1, 'SedModel', 'model', 'SedListOfModels'), - ('test_sedml', 0, 'SedDocument', 'document', ''), - ('test_sedml', 3, 'SedAddXML', 'xmlnode used', ''), - ('test_sedml', 26, 'SedSetValue', 'astnode used', ''), - ('test_sedml', 12, 'SedDataGenerator', 'astnode in getElementBySId bug', ''), - ('test_sedml', 33, 'SedRepeatedTask', 'attribute with different xml name', ''), - ('test_sedml', 7, 'SedSimulation', 'child element', ''), - ('test_sedml', 28, 'SedVectorRange', 'deal with vectors', ''), - ('test_sedml', 10, 'SedAbstractTask', 'catch different abstract types', - 'SedListOfTasks'), - ('test_sedml', 13, 'SedOutput', 'catch different abstract types', - 'SedListOfOutputs'), - ('combine-archive', 0, 'CaContent', 'check includes', 'CaListOfContents'), - ('combine-archive', 1, 'CaOmexManifest', 'document', ''), - ('testsbxml', 1, 'TSBComment', 'comment class', 'TSBListOfComments'), - ('testsbxml', 0, 'TSBDocument', 'document', ''), -]) -def test_cpp(name, num, class_name, test_case, list_of): - """ - Run the C++ file tests. - - :param name: name of test group e.g. 'test_sedml', 'combine-archive'. - :param num: list index, so we only generate a - particular class, not all of them - :param class_name: name of C++ class (and thus .cpp/.h filenames), - e.g. 'CaContent' - :param test_case: brief test description - :param list_of: class name (and thus filenames) of any corresponding - "list of" class, e.g. 'CaListOfContents' - """ - gv.reset() - xml_filename = functions.set_up_test(name, class_name, test_case) - assert xml_filename is not None and xml_filename != "" - test_utils.generate_new_cpp_header(xml_filename, num) - assert 0 == test_utils.compare_code_headers(class_name) - assert 0 == test_utils.compare_code_impl(class_name) - if len(list_of) > 0: - class_name = list_of - assert 0 == test_utils.compare_code_headers(class_name) - assert 0 == test_utils.compare_code_impl(class_name) - - -# @pytest.mark.parametrize('name, class_name, test_case, list_of', [ -# # Tests from old test_utils.testCombine() -# ('test_sedml', 'SedBase', 'templates', 'SedListOf'), -# ('combine-archive', 'CaBase', 'templates', 'CaListOf'), -# # ('testsbxml', 'TSBBase', 'templates', 'TSBListOf'), +# @pytest.mark.parametrize('name, num, class_name, test_case, list_of', [ +# ('test_sedml', 1, 'SedModel', 'model', 'SedListOfModels'), +# ('test_sedml', 0, 'SedDocument', 'document', ''), +# ('test_sedml', 3, 'SedAddXML', 'xmlnode used', ''), +# ('test_sedml', 26, 'SedSetValue', 'astnode used', ''), +# ('test_sedml', 12, 'SedDataGenerator', 'astnode in getElementBySId bug', ''), +# ('test_sedml', 33, 'SedRepeatedTask', 'attribute with different xml name', ''), +# ('test_sedml', 7, 'SedSimulation', 'child element', ''), +# ('test_sedml', 28, 'SedVectorRange', 'deal with vectors', ''), +# ('test_sedml', 10, 'SedAbstractTask', 'catch different abstract types', +# 'SedListOfTasks'), +# ('test_sedml', 13, 'SedOutput', 'catch different abstract types', +# 'SedListOfOutputs'), +# ('combine-archive', 0, 'CaContent', 'check includes', 'CaListOfContents'), +# ('combine-archive', 1, 'CaOmexManifest', 'document', ''), +# ('testsbxml', 1, 'TSBComment', 'comment class', 'TSBListOfComments'), +# ('testsbxml', 0, 'TSBDocument', 'document', ''), # ]) -# def test_templates(name, class_name, test_case, list_of): +# def test_cpp(name, num, class_name, test_case, list_of): # """ -# Based on old test_utils.run_templates() function. Run the 'template' file tests. +# Run the C++ file tests. # # :param name: name of test group e.g. 'test_sedml', 'combine-archive'. +# :param num: list index, so we only generate a +# particular class, not all of them # :param class_name: name of C++ class (and thus .cpp/.h filenames), -# e.g. 'SedBase' -# :param test_case: brief test description, e.g. 'templates'. +# e.g. 'CaContent' +# :param test_case: brief test description # :param list_of: class name (and thus filenames) of any corresponding -# "list of" class, e.g. 'SedListOf' +# "list of" class, e.g. 'CaListOfContents' # """ # gv.reset() # xml_filename = functions.set_up_test(name, class_name, test_case) # assert xml_filename is not None and xml_filename != "" -# test_utils.generate_templates(xml_filename) +# test_utils.generate_new_cpp_header(xml_filename, num) # assert 0 == test_utils.compare_code_headers(class_name) # assert 0 == test_utils.compare_code_impl(class_name) -# assert 0 == test_utils.compare_code_headers(list_of) -# assert 0 == test_utils.compare_code_impl(list_of) +# if len(list_of) > 0: +# class_name = list_of +# assert 0 == test_utils.compare_code_headers(class_name) +# assert 0 == test_utils.compare_code_impl(class_name) +# + +@pytest.mark.parametrize('name, class_name, test_case, list_of', [ +# ('test_sedml', 'SedBase', 'templates', 'SedListOf'), +# ('combine-archive', 'CaBase', 'templates', 'CaListOf'), + ('testsbxml', 'TSBBase', 'templates', 'TSBListOf'), + ('testsbxml', 'TSBConstructorException', 'templates', ''), + ('testsbxml', 'TSBReader', 'templates', ''), + ('testsbxml', 'TSBWriter', 'templates', ''), + ('testsbxml', 'TSBErrorLog', 'templates', ''), + ('testsbxml', 'TSBNamespaces', 'templates', ''), + ('testsbxml', 'TSBError', 'templates', ''), + ('testsbxml', 'TSBVisitor', 'templates', ''), + ('testsbxml', 'TSBTypeCodes', 'templates', ''), + ('testsbxml', 'TSBTypes', 'templates', ''), + ('testsbxml', 'TSBErrorTable', 'templates', '') +]) +def test_templates(name, class_name, test_case, list_of): + """ + Based on old test_utils.run_templates() function. Run the 'template' file tests. + + :param name: name of test group e.g. 'test_sedml', 'combine-archive'. + :param class_name: name of C++ class (and thus .cpp/.h filenames), + e.g. 'SedBase' + :param test_case: brief test description, e.g. 'templates'. + :param list_of: class name (and thus filenames) of any corresponding + "list of" class, e.g. 'SedListOf' + """ + gv.reset() + xml_filename = functions.set_up_test(name, class_name, test_case) + assert xml_filename is not None and xml_filename != "" + test_utils.generate_templates(xml_filename) + assert 0 == test_utils.compare_code_headers(class_name) + if class_name != 'TSBTypes' and class_name != 'TSBErrorTable': + assert 0 == test_utils.compare_code_impl(class_name) + if list_of: + assert 0 == test_utils.compare_code_headers(list_of) + assert 0 == test_utils.compare_code_impl(list_of) # # # @pytest.mark.parametrize('name, class_name, test_case, prefix, lib', [ From 0f8a15128f6786334fa052745f7b8c7bc2fa0969 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 May 2023 12:49:20 +0100 Subject: [PATCH 13/37] take out error table as this needs thought --- deviser/pytest_files/test_other_library/test_other_library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deviser/pytest_files/test_other_library/test_other_library.py b/deviser/pytest_files/test_other_library/test_other_library.py index ad87d920..cebc871d 100644 --- a/deviser/pytest_files/test_other_library/test_other_library.py +++ b/deviser/pytest_files/test_other_library/test_other_library.py @@ -85,7 +85,7 @@ def teardown(): ('testsbxml', 'TSBVisitor', 'templates', ''), ('testsbxml', 'TSBTypeCodes', 'templates', ''), ('testsbxml', 'TSBTypes', 'templates', ''), - ('testsbxml', 'TSBErrorTable', 'templates', '') +# ('testsbxml', 'TSBErrorTable', 'templates', '') ]) def test_templates(name, class_name, test_case, list_of): """ From a7c2cdf1c16a00de30711df4dc0450c576fd01fb Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 May 2023 15:25:28 +0100 Subject: [PATCH 14/37] write macros for TSB --- .../test_tex/test-tex/testsbxml/macros.tex | 20 +++++++++ deviser/pytest_files/test_tex/test_tex.py | 26 +++++++----- deviser/pytest_files/xml_files/testsbxml.xml | 2 +- deviser/spec_files/TexMacrosFile.py | 42 ++++++++++++------- 4 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 deviser/pytest_files/test_tex/test-tex/testsbxml/macros.tex diff --git a/deviser/pytest_files/test_tex/test-tex/testsbxml/macros.tex b/deviser/pytest_files/test_tex/test-tex/testsbxml/macros.tex new file mode 100644 index 00000000..ae847c79 --- /dev/null +++ b/deviser/pytest_files/test_tex/test-tex/testsbxml/macros.tex @@ -0,0 +1,20 @@ + +% \newcommand{\fixttspace}{\hspace*{1pt}} +\newcommand{\const}[1]{\texttt{ #1}} + +\newcommand{\TestTSBXMLLibrary}{\textsf{Test TSB XML Library}\xspace} +\newcommand{\Tsb}{\textsf{Test TSB XML Library}\xspace} + +\newcommand{\TODO}[1]{\colorbox{blue}{\textcolor{white}{TODO: #1}}} + + +% commands for classes +\newcommand{\TSBDocument}{\defRef{TSBDocument}{tsbdocument-class}} +\newcommand{\Comment}{\defRef{Comment}{comment-class}} + +% commands for listOfClasses +\newcommand{\ListOfComments}{\defRef{ListOfComments}{listofcomments-class}} + +% commands for types + +% commands for plugins diff --git a/deviser/pytest_files/test_tex/test_tex.py b/deviser/pytest_files/test_tex/test_tex.py index 8500b343..7ec2b64e 100644 --- a/deviser/pytest_files/test_tex/test_tex.py +++ b/deviser/pytest_files/test_tex/test_tex.py @@ -28,18 +28,22 @@ def teardown(): # @pytest.mark.skipif(sys.version_info < (3,6), # reason="requires python3.6") + + @pytest.mark.parametrize("name, test_type", [ - ('spatial', 'body'), - ('qual', 'apdx-validation'), - ('groups', 'macros'), - ('groups', 'apdx-validation'), - ('groups', 'body'), - ('unknown_type', 'apdx-validation'), - ('test_sidrefs', 'apdx-validation'), - ('test_sidrefs', 'body'), - ('test_lists', 'apdx-validation'), - ('test_lists', 'body'), - ('test_att', 'apdx-validation'), + # ('spatial', 'body'), + # ('qual', 'apdx-validation'), + # ('groups', 'macros'), + # ('groups', 'apdx-validation'), + # ('groups', 'body'), + # ('unknown_type', 'apdx-validation'), + # ('test_sidrefs', 'apdx-validation'), + # ('test_sidrefs', 'body'), + # ('test_lists', 'apdx-validation'), + # ('test_lists', 'body'), + # ('test_att', 'apdx-validation'), + # ('testsbxml', 'apdx-validation'), + ('testsbxml', 'macros'), ]) def test_tex(name, test_type): assert rtt.run_test(name, test_type) == 0 diff --git a/deviser/pytest_files/xml_files/testsbxml.xml b/deviser/pytest_files/xml_files/testsbxml.xml index 1518e444..310b23ba 100644 --- a/deviser/pytest_files/xml_files/testsbxml.xml +++ b/deviser/pytest_files/xml_files/testsbxml.xml @@ -1,5 +1,5 @@ - + diff --git a/deviser/spec_files/TexMacrosFile.py b/deviser/spec_files/TexMacrosFile.py index a6e298e0..d0f3b54f 100644 --- a/deviser/spec_files/TexMacrosFile.py +++ b/deviser/spec_files/TexMacrosFile.py @@ -41,7 +41,7 @@ import re from ..base_files import BaseTexFile -from ..util import strFunctions +from ..util import strFunctions, global_variables class TexMacrosFile(BaseTexFile.BaseTexFile): @@ -81,6 +81,8 @@ def write_macro_for_listof(self, sbml_class): and sbml_class['lo_elementName'] != '': lo_name = strFunctions.upper_first( sbml_class['lo_elementName']) + elif global_variables.language != 'sbml': + lo_name = strFunctions.cap_list_of_name(sbml_class['name'], False) else: lo_name = strFunctions.cap_list_of_name(sbml_class['name']) self.write_text_line('\\newcommand{0}\\{1}{2}{0}\\defRef{0}{1}{2}' @@ -128,25 +130,33 @@ def write_general_commands(self): self.write_text_line('\\newcommand{0}\\const{1}[1]{0}\\texttt{0} #1{1}{1}' .format(self.start_b, self.end_b)) self.skip_line() - self.write_text_line('\\newcommand{0}\\sbmlthreecore{1}{0}SBML Level~{2} ' - 'Version~{3} Core\\xspace{1}'.format(self.start_b, - self.end_b, - self.level, - self.version)) - self.write_text_line('\\newcommand{0}{1}{2}{0}\\textsf{0}{3}' - '{2} package\\xspace{2}'.format(self.start_b, - self.full_pkg_command, - self.end_b, - self.fullname)) + if global_variables.language == 'sbml': + self.write_text_line('\\newcommand{0}\\sbmlthreecore{1}{0}SBML Level~{2} ' + 'Version~{3} Core\\xspace{1}'.format(self.start_b, + self.end_b, + self.level, + self.version)) + self.write_text_line('\\newcommand{0}{1}{2}{0}\\textsf{0}{3}' + '{2} package\\xspace{2}'.format(self.start_b, + self.full_pkg_command, + self.end_b, + self.fullname)) + else: + self.write_text_line('\\newcommand{0}{1}{2}{0}\\textsf{0}{3}' + '{2}\\xspace{2}'.format(self.start_b, + self.full_pkg_command, + self.end_b, + self.fullname)) + self.write_text_line('\\newcommand{0}{1}{2}{0}\\textsf{0}{3}{2}' - '\\xspace{2}' + '\\xspace{2}' .format(self.start_b, - self.brief_pkg_command, - self.end_b, - self.fullname)) + self.brief_pkg_command, + self.end_b, + self.fullname)) self.skip_line() self.write_text_line('\\newcommand{0}\\TODO{1}[1]{0}\\colorbox{0}blue{1}' - '{0}\\textcolor{0}white{1}{0}TODO: #1{1}{1}{1}' + '{0}\\textcolor{0}white{1}{0}TODO: #1{1}{1}{1}' .format(self.start_b, self.end_b)) self.skip_line() From 1813537b368230cf6e9e364b7e48a81d85c986d6 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 May 2023 15:26:06 +0100 Subject: [PATCH 15/37] WRITE MACROS.TEX --- deviser/base_files/BaseTexFile.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/deviser/base_files/BaseTexFile.py b/deviser/base_files/BaseTexFile.py index d0eeae27..e1182310 100644 --- a/deviser/base_files/BaseTexFile.py +++ b/deviser/base_files/BaseTexFile.py @@ -40,7 +40,7 @@ from . import BaseFile -from ..util import strFunctions +from ..util import strFunctions, global_variables class BaseTexFile(BaseFile.BaseFile): @@ -86,7 +86,11 @@ def __init__(self, name, extension, object_desc): self.sort_attribute_names(self.sbml_classes) self.sort_enum_names(self.enums) - self.full_pkg_command = '\\{0}Package'.format(self.fulltexname) + if global_variables.language == 'sbml': + self.full_pkg_command = '\\{0}Package'.format(self.fulltexname) + else: + self.full_pkg_command = '\\{0}'.format(self.fulltexname) + self.brief_pkg_command = '\\{0}'.format(self.upper_package) ######################################################################## From 4a17dd3d43a970d21f2bd36b960228fe39f0654f Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 May 2023 15:47:41 +0100 Subject: [PATCH 16/37] linting --- deviser/spec_files/TexMacrosFile.py | 219 ++++++++++++++++------------ 1 file changed, 128 insertions(+), 91 deletions(-) diff --git a/deviser/spec_files/TexMacrosFile.py b/deviser/spec_files/TexMacrosFile.py index d0f3b54f..554bc69b 100644 --- a/deviser/spec_files/TexMacrosFile.py +++ b/deviser/spec_files/TexMacrosFile.py @@ -41,123 +41,160 @@ import re from ..base_files import BaseTexFile -from ..util import strFunctions, global_variables +from ..util import global_variables, strFunctions class TexMacrosFile(BaseTexFile.BaseTexFile): """Class for the definition of class name macros in LaTeX""" def __init__(self, object_desc): - # derived members for description - self.brief_description = 'Macros definition for specification' - - BaseTexFile.BaseTexFile.__init__(self, 'macros', 'tex', object_desc) - - # self.full_pkg_command = '\\{}Package'.format(self.fulltexname) - # self.brief_pkg_command = '\\{}'.format(self.upper_package) - - self.core_classes = ['Model', 'Compartment', 'Species', 'Parameter', - 'Rule', 'InitialAssignment', 'Reaction', 'Event', - 'Constraint', 'SpeciesReference', - 'EventAssignment', - 'KineticLaw', 'LocalParameter'] + self.brief_description = "Macros definition for specification" + + BaseTexFile.BaseTexFile.__init__(self, "macros", "tex", object_desc) + + self.core_classes = [ + "Model", + "Compartment", + "Species", + "Parameter", + "Rule", + "InitialAssignment", + "Reaction", + "Event", + "Constraint", + "SpeciesReference", + "EventAssignment", + "KineticLaw", + "LocalParameter", + ] ######################################################################## # Write the command for each class def write_macro_for_class(self, sbml_class): - self.write_text_line('\\newcommand{0}\\{1}{2}{0}\\defRef{0}{4}{2}' - '{0}{3}{2}{2}' - .format(self.start_b, sbml_class['texname'], - self.end_b, - strFunctions.make_tex_class(sbml_class['texname']), - sbml_class['name'])) + self.write_text_line( + "\\newcommand{0}\\{1}{2}{0}\\defRef{0}{4}{2}" + "{0}{3}{2}{2}".format( + self.start_b, + sbml_class["texname"], + self.end_b, + strFunctions.make_tex_class(sbml_class["texname"]), + sbml_class["name"], + ) + ) # Write commands for each ListOf class def write_macro_for_listof(self, sbml_class): - if sbml_class['hasListOf']: - if 'lo_elementName' in sbml_class \ - and sbml_class['lo_elementName'] != '': - lo_name = strFunctions.upper_first( - sbml_class['lo_elementName']) - elif global_variables.language != 'sbml': - lo_name = strFunctions.cap_list_of_name(sbml_class['name'], False) + if sbml_class["hasListOf"]: + if "lo_elementName" in sbml_class and sbml_class["lo_elementName"] != "": + lo_name = strFunctions.upper_first(sbml_class["lo_elementName"]) + elif global_variables.language != "sbml": + lo_name = strFunctions.cap_list_of_name(sbml_class["name"], False) else: - lo_name = strFunctions.cap_list_of_name(sbml_class['name']) - self.write_text_line('\\newcommand{0}\\{1}{2}{0}\\defRef{0}{1}{2}' - '{0}{3}{2}{2}' - .format(self.start_b, lo_name, self.end_b, - strFunctions.make_tex_class(lo_name))) + lo_name = strFunctions.cap_list_of_name(sbml_class["name"]) + self.write_text_line( + "\\newcommand{0}\\{1}{2}{0}\\defRef{0}{1}{2}" + "{0}{3}{2}{2}".format( + self.start_b, + lo_name, + self.end_b, + strFunctions.make_tex_class(lo_name), + ) + ) # hack for render - if sbml_class['name'] == 'GradientBase': - self.write_text_line('\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}' - '{0}{3}{2}{2}' - .format(self.start_b, lo_name, self.end_b, - strFunctions.make_tex_class(lo_name), - 'ListOfGradientBases')) - elif sbml_class['name'] == 'RenderPoint': - self.write_text_line('\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}' - '{0}{3}{2}{2}' - .format(self.start_b, lo_name, self.end_b, - strFunctions.make_tex_class(lo_name), - 'ListOfRenderPoints')) + if sbml_class["name"] == "GradientBase": + self.write_text_line( + "\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}" + "{0}{3}{2}{2}".format( + self.start_b, + lo_name, + self.end_b, + strFunctions.make_tex_class(lo_name), + "ListOfGradientBases", + ) + ) + elif sbml_class["name"] == "RenderPoint": + self.write_text_line( + "\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}" + "{0}{3}{2}{2}".format( + self.start_b, + lo_name, + self.end_b, + strFunctions.make_tex_class(lo_name), + "ListOfRenderPoints", + ) + ) # Write commands for each primitive type def write_macro_for_enum(self, enum): # check for underscores - cmd_name = re.sub('_t', 't', enum['name']) - self.write_text_line('\\newcommand{0}\\{1}{2}{0}\\defRef{0}{3}{2}' - '{0}{4}{2}{2}' - .format(self.start_b, cmd_name, - self.end_b, enum['name'], - 'primitive-types')) + cmd_name = re.sub("_t", "t", enum["name"]) + self.write_text_line( + "\\newcommand{0}\\{1}{2}{0}\\defRef{0}{3}{2}" + "{0}{4}{2}{2}".format( + self.start_b, cmd_name, self.end_b, enum["name"], "primitive-types" + ) + ) # Write commands for each plugin def write_macro_for_plugin(self, plugin): - if plugin['sbase'] not in self.core_classes: - self.write_text_line('\\newcommand{0}\\{1}{2}{0}\\defRef{0}{4}{2}' - '{0}{3}{2}{2}' - .format(self.start_b, plugin['sbase'], - self.end_b, - strFunctions.make_tex_class(plugin['sbase']), - plugin['sbase'])) + if plugin["sbase"] not in self.core_classes: + self.write_text_line( + "\\newcommand{0}\\{1}{2}{0}\\defRef{0}{4}{2}" + "{0}{3}{2}{2}".format( + self.start_b, + plugin["sbase"], + self.end_b, + strFunctions.make_tex_class(plugin["sbase"]), + plugin["sbase"], + ) + ) # Write general commands def write_general_commands(self): - self.write_comment_line('\\newcommand{\\fixttspace}{\\hspace*{1pt}}') + self.write_comment_line("\\newcommand{\\fixttspace}{\\hspace*{1pt}}") - self.write_text_line('\\newcommand{0}\\const{1}[1]{0}\\texttt{0} #1{1}{1}' - .format(self.start_b, self.end_b)) + self.write_text_line( + "\\newcommand{0}\\const{1}[1]{0}\\texttt{0} #1{1}{1}".format( + self.start_b, self.end_b + ) + ) self.skip_line() - if global_variables.language == 'sbml': - self.write_text_line('\\newcommand{0}\\sbmlthreecore{1}{0}SBML Level~{2} ' - 'Version~{3} Core\\xspace{1}'.format(self.start_b, - self.end_b, - self.level, - self.version)) - self.write_text_line('\\newcommand{0}{1}{2}{0}\\textsf{0}{3}' - '{2} package\\xspace{2}'.format(self.start_b, - self.full_pkg_command, - self.end_b, - self.fullname)) + if global_variables.language == "sbml": + self.write_text_line( + "\\newcommand{0}\\sbmlthreecore{1}{0}SBML Level~{2} " + "Version~{3} Core\\xspace{1}".format( + self.start_b, self.end_b, self.level, self.version + ) + ) + self.write_text_line( + "\\newcommand{0}{1}{2}{0}\\textsf{0}{3}" + "{2} package\\xspace{2}".format( + self.start_b, self.full_pkg_command, self.end_b, self.fullname + ) + ) else: - self.write_text_line('\\newcommand{0}{1}{2}{0}\\textsf{0}{3}' - '{2}\\xspace{2}'.format(self.start_b, - self.full_pkg_command, - self.end_b, - self.fullname)) - - self.write_text_line('\\newcommand{0}{1}{2}{0}\\textsf{0}{3}{2}' - '\\xspace{2}' - .format(self.start_b, - self.brief_pkg_command, - self.end_b, - self.fullname)) + self.write_text_line( + "\\newcommand{0}{1}{2}{0}\\textsf{0}{3}" + "{2}\\xspace{2}".format( + self.start_b, self.full_pkg_command, self.end_b, self.fullname + ) + ) + + self.write_text_line( + "\\newcommand{0}{1}{2}{0}\\textsf{0}{3}{2}" + "\\xspace{2}".format( + self.start_b, self.brief_pkg_command, self.end_b, self.fullname + ) + ) self.skip_line() - self.write_text_line('\\newcommand{0}\\TODO{1}[1]{0}\\colorbox{0}blue{1}' - '{0}\\textcolor{0}white{1}{0}TODO: #1{1}{1}{1}' - .format(self.start_b, self.end_b)) + self.write_text_line( + "\\newcommand{0}\\TODO{1}[1]{0}\\colorbox{0}blue{1}" + "{0}\\textcolor{0}white{1}{0}TODO: #1{1}{1}{1}".format( + self.start_b, self.end_b + ) + ) self.skip_line() ######################################################################### @@ -167,23 +204,23 @@ def write_file(self): BaseTexFile.BaseTexFile.write_file(self) self.write_general_commands() self.skip_line() - self.write_comment_line('commands for classes') + self.write_comment_line("commands for classes") for i in range(0, len(self.sbml_classes)): # hack for render - if self.sbml_classes[i]['name'] != "RelAbsVector": + if self.sbml_classes[i]["name"] != "RelAbsVector": self.write_macro_for_class(self.sbml_classes[i]) self.skip_line() - self.write_comment_line('commands for listOfClasses') + self.write_comment_line("commands for listOfClasses") for i in range(0, len(self.sbml_classes)): self.write_macro_for_listof(self.sbml_classes[i]) self.skip_line() - self.write_comment_line('commands for types') + self.write_comment_line("commands for types") for i in range(0, len(self.enums)): self.write_macro_for_enum(self.enums[i]) for i in range(0, len(self.prim_class)): self.write_macro_for_enum(self.prim_class[i]) self.skip_line() - self.write_comment_line('commands for plugins') + self.write_comment_line("commands for plugins") for i in range(0, len(self.plugins)): self.write_macro_for_plugin(self.plugins[i]) From db71fe6a38349d3dad2fe6c1092b5b6ef284ad95 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 May 2023 15:51:49 +0100 Subject: [PATCH 17/37] linting --- deviser/base_files/BaseTexFile.py | 90 +++++++++++++------------------ 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/deviser/base_files/BaseTexFile.py b/deviser/base_files/BaseTexFile.py index e1182310..43e7e971 100644 --- a/deviser/base_files/BaseTexFile.py +++ b/deviser/base_files/BaseTexFile.py @@ -39,8 +39,8 @@ # ------------------------------------------------------------------------ --> +from ..util import global_variables, strFunctions from . import BaseFile -from ..util import strFunctions, global_variables class BaseTexFile(BaseFile.BaseFile): @@ -57,27 +57,27 @@ def __init__(self, name, extension, object_desc): BaseFile.BaseFile.__init__(self, name, extension) # change the comment delimiter and line length - self.comment = '%' + self.comment = "%" self.line_length = 72 - self.package = object_desc['name'] - self.fullname = object_desc['fullname'] - self.sbml_classes = object_desc['baseElements'] - self.offset = object_desc['offset'] - self.plugins = object_desc['plugins'] - self.enums = object_desc['enums'] - self.level = object_desc['base_level'] - self.version = object_desc['base_version'] - self.pkg_version = object_desc['pkg_version'] - if object_desc['required']: - self.reqd_status = 'true' + self.package = object_desc["name"] + self.fullname = object_desc["fullname"] + self.sbml_classes = object_desc["baseElements"] + self.offset = object_desc["offset"] + self.plugins = object_desc["plugins"] + self.enums = object_desc["enums"] + self.level = object_desc["base_level"] + self.version = object_desc["base_version"] + self.pkg_version = object_desc["pkg_version"] + if object_desc["required"]: + self.reqd_status = "true" else: - self.reqd_status = 'false' + self.reqd_status = "false" self.prim_class = [] - self.start_b = '{' - self.end_b = '}' + self.start_b = "{" + self.end_b = "}" # expand the information for the classes self.fulltexname = strFunctions.texify(self.fullname) @@ -86,12 +86,12 @@ def __init__(self, name, extension, object_desc): self.sort_attribute_names(self.sbml_classes) self.sort_enum_names(self.enums) - if global_variables.language == 'sbml': - self.full_pkg_command = '\\{0}Package'.format(self.fulltexname) + if global_variables.language == "sbml": + self.full_pkg_command = "\\{0}Package".format(self.fulltexname) else: - self.full_pkg_command = '\\{0}'.format(self.fulltexname) + self.full_pkg_command = "\\{0}".format(self.fulltexname) - self.brief_pkg_command = '\\{0}'.format(self.upper_package) + self.brief_pkg_command = "\\{0}".format(self.upper_package) ######################################################################## @@ -103,14 +103,14 @@ def sort_class_names(self, classes): """ if classes is not None: for i in range(0, len(classes)): - name = classes[i]['name'] + name = classes[i]["name"] texname = strFunctions.texify(name) - classes[i]['texname'] = texname + classes[i]["texname"] = texname # hack for render - if name == 'Ellipse' or name == 'Rectangle': - texname = 'Render' + name - classes[i]['texname'] = texname - if name == 'RelAbsVector': + if name == "Ellipse" or name == "Rectangle": + texname = "Render" + name + classes[i]["texname"] = texname + if name == "RelAbsVector": self.prim_class.append(classes[i]) @staticmethod @@ -122,28 +122,12 @@ def sort_attribute_names(classes): """ if classes is not None: for i in range(0, len(classes)): - attribs = classes[i]['attribs'] + attribs = classes[i]["attribs"] BaseTexFile.update_attrib_dicts(attribs) - # for j in range(0, len(attribs)): - # if attribs[j]['type'] in ['lo_element', 'element', - # 'inline_lo_element']: - # name = attribs[j]['element'] - # else: - # name = attribs[j]['name'] - # texname = strFunctions.texify(name) - # attribs[j]['texname'] = texname for i in range(0, len(classes)): - if 'lo_attribs' in classes[i]: - lo_attribs = classes[i]['lo_attribs'] + if "lo_attribs" in classes[i]: + lo_attribs = classes[i]["lo_attribs"] BaseTexFile.update_attrib_dicts(lo_attribs) - # for j in range(0, len(lo_attribs)): - # if lo_attribs[j]['type'] in ['lo_element', 'element', - # 'inline_lo_element']: - # name = lo_attribs[j]['element'] - # else: - # name = lo_attribs[j]['name'] - # texname = strFunctions.texify(name) - # lo_attribs[j]['texname'] = texname @staticmethod def update_attrib_dicts(my_list): @@ -153,13 +137,12 @@ def update_attrib_dicts(my_list): :param my_list: the list which we update. """ for j in range(0, len(my_list)): - if my_list[j]['type'] in ['lo_element', 'element', - 'inline_lo_element']: - name = my_list[j]['element'] + if my_list[j]["type"] in ["lo_element", "element", "inline_lo_element"]: + name = my_list[j]["element"] else: - name = my_list[j]['name'] + name = my_list[j]["name"] texname = strFunctions.texify(name) - my_list[j]['texname'] = texname + my_list[j]["texname"] = texname @staticmethod def sort_enum_names(enums): @@ -170,9 +153,9 @@ def sort_enum_names(enums): """ if enums is not None: for i in range(0, len(enums)): - name = enums[i]['name'] + name = enums[i]["name"] texname = strFunctions.texify(name) - enums[i]['texname'] = texname + enums[i]["texname"] = texname def write_to_do(self, text): """ @@ -181,8 +164,7 @@ def write_to_do(self, text): :param text: the text describing the TODO. """ - self.write_text_line('\\TODO{0}{1}{2}'.format(self.start_b, text, - self.end_b)) + self.write_text_line("\\TODO{0}{1}{2}".format(self.start_b, text, self.end_b)) self.skip_line() def write_text_line(self, line): From d1cd80ee0f05a0e71a62e293e99840c154aafb3d Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Jun 2023 15:14:25 +0100 Subject: [PATCH 18/37] dont print files when fail comparison --- deviser/pytest_files/functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deviser/pytest_files/functions.py b/deviser/pytest_files/functions.py index 512e2349..bcc4440a 100644 --- a/deviser/pytest_files/functions.py +++ b/deviser/pytest_files/functions.py @@ -102,8 +102,8 @@ def compare_files(infile, outfile, fails, not_tested): else: fails.append(infile) print('{0}=================>> FAILED'.format(outfile)) - print('\n\nEXPECTED:\n{0}'.format(indata.strip())) - print('=================\n\nGOT:\n{0}'.format(out.strip())) +# print('\n\nEXPECTED:\n{0}'.format(indata.strip())) +# print('=================\n\nGOT:\n{0}'.format(out.strip())) print('=================') ret = 1 return ret From 02399666977af4b20e6c29461a1752cb71be9345 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Jun 2023 15:16:41 +0100 Subject: [PATCH 19/37] no offset for other libraries --- deviser/pytest_files/xml_files/testsbxml.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deviser/pytest_files/xml_files/testsbxml.xml b/deviser/pytest_files/xml_files/testsbxml.xml index 310b23ba..224a1b57 100644 --- a/deviser/pytest_files/xml_files/testsbxml.xml +++ b/deviser/pytest_files/xml_files/testsbxml.xml @@ -1,5 +1,5 @@ - + From 0d05cf2cc173afa111699410dda19959e673a363 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Jun 2023 15:19:01 +0100 Subject: [PATCH 20/37] names for other libraries --- deviser/spec_files/TexValidationRulesFile.py | 14 +++++++++++--- deviser/util/global_variables.py | 5 +++++ deviser/validation/ValidationRulesForClass.py | 8 ++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/deviser/spec_files/TexValidationRulesFile.py b/deviser/spec_files/TexValidationRulesFile.py index 632cd3ef..5f311b73 100644 --- a/deviser/spec_files/TexValidationRulesFile.py +++ b/deviser/spec_files/TexValidationRulesFile.py @@ -41,6 +41,7 @@ import re from ..base_files import BaseTexFile +from ..util import global_variables from ..validation import ValidationRulesForClass from ..validation import ValidationRulesForPlugin from ..validation import ValidationRulesGeneral @@ -62,9 +63,16 @@ def __init__(self, object_desc): self.full_pkg_command = '\\{0}Package'.format(self.fulltexname) self.brief_pkg_command = '\\{0}'.format(self.upper_package) - self.pkg_ref = 'SBML Level~{0} Specification for {1}, ' \ - 'Version~{2}'.format(self.level, - self.fullname, self.pkg_version) + if global_variables.is_sbml: + self.pkg_ref = 'SBML Level~{0} Specification for {1}, ' \ + 'Version~{2}'.format(self.level, + self.fullname, self.pkg_version) + else: + self.pkg_ref = '{3} Level~{0} Specification for {1}, ' \ + 'Version~{2}'.format(self.level, + self.fullname, self.version, + global_variables.language) + self.reqd_status = object_desc['required'] ######################################################################## diff --git a/deviser/util/global_variables.py b/deviser/util/global_variables.py index 023f0614..a952fd55 100644 --- a/deviser/util/global_variables.py +++ b/deviser/util/global_variables.py @@ -59,6 +59,8 @@ global language language = 'sbml' +global is_sbml +is_sbml = True global baseClass baseClass = 'SBase' global std_base @@ -192,6 +194,9 @@ def set_globals(lang, base, doc, prfix, lib, is_pack, pkg_prefix, use_name_1=True, ast=False, xml=False, top_name=''): global language language = lang + if language != 'sbml': + global is_sbml + is_sbml = False global namespaces global has_level_version diff --git a/deviser/validation/ValidationRulesForClass.py b/deviser/validation/ValidationRulesForClass.py index e566879c..91ca8c36 100644 --- a/deviser/validation/ValidationRulesForClass.py +++ b/deviser/validation/ValidationRulesForClass.py @@ -59,8 +59,12 @@ def __init__(self, object_desc, spec_name, number, package, pkg_ref): self.start_b = '{' self.end_b = '}' - self.lower_name = strFunctions.lower_first(strFunctions.remove_prefix(self.name)) - self.formatted_name = r'\{0}'.format(strFunctions.remove_prefix(self.name)) + if global_variables.is_sbml: + self.lower_name = strFunctions.lower_first(strFunctions.remove_prefix(self.name)) + self.formatted_name = r'\{0}'.format(strFunctions.remove_prefix(self.name)) + else + self.lower_name = strFunctions.lower_first(self.name) + self.formatted_name = r'\{0}'.format(self.name) self.indef = strFunctions.get_indefinite(self.lower_name) self.indef_u = strFunctions.upper_first(self.indef) From baf4b34b71b5ab022c1b36ce59b3e59603913739 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 15 Jun 2023 11:31:38 +0100 Subject: [PATCH 21/37] almost sorted validation --- deviser/base_files/BaseTexFile.py | 37 ++- .../test-tex/testsbxml/apdx-validation.tex | 190 ++++++++++++++++ deviser/spec_files/TexValidationRulesFile.py | 88 +++++-- deviser/validation/ValidationRulesForClass.py | 108 ++++++--- deviser/validation/ValidationRulesGeneral.py | 214 ++++++++++++++---- 5 files changed, 533 insertions(+), 104 deletions(-) create mode 100644 deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex diff --git a/deviser/base_files/BaseTexFile.py b/deviser/base_files/BaseTexFile.py index 43e7e971..20999604 100644 --- a/deviser/base_files/BaseTexFile.py +++ b/deviser/base_files/BaseTexFile.py @@ -60,20 +60,33 @@ def __init__(self, name, extension, object_desc): self.comment = "%" self.line_length = 72 - self.package = object_desc["name"] - self.fullname = object_desc["fullname"] - self.sbml_classes = object_desc["baseElements"] - self.offset = object_desc["offset"] - self.plugins = object_desc["plugins"] - self.enums = object_desc["enums"] - self.level = object_desc["base_level"] - self.version = object_desc["base_version"] - self.pkg_version = object_desc["pkg_version"] - if object_desc["required"]: - self.reqd_status = "true" + if global_variables.is_sbml: + self.package = object_desc["name"] + self.fullname = object_desc["fullname"] + self.sbml_classes = object_desc["baseElements"] + self.offset = object_desc["offset"] + self.plugins = object_desc["plugins"] + self.enums = object_desc["enums"] + self.level = object_desc["base_level"] + self.version = object_desc["base_version"] + self.pkg_version = object_desc["pkg_version"] + if object_desc["required"]: + self.reqd_status = "true" + else: + self.reqd_status = "false" else: + self.package = '' + self.fullname = global_variables.package_full_name + self.sbml_classes = object_desc["baseElements"] + self.offset = object_desc["offset"] + self.plugins = [] + self.enums = object_desc["enums"] + self.level = object_desc["base_level"] + self.version = object_desc["base_version"] + self.pkg_version = 0 self.reqd_status = "false" + self.prim_class = [] self.start_b = "{" @@ -86,7 +99,7 @@ def __init__(self, name, extension, object_desc): self.sort_attribute_names(self.sbml_classes) self.sort_enum_names(self.enums) - if global_variables.language == "sbml": + if global_variables.is_sbml: self.full_pkg_command = "\\{0}Package".format(self.fulltexname) else: self.full_pkg_command = "\\{0}".format(self.fulltexname) diff --git a/deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex b/deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex new file mode 100644 index 00000000..9c453a76 --- /dev/null +++ b/deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex @@ -0,0 +1,190 @@ +% -*- TeX-master: "main"; fill-column: 72 -*- + +\section{Validation of SBML documents} +\label{apdx-validation} + +\subsection{Validation and consistency rules} +\label{validation-rules} + +This section summarizes all the conditions that must (or in some cases, +at least \emph{should}) be true of an SBML Level~1 Version~1 model that +uses the \TestTSBXMLLibraryPackage. We use the same conventions as are +used in the SBML Level~1 Version~1 Core specification document. In +particular, there are different degrees of rule strictness. Formally, +the differences are expressed in the statement of a rule: either a rule +states that a condition \emph{must} be true, or a rule states that it +\emph{should} be true. Rules of the former kind are strict SBML +validation rules---a model encoded in SBML must conform to all of them +in order to be considered valid. Rules of the latter kind are +consistency rules. To help highlight these differences, we use the +following three symbols next to the rule numbers: + +\begin{description} + +\item[\hspace*{6.5pt}\vSymbol\vsp] A \vSymbolName indicates a +\emph{requirement} for SBML conformance. If a model does not follow this +rule, it does not conform to the \TestTSBXMLLibraryPackage +specification. (Mnemonic intention behind the choice of symbol: ``This +must be checked.'') + +\item[\hspace*{6.5pt}\cSymbol\csp] A \cSymbolName indicates a +\emph{recommendation} for model consistency. If a model does not follow +this rule, it is not considered strictly invalid as far as the +\TestTSBXMLLibraryPackage specification is concerned; however, it +indicates that the model contains a physical or conceptual +inconsistency. (Mnemonic intention behind the choice of symbol: ``This +is a cause for warning.'') + +\item[\hspace*{6.5pt}\mSymbol\msp] A \mSymbolName indicates a strong +recommendation for good modeling practice. This rule is not strictly a +matter of SBML encoding, but the recommendation comes from logical +reasoning. As in the previous case, if a model does not follow this +rule, it is not strictly considered an invalid SBML encoding. (Mnemonic +intention behind the choice of symbol: ``You're a star if you heed +this.'') + +\end{description} + +The validation rules listed in the following subsections are all stated +or implied in the rest of this specification document. They are +enumerated here for convenience. Unless explicitly stated, all +validation rules concern objects and attributes specifically defined in +the \TestTSBXMLLibraryPackage package. + +For \notice convenience and brevity, we use the shorthand +``\token{tsb:\-x}'' to stand for an attribute or element name \token{x} +in the namespace for the \TestTSBXMLLibraryPackage package, using the +namespace prefix \token{tsb}. In reality, the prefix string may be +different from the literal ``\token{tsb}'' used here (and indeed, it can +be any valid XML namespace prefix that the modeler or software chooses). +We use ``\token{tsb:\-x}'' because it is shorter than to write a full +explanation everywhere we refer to an attribute or element in the +\TestTSBXMLLibraryPackage namespace. + +\subsubsection*{General rules about this language.} + +\validRule{tsb-10101}{To conform to the \TestTSBXMLLibrary specification +for TSB Level~1 Version~1, an TSB document must declare +\uri{http://testsbxml.org/l1v1} as the XMLNamespace to use for elements +of this package. (Reference: TSB Level~1 Specification for Test TSB XML +Library, Version~1 \sec{xml-namespace}.)} + +\validRule{tsb-10102}{Wherever they appear in a TSB document, elements +and attributes from the \TestTSBXMLLibrary must use the +\uri{http://testsbxml.org/l1v1} namespace, declaring so either +explicitly or implicitly. (Reference: TSB Level~1 Specification for Test +TSB XML Library, Version~1 \sec{xml-namespace}.)} + +\subsubsection*{General rules about identifiers} + +\validRule{tsb-10201}{The value of a \token{tsb:\-metaid} must conform +to the syntax of the XML Type ID (Reference: )} + + + +\subsubsection*{General rules for \TestAnnotation elements} + +\validRule{tsb-10301}{Every top-level XML element within an +\TestAnnotation object must have an XML namespace declared. (Reference: +TSB Level~1 Specification for Test TSB XML Library, Version~1 +\sec{annotation-use}.)} + +\validRule{tsb-10302}{A given XML namespace cannot be the namespace of +more than one top-levelelement within a given \TestAnnotation object. +(Reference: TSB Level~1 Specification for Test TSB XML Library, +Version~1 \sec{annotation-use}.)} + +\validRule{tsb-10303}{A given TSB element may contain at most one +\TestAnnotation subobject. (Reference: TSB Level~1 Specification for +Test TSB XML Library, Version~1 \sec{annotation-use}.)} + +\subsubsection*{General rules for \notes elements} + +\validRule{tsb-10401}{The contents of a \Notes object must be explicitly +placed in the XHTML XML namespace. (Reference: TSB Level~1 Specification +for Test TSB XML Library, Version~1 \sec{notes}.)} + +\validRule{tsb-10402}{The contents of a \Notes object must not contain +an XML declaration, \ie a string of the form \val{} or similar. (Reference: TSB Level~1 Specification +for Test TSB XML Library, Version~1 \sec{notes}.)} + +\validRule{tsb-10403}{The content of a \Notes object must not contain an +XML DOCTYPE declaration, \ie a string beginning with the characters +\val{ 0: self.number += 1 rule = self.write_optional_lo_rule() @@ -431,9 +438,16 @@ def write_package_attribute_rule(self): return reqd = self.parse_required(self, self.reqd_att) opt = self.parse_optional(self, self.opt_att) - no_other_statement = 'No other attributes from the SBML Level~3 {0} ' \ - 'namespaces are permitted on {1} {2} object. '\ - .format(self.fullname, self.indef, self.formatted_name) + if global_variables.is_sbml: + no_other_statement = 'No other attributes from the SBML Level~3 {0} ' \ + 'namespaces are permitted on {1} {2} object. '\ + .format(self.fullname, self.indef, self.formatted_name) + else: + no_other_statement = 'No other attributes from the {3} Level~{4} Version~{5} ' \ + 'namespaces are permitted on {1} {2} object. ' \ + .format(self.fullname, self.indef, self.formatted_name, global_variables.language.upper(), + global_variables.namespaces[0]['level'], global_variables.namespaces[0]['version']) + if len(opt) == 0 and len(reqd) > 0: text = '{0} {1} object must have {2}. {3}'\ .format(self.indef_u, self.formatted_name, @@ -465,21 +479,43 @@ def write_package_object_rule(self): return reqd = self.parse_required_elements(self.reqd_elem) opt = self.parse_optional_elements(self.opt_elem) - no_other_statement = 'No other elements from the SBML Level~3 {0} ' \ - 'namespaces are permitted on {1} {2} object. '\ - .format(self.fullname, self.indef, self.formatted_name) - if len(opt) == 0 and len(reqd) > 0: - text = '{0} {1} object must contain {2}. {3}'\ - .format(self.indef_u, self.formatted_name, - reqd, no_other_statement) - elif len(reqd) == 0 and len(opt) > 0: - text = '{0} {1} object may contain {2}. {3}'\ - .format(self.indef_u, self.formatted_name, - opt, no_other_statement) + if global_variables.is_sbml: + no_other_statement = 'No other elements from the SBML Level~3 {0} ' \ + 'namespaces are permitted on {1} {2} object. '\ + .format(self.fullname, self.indef, self.formatted_name) + if len(opt) == 0 and len(reqd) > 0: + text = '{0} {1} object must contain {2}. {3}'\ + .format(self.indef_u, self.formatted_name, + reqd, no_other_statement) + elif len(reqd) == 0 and len(opt) > 0: + text = '{0} {1} object may contain {2}. {3}'\ + .format(self.indef_u, self.formatted_name, + opt, no_other_statement) + else: + text = '{0} {1} object must contain {2}, and may contain {3}. {4}'\ + .format(self.indef_u, self.formatted_name, + reqd, opt, no_other_statement) else: - text = '{0} {1} object must contain {2}, and may contain {3}. {4}'\ - .format(self.indef_u, self.formatted_name, - reqd, opt, no_other_statement) + common = 'Apart from the general \\{0} and \\{1} subobjects permitted ' \ + 'on all {2} components,'.format('Notes', global_variables.annot_element, + global_variables.language.upper()) + no_other_statement = 'No other objects from the {3} Level~{4} Version~{5} ' \ + 'namespaces are permitted on {1} {2} object. ' \ + .format(self.fullname, self.indef, self.formatted_name, global_variables.language.upper(), + global_variables.namespaces[0]['level'], global_variables.namespaces[0]['version']) + if len(opt) == 0 and len(reqd) > 0: + text = '{4} {0} {1} object must contain {2}. {3}'\ + .format(self.indef_u, self.formatted_name, + reqd, no_other_statement, common) + elif len(reqd) == 0 and len(opt) > 0: + text = '{4} {0} {1} object may contain {2}. {3}'\ + .format(self.indef_u, self.formatted_name, + opt, no_other_statement, common) + else: + text = '{5} {0} {1} object must contain {2}, and may contain {3}. {4}'\ + .format(self.indef_u, self.formatted_name, + reqd, opt, no_other_statement, common) + ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' @@ -686,6 +722,10 @@ def write_reqd_lo_rule(self): # parse the required attribute sentence @staticmethod def parse_required(self, attributes): + if global_variables.is_sbml: + prefix = self.package + else: + prefix = global_variables.language for attrib in attributes: if 'texname' not in attrib or attrib['texname'] == 'RelAbsVector': attrib['texname'] = attrib['name'] @@ -695,25 +735,31 @@ def parse_required(self, attributes): elif num == 1: return 'the required attribute {0}'\ .format(strFunctions.wrap_token(attributes[0]['texname'], - self.package)) + prefix)) else: required_statement = 'the required attributes {0}'\ .format(strFunctions.wrap_token(attributes[0]['texname'], - self.package)) + prefix)) i = 1 while i < num - 1: required_statement += ', {0}'\ .format(strFunctions.wrap_token(attributes[i]['texname'], - self.package)) + prefix)) i += 1 required_statement += ' and {0}'\ .format(strFunctions.wrap_token(attributes[i]['texname'], - self.package)) + prefix)) return required_statement # parse the optional attribute sentence @staticmethod def parse_optional(self, attributes): + if global_variables.is_sbml: + prefix = self.package + else: + prefix = global_variables.language + metaid = {'name': 'metaid', 'type': 'string'} + attributes.append(metaid) for attrib in attributes: if 'texname' not in attrib or attrib['texname'] == 'RelAbsVector': attrib['texname'] = attrib['name'] @@ -723,20 +769,20 @@ def parse_optional(self, attributes): elif num == 1: return 'the optional attribute {0}' \ .format(strFunctions.wrap_token(attributes[0]['texname'], - self.package)) + prefix)) else: optional_statement = 'the optional attributes {0}' \ .format(strFunctions.wrap_token(attributes[0]['texname'], - self.package)) + prefix)) i = 1 while i < num - 1: optional_statement += ', {0}' \ .format(strFunctions.wrap_token(attributes[i]['texname'], - self.package)) + prefix)) i += 1 optional_statement += ' and {0}' \ .format(strFunctions.wrap_token(attributes[i]['texname'], - self.package)) + prefix)) return optional_statement # parse the required elements sentence diff --git a/deviser/validation/ValidationRulesGeneral.py b/deviser/validation/ValidationRulesGeneral.py index 0fb4f9ea..cfabbbec 100644 --- a/deviser/validation/ValidationRulesGeneral.py +++ b/deviser/validation/ValidationRulesGeneral.py @@ -40,11 +40,11 @@ from ..util import strFunctions, global_variables -class ValidationRulesGeneral(): +class ValidationRulesGeneral: """Class for creating the general validation rules""" def __init__(self, spec_name, number, package, pkg_ref, level, version, - pkg_version, reqd_status): + pkg_version, reqd_status, full_pkg_command): # members from object self.fullname = spec_name self.number = number @@ -57,8 +57,7 @@ def __init__(self, spec_name, number, package, pkg_ref, level, version, else: self.reqd_status = 'false' - self.full_pkg_command = \ - '\\{0}Package'.format(strFunctions.texify(self.fullname)) + self.full_pkg_command = full_pkg_command # useful repeated text strings self.valid = '\\validRule{' self.start_b = '{' @@ -77,53 +76,98 @@ def __init__(self, spec_name, number, package, pkg_ref, level, version, def determine_rules(self): # write rules increasing the number - self.number += 10100 - rule = self.write_unknown_rule(self) - self.add_rule(rule) + if global_variables.is_sbml: + self.number += 10100 + rule = self.write_unknown_rule(self) + self.add_rule(rule) - self.number += 1 - rule = self.write_ns_rule(self) - self.add_rule(rule) + self.number += 1 + rule = self.write_ns_rule(self) + self.add_rule(rule) - self.number += 1 - rule = self.write_element_not_ns_rule(self) - self.add_rule(rule) + self.number += 1 + rule = self.write_element_not_ns_rule(self) + self.add_rule(rule) - self.number = self.offset + 10301 - rule = self.write_id_rule(self) - self.add_rule(rule) + self.number = self.offset + 10301 + rule = self.write_id_rule(self) + self.add_rule(rule) - self.number += 1 - rule = self.write_id_syntax_rule(self) - self.add_rule(rule) + self.number += 1 + rule = self.write_id_syntax_rule(self) + self.add_rule(rule) - if global_variables.is_package: - self.number = self.offset + 20101 - rule = self.write_reqd_rule(self) + if global_variables.is_package: + self.number = self.offset + 20101 + rule = self.write_reqd_rule(self) + self.add_rule(rule) + + self.number += 1 + rule = self.write_reqd_bool_rule(self) + self.add_rule(rule) + + self.number += 1 + rule = self.write_reqd_value_rule(self) + self.add_rule(rule) + else: + self.number += 1 + rule = self.write_metaid_syntax_rule(self) + self.add_rule(rule) + + self.number = self.offset + 20101 + rule = self.write_valid_ns_rule(self) + self.add_rule(rule) + + self.number += 1 + rule = self.write_allowed_attributes_rule(self) + self.add_rule(rule) + + self.number += 1 + rule = self.write_empty_list_rule(self) + self.add_rule(rule) + else: + self.number += 10100 + rule = self.write_unknown_rule(self) self.add_rule(rule) self.number += 1 - rule = self.write_reqd_bool_rule(self) + rule = self.write_ns_rule(self) self.add_rule(rule) self.number += 1 - rule = self.write_reqd_value_rule(self) + rule = self.write_element_not_ns_rule(self) self.add_rule(rule) - else: - self.number += 1 + + self.number = 10201 rule = self.write_metaid_syntax_rule(self) self.add_rule(rule) - self.number = self.offset + 20101 - rule = self.write_valid_ns_rule(self) + self.number = 10301 + rule = self.write_annotation_rule(self, 1) self.add_rule(rule) self.number += 1 - rule = self.write_allowed_attributes_rule(self) + rule = self.write_annotation_rule(self, 2) self.add_rule(rule) self.number += 1 - rule = self.write_empty_list_rule(self) + rule = self.write_annotation_rule(self, 3) + self.add_rule(rule) + + self.number = 10401 + rule = self.write_notes_rule(self, 1) + self.add_rule(rule) + + self.number += 1 + rule = self.write_notes_rule(self, 2) + self.add_rule(rule) + + self.number += 1 + rule = self.write_notes_rule(self, 3) + self.add_rule(rule) + + self.number += 1 + rule = self.write_notes_rule(self, 4) self.add_rule(rule) def add_rule(self, rule): @@ -154,13 +198,24 @@ def write_unknown_rule(self): # write rules about ns @staticmethod def write_ns_rule(self): - text = 'To conform to the {0} specification for SBML Level~{1} ' \ - 'Version~{2}, an SBML document must declare ' \ - '\\uri{3}http://www.sbml.org/sbml/' \ - 'level{1}/version{2}/{4}/version{5}{6} as the XMLNamespace ' \ - 'to use for elements of this package.'\ - .format(self.full_pkg_command, self.level, self.version, - self.start_b, self.package, self.pkg_version, self.end_b) + if global_variables.is_sbml: + text = 'To conform to the {0} specification for {7} Level~{1} ' \ + 'Version~{2}, an {7} document must declare ' \ + '\\uri{3}http://www.sbml.org/sbml/' \ + 'level{1}/version{2}/{4}/version{5}{6} as the XMLNamespace ' \ + 'to use for elements of this package.'\ + .format(self.full_pkg_command, self.level, self.version, + self.start_b, self.package, self.pkg_version, self.end_b, + global_variables.language.upper()) + else: + text = 'To conform to the {0} specification for {7} Level~{1} ' \ + 'Version~{2}, an {7} document must declare ' \ + '\\uri{3}{8}{6} as the XMLNamespace ' \ + 'to use for elements of this package.'\ + .format(self.full_pkg_command, self.level, self.version, + self.start_b, self.package, self.pkg_version, self.end_b, + global_variables.language.upper(), global_variables.namespaces[0]['namespace']) + ref = '{0} {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section('xml-namespace', False)) @@ -176,13 +231,22 @@ def write_ns_rule(self): @staticmethod def write_element_not_ns_rule(self): - text = 'Wherever they appear in an SBML document, elements and ' \ - 'attributes from the {0} must use the ' \ - '\\uri{1}http://www.sbml.org/sbml/level{2}/version{3}' \ - '/{4}/version{5}{6} namespace, declaring so either explicitly ' \ - 'or implicitly.'\ - .format(self.full_pkg_command, self.start_b, self.level, - self.version, self.package, self.pkg_version, self.end_b) + if global_variables.is_sbml: + text = 'Wherever they appear in an SBML document, elements and ' \ + 'attributes from the {0} must use the ' \ + '\\uri{1}http://www.sbml.org/sbml/level{2}/version{3}' \ + '/{4}/version{5}{6} namespace, declaring so either explicitly ' \ + 'or implicitly.'\ + .format(self.full_pkg_command, self.start_b, self.level, + self.version, self.package, self.pkg_version, self.end_b) + else: + text = 'Wherever they appear in a {7} document, elements and ' \ + 'attributes from the {0} must use the ' \ + '\\uri{1}{8}{6} namespace, declaring so either explicitly ' \ + 'or implicitly.' \ + .format(self.full_pkg_command, self.start_b, self.level, + self.version, self.package, self.pkg_version, self.end_b, + global_variables.language.upper(), global_variables.namespaces[0]['namespace']) ref = '{0} {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section('xml-namespace', False)) @@ -347,3 +411,65 @@ def write_empty_list_rule(self): 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref}) + @staticmethod + def write_annotation_rule(self, num): + if num == 1: + text = 'Every top-level XML element within an \\{0} object must ' \ + 'have an XML namespace declared.'.format(global_variables.annot_element) + short = 'No ns for {0}'.format(global_variables.annot_element) + tc = '{0}NoAnnotationNS'.format(global_variables.prefix) + elif num == 2: + text = 'A given XML namespace cannot be the namespace of more than one top-level' \ + 'element within a given \\{0} object.'.format(global_variables.annot_element) + short = 'Repeat ns for {0}'.format(global_variables.annot_element) + tc = '{0}RepeatAnnotationNS'.format(global_variables.prefix) + else: + text = 'A given {0} element may contain at most one \\{1} ' \ + 'subobject.'.format(global_variables.up_full_lib, global_variables.annot_element) + short = 'Only one {0}'.format(global_variables.annot_element) + tc = '{0}OnlyOneAnnotation'.format(global_variables.prefix) + + ref = '{0} {1}.' \ + .format(self.pkg_ref, + strFunctions.wrap_section('annotation-use', False)) + sev = 'ERROR' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + 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}) + + @staticmethod + def write_notes_rule(self, num): + if num == 1: + text = 'The contents of a \\{0} object must be explicitly placed in the ' \ + 'XHTML XML namespace. '.format('Notes') + short = 'Notes not in XHTML' + tc = 'NotesInXHTML' + elif num == 2: + text = 'The contents of a \\{0} object must not contain an XML declaration, ' \ + '\\ie a string of the form \\val{1}{2} or ' \ + 'similar.'.format('Notes', '{', '}') + short = 'No XML decl in Notes' + tc = 'XMLDeclNotes' + elif num == 3: + text = 'The content of a \\{0} object must not contain an XML DOCTYPE declaration, ' \ + '\\ie a string beginning with the characters \\val{1} Date: Wed, 21 Jun 2023 10:38:06 +0100 Subject: [PATCH 22/37] amend metaid rule --- deviser/validation/ValidationRulesGeneral.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/deviser/validation/ValidationRulesGeneral.py b/deviser/validation/ValidationRulesGeneral.py index cfabbbec..ff52acb9 100644 --- a/deviser/validation/ValidationRulesGeneral.py +++ b/deviser/validation/ValidationRulesGeneral.py @@ -350,10 +350,17 @@ def write_reqd_value_rule(self): @staticmethod 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.' + if global_variables.is_sbml: + 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.' + else: + text = 'The value of a {0} must conform to the syntax of ' \ + 'the XML Type ID'\ + .format(strFunctions.wrap_token('metaid', self.package)) + ref = 'metaid' + # ref = '{0} {1}.'\ # .format(self.pkg_ref, # strFunctions.wrap_section('primitive-types', False)) From 1b4059d8e1864bd2c7fe445e038cdb0ca09fb581 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 21 Jun 2023 10:47:58 +0100 Subject: [PATCH 23/37] sort notes/annotations --- deviser/validation/ValidationRulesGeneral.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deviser/validation/ValidationRulesGeneral.py b/deviser/validation/ValidationRulesGeneral.py index ff52acb9..ca56e6a0 100644 --- a/deviser/validation/ValidationRulesGeneral.py +++ b/deviser/validation/ValidationRulesGeneral.py @@ -432,7 +432,7 @@ def write_annotation_rule(self, num): tc = '{0}RepeatAnnotationNS'.format(global_variables.prefix) else: text = 'A given {0} element may contain at most one \\{1} ' \ - 'subobject.'.format(global_variables.up_full_lib, global_variables.annot_element) + 'subobject.'.format(global_variables.language.upper(), global_variables.annot_element) short = 'Only one {0}'.format(global_variables.annot_element) tc = '{0}OnlyOneAnnotation'.format(global_variables.prefix) @@ -466,7 +466,7 @@ def write_notes_rule(self, num): tc = 'DOCTYPEInNotes' else: text = 'A given {0} element may contain at most one \\{1} ' \ - 'subobject.'.format(global_variables.up_full_lib, 'Notes') + 'subobject.'.format(global_variables.language.upper(), 'Notes') short = 'Only one {0}'.format('Notes') tc = '{0}OnlyOneNotes'.format(global_variables.prefix) From df3c0b9893ed055758e58313e8ce468ed53acad2 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 24 Jun 2023 10:04:50 +0100 Subject: [PATCH 24/37] sort validation rules --- .../test-tex/testsbxml/apdx-validation.tex | 62 +++--- deviser/spec_files/TexValidationRulesFile.py | 7 +- deviser/validation/ValidationRulesForClass.py | 195 ++++++++++++------ 3 files changed, 165 insertions(+), 99 deletions(-) diff --git a/deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex b/deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex index 9c453a76..66db3160 100644 --- a/deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex +++ b/deviser/pytest_files/test_tex/test-tex/testsbxml/apdx-validation.tex @@ -52,16 +52,16 @@ \subsection{Validation and consistency rules} the \TestTSBXMLLibraryPackage package. For \notice convenience and brevity, we use the shorthand -``\token{tsb:\-x}'' to stand for an attribute or element name \token{x} -in the namespace for the \TestTSBXMLLibraryPackage package, using the -namespace prefix \token{tsb}. In reality, the prefix string may be -different from the literal ``\token{tsb}'' used here (and indeed, it can -be any valid XML namespace prefix that the modeler or software chooses). -We use ``\token{tsb:\-x}'' because it is shorter than to write a full +``\token{:\-x}'' to stand for an attribute or element name \token{x} in +the namespace for the \TestTSBXMLLibraryPackage package, using the +namespace prefix \token{}. In reality, the prefix string may be +different from the literal ``\token{}'' used here (and indeed, it can be +any valid XML namespace prefix that the modeler or software chooses). We +use ``\token{:\-x}'' because it is shorter than to write a full explanation everywhere we refer to an attribute or element in the \TestTSBXMLLibraryPackage namespace. -\subsubsection*{General rules about this language.} +\subsubsection*{General rules about this package} \validRule{tsb-10101}{To conform to the \TestTSBXMLLibrary specification for TSB Level~1 Version~1, an TSB document must declare @@ -77,10 +77,8 @@ \subsubsection*{General rules about this language.} \subsubsection*{General rules about identifiers} -\validRule{tsb-10201}{The value of a \token{tsb:\-metaid} must conform -to the syntax of the XML Type ID (Reference: )} - - +\validRule{tsb-10201}{The value of a \token{metaid} must conform to the +syntax of the XML Type ID (Reference: metaid)} \subsubsection*{General rules for \TestAnnotation elements} @@ -114,8 +112,8 @@ \subsubsection*{General rules for \notes elements} \val{ 0: @@ -353,39 +352,77 @@ def write_attribute_type_rule(self, attribute, lo=None): @staticmethod # write core attribute rule 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' - lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) - tc = '{0}{1}AllowedCoreAttributes'.format(self.up_package, - self.name) - short = 'Core attributes allowed on <{0}>.'.format(self.lower_name) - lo = False + if global_variables.is_sbml: + 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' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}AllowedCoreAttributes'.format(self.up_package, + self.name) + short = 'Core attributes allowed on <{0}>.'.format(self.lower_name) + lo = False + else: + loname = strFunctions.get_tex_element_name(lo_child, leave_pkg_prefix=False) + temp = strFunctions.remove_prefix(lo_child['element']) + lo_name = loname[7:] #strFunctions.plural(temp) + 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_tex_element_name(lo_child, False), + strFunctions.wrap_token('metaid'), + strFunctions.wrap_token('sboTerm')) + sec_name = 'listof' + lo_name.lower() + ref = '{0}, {1}.'\ + .format(self.pkg_ref, strFunctions.wrap_section(sec_name)) + sev = 'ERROR' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}LO{2}AllowedCoreAttributes'.format(self.up_package, + self.name, lo_name) + lo = True + short = 'Core attributes allowed on .'.format(lo_name) else: - loname = strFunctions.get_tex_element_name(lo_child, leave_pkg_prefix=False) - temp = strFunctions.remove_prefix(lo_child['element']) - lo_name = loname[7:] #strFunctions.plural(temp) - 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_tex_element_name(lo_child, False), - strFunctions.wrap_token('metaid'), - strFunctions.wrap_token('sboTerm')) - sec_name = 'listof' + lo_name.lower() - ref = '{0}, {1}.'\ - .format(self.pkg_ref, strFunctions.wrap_section(sec_name)) - sev = 'ERROR' - lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) - tc = '{0}{1}LO{2}AllowedCoreAttributes'.format(self.up_package, - self.name, lo_name) - lo = True - short = 'Core attributes allowed on .'.format(lo_name) + 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' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}AllowedCoreAttributes'.format(self.up_package, + self.name) + short = 'Core attributes allowed on <{0}>.'.format(self.lower_name) + lo = False + else: + loname = strFunctions.get_tex_element_name(lo_child, leave_pkg_prefix=False) + temp = strFunctions.remove_prefix(lo_child['element']) + lo_name = loname[7:] #strFunctions.plural(temp) + text = 'A {0} object may have the optional attribute {1}. No other attributes from the ' \ + '{2} Level~{3} Version~{4} namespaces are permitted on a {0} object.'\ + .format(strFunctions.get_tex_element_name(lo_child, False), + strFunctions.wrap_token('metaid'), + global_variables.language.upper(), + global_variables.namespaces[0]['level'], + global_variables.namespaces[0]['version'] + ) + sec_name = 'listof' + lo_name.lower() + ref = '{0}, {1}.'\ + .format(self.pkg_ref, strFunctions.wrap_section(sec_name)) + sev = 'ERROR' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}LO{2}AllowedCoreAttributes'.format(self.up_package, + self.name, lo_name) + lo = True + short = 'Core attributes allowed on .'.format(lo_name) + lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, @@ -396,36 +433,68 @@ def write_core_attribute_rule(self, lo_child=None): # write core subobjects rule @staticmethod def write_core_subobject_rule(self, lo_child=None): - if lo_child is None: - text = '{0} {1} object may have the optional SBML Level~3 ' \ - 'Core subobjects for notes and annotations. No other ' \ - 'elements from the SBML Level~3 Core namespaces are ' \ - 'permitted on {2} {1}.'\ - .format(self.indef_u, self.formatted_name, self.indef) - ref = 'SBML Level~3 Version~1 Core, Section~3.2.' - sev = 'ERROR' - lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) - tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name) - short = 'Core elements allowed on <{0}>.'.format(self.lower_name) - lo = False + if global_variables.is_sbml: + if lo_child is None: + text = '{0} {1} object may have the optional SBML Level~3 ' \ + 'Core subobjects for notes and annotations. No other ' \ + 'elements from the SBML Level~3 Core namespaces are ' \ + 'permitted on {2} {1}.'\ + .format(self.indef_u, self.formatted_name, self.indef) + ref = 'SBML Level~3 Version~1 Core, Section~3.2.' + sev = 'ERROR' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name) + short = 'Core elements allowed on <{0}>.'.format(self.lower_name) + lo = False + else: + loname = strFunctions.get_tex_element_name(lo_child, leave_pkg_prefix=False) + temp = strFunctions.remove_prefix(lo_child['element']) + lo_name = loname[7:] #strFunctions.plural(temp) + text = r'Apart from the general notes and annotations subobjects ' \ + r'permitted on all SBML objects, a {0} container object ' \ + r'may only contain \{1} objects.'\ + .format(loname, temp) + sec_name = 'listof' + lo_name.lower() + ref = '{0}, {1}.'\ + .format(self.pkg_ref, strFunctions.wrap_section(sec_name)) + sev = 'ERROR' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name, + lo_name) + lo = True + short = 'Core elements allowed on .'.format(lo_name) + lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) else: - loname = strFunctions.get_tex_element_name(lo_child, leave_pkg_prefix=False) - temp = strFunctions.remove_prefix(lo_child['element']) - lo_name = loname[7:] #strFunctions.plural(temp) - text = r'Apart from the general notes and annotations subobjects ' \ - r'permitted on all SBML objects, a {0} container object ' \ - r'may only contain \{1} objects.'\ - .format(loname, temp) - sec_name = 'listof' + lo_name.lower() - ref = '{0}, {1}.'\ - .format(self.pkg_ref, strFunctions.wrap_section(sec_name)) - sev = 'ERROR' - lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) - tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name, - lo_name) - lo = True - short = 'Core elements allowed on .'.format(lo_name) - lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) + if lo_child is None: + text = '{0} {1} object may have the optional SBML Level~3 ' \ + 'Core subobjects for notes and annotations. No other ' \ + 'elements from the SBML Level~3 Core namespaces are ' \ + 'permitted on {2} {1}.'\ + .format(self.indef_u, self.formatted_name, self.indef) + ref = 'SBML Level~3 Version~1 Core, Section~3.2.' + sev = 'ERROR' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name) + short = 'Core elements allowed on <{0}>.'.format(self.lower_name) + lo = False + else: + child = strFunctions.remove_prefix(lo_child['element']) + loname = strFunctions.list_of_name(child, False) + text = r'Apart from the general \notes and \{2} subobjects ' \ + r'permitted on all {3} objects, a \{0} container object ' \ + r'may only contain \{1} objects.' \ + .format(loname, child, global_variables.annot_element, + global_variables.language.upper()) + sec_name = loname.lower() + ref = '{0}, {1}.' \ + .format(self.pkg_ref, strFunctions.wrap_section(sec_name)) + sev = 'ERROR' + lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) + tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name, child) + lo = True + short = 'Core elements allowed on .'.format(child) + 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, From 906baabbfb22480115092c1c7933af58566a957e Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 24 Jun 2023 10:06:59 +0100 Subject: [PATCH 25/37] put back tests --- deviser/pytest_files/test_tex/test_tex.py | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/deviser/pytest_files/test_tex/test_tex.py b/deviser/pytest_files/test_tex/test_tex.py index 7ec2b64e..27b6cb80 100644 --- a/deviser/pytest_files/test_tex/test_tex.py +++ b/deviser/pytest_files/test_tex/test_tex.py @@ -31,19 +31,19 @@ def teardown(): @pytest.mark.parametrize("name, test_type", [ - # ('spatial', 'body'), - # ('qual', 'apdx-validation'), - # ('groups', 'macros'), - # ('groups', 'apdx-validation'), - # ('groups', 'body'), - # ('unknown_type', 'apdx-validation'), - # ('test_sidrefs', 'apdx-validation'), - # ('test_sidrefs', 'body'), - # ('test_lists', 'apdx-validation'), - # ('test_lists', 'body'), - # ('test_att', 'apdx-validation'), - # ('testsbxml', 'apdx-validation'), - ('testsbxml', 'macros'), + ('spatial', 'body'), + ('qual', 'apdx-validation'), + ('groups', 'macros'), + ('groups', 'apdx-validation'), + ('groups', 'body'), + ('unknown_type', 'apdx-validation'), + ('test_sidrefs', 'apdx-validation'), + ('test_sidrefs', 'body'), + ('test_lists', 'apdx-validation'), + ('test_lists', 'body'), + ('test_att', 'apdx-validation'), + ('testsbxml', 'apdx-validation'), + # ('testsbxml', 'macros'), ]) def test_tex(name, test_type): assert rtt.run_test(name, test_type) == 0 From 99796d3a1b294879ca12013954b36d897a304a2b Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 24 Jun 2023 10:56:01 +0100 Subject: [PATCH 26/37] changes while i work on error files --- deviser/code_files/ValidationFiles.py | 3 +- .../test-code/tsb/TSBErrorTable.h | 21 +++-- .../test_other_library/test_other_library.py | 82 ++++++++----------- 3 files changed, 47 insertions(+), 59 deletions(-) diff --git a/deviser/code_files/ValidationFiles.py b/deviser/code_files/ValidationFiles.py index e28f5d7d..dca7b946 100644 --- a/deviser/code_files/ValidationFiles.py +++ b/deviser/code_files/ValidationFiles.py @@ -106,7 +106,8 @@ def create_rule_structure(self): rules = ValidationRulesGeneral\ .ValidationRulesGeneral(self.fullname, number, self.package, self.pkg_ref, self.level, self.version, - self.pkg_version, self.reqd_status) + self.pkg_version, self.reqd_status, + global_variables.language) rules.determine_rules() self.class_rules += rules.rules if global_variables.is_package: diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h b/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h index aae6825a..a84574ef 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h @@ -244,10 +244,9 @@ static const tsbErrorTableEntry tsbErrorTable[] = "The Tsb namespace is not correctly declared.", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "To conform to the Package specification for SBML Level 0 Version 1, an " - "SBML document must declare " - "'http://www.sbml.org/sbml/level0/version1/tsb/version0' as the " - "XMLNamespace to use for elements of this package.", + "To conform to the tsb specification for TSB Level 1 Version 1, an TSB " + "document must declare 'http://testsbxml.org/l1v1' as the XMLNamespace to " + "use for elements of this package.", { "L3V1 Tsb V1 Section 3.1" } }, @@ -446,20 +445,20 @@ static const tsbErrorTableEntry tsbErrorTable[] = } }, - // 20303 + // 20301 { TsbCommentAllowedAttributes, "Attributes allowed on .", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, "A object must have the required attributes 'tsb:contributor' and " - "'tsb:number', and may have the optional attribute 'tsb:point'. No other " - "attributes from the SBML Level 3 Test SB XML Library namespaces are " - "permitted on a object. ", + "'tsb:number', and may have the optional attributes 'tsb:point' and " + "'tsb:metaid'. No other attributes from the TSB Level 1 Version 1 " + "namespaces are permitted on a object. ", { "L3V1 Tsb V1 Section" } }, - // 20304 + // 20302 { TsbCommentContributorMustBeString, "The 'contributor' attribute must be String.", LIBTSB_CAT_GENERAL_CONSISTENCY, @@ -470,7 +469,7 @@ static const tsbErrorTableEntry tsbErrorTable[] = } }, - // 20305 + // 20303 { TsbCommentNumberMustBeDouble, "The 'number' attribute must be Double.", LIBTSB_CAT_GENERAL_CONSISTENCY, @@ -481,7 +480,7 @@ static const tsbErrorTableEntry tsbErrorTable[] = } }, - // 20306 + // 20304 { TsbCommentPointMustBeString, "The 'point' attribute must be String.", LIBTSB_CAT_GENERAL_CONSISTENCY, diff --git a/deviser/pytest_files/test_other_library/test_other_library.py b/deviser/pytest_files/test_other_library/test_other_library.py index cebc871d..edf9f9b1 100644 --- a/deviser/pytest_files/test_other_library/test_other_library.py +++ b/deviser/pytest_files/test_other_library/test_other_library.py @@ -29,7 +29,7 @@ def teardown(): shutil.rmtree(temp_dir) -# @pytest.mark.parametrize('name, num, class_name, test_case, list_of', [ +@pytest.mark.parametrize('name, num, class_name, test_case, list_of', [ # ('test_sedml', 1, 'SedModel', 'model', 'SedListOfModels'), # ('test_sedml', 0, 'SedDocument', 'document', ''), # ('test_sedml', 3, 'SedAddXML', 'xmlnode used', ''), @@ -44,48 +44,38 @@ def teardown(): # 'SedListOfOutputs'), # ('combine-archive', 0, 'CaContent', 'check includes', 'CaListOfContents'), # ('combine-archive', 1, 'CaOmexManifest', 'document', ''), -# ('testsbxml', 1, 'TSBComment', 'comment class', 'TSBListOfComments'), -# ('testsbxml', 0, 'TSBDocument', 'document', ''), -# ]) -# def test_cpp(name, num, class_name, test_case, list_of): -# """ -# Run the C++ file tests. -# -# :param name: name of test group e.g. 'test_sedml', 'combine-archive'. -# :param num: list index, so we only generate a -# particular class, not all of them -# :param class_name: name of C++ class (and thus .cpp/.h filenames), -# e.g. 'CaContent' -# :param test_case: brief test description -# :param list_of: class name (and thus filenames) of any corresponding -# "list of" class, e.g. 'CaListOfContents' -# """ -# gv.reset() -# xml_filename = functions.set_up_test(name, class_name, test_case) -# assert xml_filename is not None and xml_filename != "" -# test_utils.generate_new_cpp_header(xml_filename, num) -# assert 0 == test_utils.compare_code_headers(class_name) -# assert 0 == test_utils.compare_code_impl(class_name) -# if len(list_of) > 0: -# class_name = list_of -# assert 0 == test_utils.compare_code_headers(class_name) -# assert 0 == test_utils.compare_code_impl(class_name) -# + ('testsbxml', 1, 'TSBComment', 'comment class', 'TSBListOfComments'), + ('testsbxml', 0, 'TSBDocument', 'document', ''), + ]) +def test_cpp(name, num, class_name, test_case, list_of): + """ + Based on old test_utils.run_templates() function. Run the 'template' file tests. + + :param name: name of test group e.g. 'test_sedml', 'combine-archive'. + :param class_name: name of C++ class (and thus .cpp/.h filenames), + e.g. 'SedBase' + :param test_case: brief test description, e.g. 'templates'. + :param list_of: class name (and thus filenames) of any corresponding + "list of" class, e.g. 'SedListOf' + """ + # gv.reset() + # xml_filename = functions.set_up_test(name, class_name, test_case) + # assert xml_filename is not None and xml_filename != "" + # test_utils.generate_new_cpp_header(xml_filename, num) + # assert 0 == test_utils.compare_code_headers(class_name) + # assert 0 == test_utils.compare_code_impl(class_name) + # if len(list_of) > 0: + # class_name = list_of + # assert 0 == test_utils.compare_code_headers(class_name) + # assert 0 == test_utils.compare_code_impl(class_name) + print('skip') + @pytest.mark.parametrize('name, class_name, test_case, list_of', [ -# ('test_sedml', 'SedBase', 'templates', 'SedListOf'), -# ('combine-archive', 'CaBase', 'templates', 'CaListOf'), +# # Tests from old test_utils.testCombine() +# ('test_sedml', 'SedBase', 'templates', 'SedListOf'), +# ('combine-archive', 'CaBase', 'templates', 'CaListOf'), ('testsbxml', 'TSBBase', 'templates', 'TSBListOf'), - ('testsbxml', 'TSBConstructorException', 'templates', ''), - ('testsbxml', 'TSBReader', 'templates', ''), - ('testsbxml', 'TSBWriter', 'templates', ''), - ('testsbxml', 'TSBErrorLog', 'templates', ''), - ('testsbxml', 'TSBNamespaces', 'templates', ''), - ('testsbxml', 'TSBError', 'templates', ''), - ('testsbxml', 'TSBVisitor', 'templates', ''), - ('testsbxml', 'TSBTypeCodes', 'templates', ''), - ('testsbxml', 'TSBTypes', 'templates', ''), -# ('testsbxml', 'TSBErrorTable', 'templates', '') ]) def test_templates(name, class_name, test_case, list_of): """ @@ -103,13 +93,11 @@ def test_templates(name, class_name, test_case, list_of): assert xml_filename is not None and xml_filename != "" test_utils.generate_templates(xml_filename) assert 0 == test_utils.compare_code_headers(class_name) - if class_name != 'TSBTypes' and class_name != 'TSBErrorTable': - assert 0 == test_utils.compare_code_impl(class_name) - if list_of: - assert 0 == test_utils.compare_code_headers(list_of) - assert 0 == test_utils.compare_code_impl(list_of) -# -# + assert 0 == test_utils.compare_code_impl(class_name) + assert 0 == test_utils.compare_code_headers(list_of) + assert 0 == test_utils.compare_code_impl(list_of) + + # @pytest.mark.parametrize('name, class_name, test_case, prefix, lib', [ # ('test_sedml', 'SedBase', 'common', 'Sed', 'sedml'), # ('combine-archive', 'CaBase', 'common', 'Ca', 'combine'), From 5166f19f74e447ba7884c924a6defe513cbf5625 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 24 Jul 2023 09:02:46 +0100 Subject: [PATCH 27/37] validation sorted to date --- deviser/code_files/ValidationFiles.py | 40 ++++-- deviser/code_files/templates/Error.h | 11 -- deviser/code_files/templates/ErrorTable.h | 120 ------------------ .../test-code/tsb/TSBError.h | 53 +++----- .../test_other_library/test_utils.py | 4 +- deviser/validation/ValidationRulesForClass.py | 39 +++--- deviser/validation/ValidationRulesGeneral.py | 56 ++++---- 7 files changed, 98 insertions(+), 225 deletions(-) diff --git a/deviser/code_files/ValidationFiles.py b/deviser/code_files/ValidationFiles.py index dca7b946..11fb66a4 100644 --- a/deviser/code_files/ValidationFiles.py +++ b/deviser/code_files/ValidationFiles.py @@ -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, @@ -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() @@ -438,10 +448,12 @@ 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: @@ -449,12 +461,7 @@ def replace_name(i, text_string, length): 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: @@ -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 diff --git a/deviser/code_files/templates/Error.h b/deviser/code_files/templates/Error.h index 0acdb23a..24fe012b 100644 --- a/deviser/code_files/templates/Error.h +++ b/deviser/code_files/templates/Error.h @@ -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 -, SBMLMissingNamespace = 10401 /*!< Missing declaration of the XML namespace for the annotation. */ -, SBMLDuplicateNamespaces = 10402 /*!< Multiple annotations using the same XML namespace. */ -, SBMLNamespaceIn = 10403 /*!< The SBML_Lang XML namespace cannot be used in an object. */ -, SBMLMultiples = 10404 /*!< Only one object is permitted under a given SBML_Lang object. */ -, SBMLNotElement = 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. */ , SBMLUnknownCoreAttribute = 99994 /*!< Encountered an unknown attribute in the SBML_Lang Core namespace. */ , SBMLCodesUpperBound = 99999 /*!< Upper boundary of libSBML-specific diagnostic codes. */ diff --git a/deviser/code_files/templates/ErrorTable.h b/deviser/code_files/templates/ErrorTable.h index ea8e1021..8fb21fc1 100644 --- a/deviser/code_files/templates/ErrorTable.h +++ b/deviser/code_files/templates/ErrorTable.h @@ -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 element, and the " - " element must be either explicitly or implicitly in the XML " - "namespace \"http://www.w3.org/1998/Math/MathML\".", - {"" - } - }, - - //10401 - { - SBMLMissingNamespace, - "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 - { - SBMLDuplicateNamespaces, - "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, - "The SBML_Lang XML namespace cannot be used in an 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 - { - SBMLMultiples, - "Only one 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 element.", - {"" - } - }, - - //10801 - { - SBMLNotesNotInXHTMLNamespace, - "Notes must be placed in the XHTML XML namespace", - LIBSBML_CAT_SBML, - LIBSBML_SEV_ERROR, - "The contents of the 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 element must not contain an XML declaration " - "(i.e., a string of the form \"\" " - "or similar).", - {"" - } - }, - - //10803 - { - SBMLNotesContainsDOCTYPE, - "XML DOCTYPE elements are not permitted in Notes objects", - LIBSBML_CAT_SBML, - LIBSBML_SEV_ERROR, - "The contents of the element must not contain an XML DOCTYPE " - "declaration (i.e., a string beginning with the characters \" 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 element. ", - {"" - } - }, - /* -------------------------------------------------------------------------- * Boundary marker. SBML_Lang specific errors. * ----------------------------------------------------------------------- */ diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBError.h b/deviser/pytest_files/test_other_library/test-code/tsb/TSBError.h index ab9e2427..cad7fe16 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/TSBError.h +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBError.h @@ -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; diff --git a/deviser/pytest_files/test_other_library/test_utils.py b/deviser/pytest_files/test_other_library/test_utils.py index 09c8be7e..d638b434 100644 --- a/deviser/pytest_files/test_other_library/test_utils.py +++ b/deviser/pytest_files/test_other_library/test_utils.py @@ -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") diff --git a/deviser/validation/ValidationRulesForClass.py b/deviser/validation/ValidationRulesForClass.py index 35174b5f..4acb29ed 100644 --- a/deviser/validation/ValidationRulesForClass.py +++ b/deviser/validation/ValidationRulesForClass.py @@ -41,7 +41,7 @@ from ..util import strFunctions, query, global_variables -class ValidationRulesForClass(): +class ValidationRulesForClass: """Class for creating the validation rules for an object""" def __init__(self, object_desc, spec_name, number, package, pkg_ref): @@ -53,7 +53,8 @@ def __init__(self, object_desc, spec_name, number, package, pkg_ref): self.number = number self.package = package.lower() self.pkg_ref = pkg_ref - self.up_package = strFunctions.upper_first(self.package) + self.level = object_desc['root']['base_level'] + self.version = object_desc['root']['base_version'] # useful repeated text strings self.valid = '\\validRule{' @@ -82,6 +83,14 @@ def __init__(self, object_desc, spec_name, number, package, pkg_ref): self.parse_elements(self, object_desc['attribs'], object_desc['root']) self.rules = [] self.tc = 'TBC' + # constants for rules + if global_variables.is_sbml: + self.up_package = strFunctions.upper_first(self.package) + self.lib_ref = 'L3V1 {0} V1 Section 3.1'.format(self.up_package) + else: + self.up_package = self.package.upper() + self.lib_ref = '{0} L{1}V{2} Section '.format(self.up_package, self.level, self.version) + ######################################################################## @@ -185,9 +194,9 @@ def add_lo_rules(self): self.write_lochild_attribute_rule(self.lo_reqd_att[i], lo_info) self.add_rule(rule) if rule and 'attributes' in lo_info[0]: - for i in range(0, len(lo_info[0]['attributes'])): + for j in range(0, len(lo_info[0]['attributes'])): self.number += 1 - rule = self.write_attribute_type_rule(self, lo_info[0]['attributes'][i], lo_info[0]) + rule = self.write_attribute_type_rule(self, lo_info[0]['attributes'][j], lo_info[0]) self.add_rule(rule) lo_info = [] @@ -197,9 +206,9 @@ def add_lo_rules(self): self.write_lochild_attribute_rule(self.lo_opt_att[i], lo_info) self.add_rule(rule) if rule and 'attributes' in lo_info[0]: - for i in range(0, len(lo_info[0]['attributes'])): + for j in range(0, len(lo_info[0]['attributes'])): self.number += 1 - rule = self.write_attribute_type_rule(self, lo_info[0]['attributes'][i], lo_info[0]) + rule = self.write_attribute_type_rule(self, lo_info[0]['attributes'][j], lo_info[0]) self.add_rule(rule) def add_rule(self, rule): @@ -225,7 +234,7 @@ def write_attribute_type_rule(self, attribute, lo=None): refname = self.name abbrev = self.name att_type = attribute['type'] - [att_name_no_hyphen, unused] = strFunctions.remove_hyphens(attribute['name']) + [att_name_no_hyphen, __] = strFunctions.remove_hyphens(attribute['name']) att_name = strFunctions.upper_first(att_name_no_hyphen) name = strFunctions.wrap_token(attribute['texname'], self.package) rule_type = 'String' @@ -345,7 +354,7 @@ def write_attribute_type_rule(self, attribute, lo=None): 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, + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref, 'object': refname, 'attrib': att_name, 'attrib_type': att_type}) @@ -426,7 +435,7 @@ def write_core_attribute_rule(self, lo_child=None): 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, + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref, 'plugin': False, 'object': self.name, 'lo': lo, 'reqd': self.reqd_elem, 'opt': self.opt_elem}) @@ -497,7 +506,7 @@ def write_core_subobject_rule(self, lo_child=None): return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, - 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref, 'plugin': False, 'object': self.name, 'lo': lo, 'reqd': self.reqd_elem, 'opt': self.opt_elem}) @@ -538,7 +547,7 @@ def write_package_attribute_rule(self): tc = '{0}{1}AllowedAttributes'.format(self.up_package, self.name) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, - 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref, 'plugin': False, 'object': self.name, 'lo': False, 'reqd': self.reqd_att, 'opt': self.opt_att}) @@ -594,7 +603,7 @@ def write_package_object_rule(self): tc = '{0}{1}AllowedElements'.format(self.up_package, self.name) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, - 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref, 'plugin': False, 'object': self.name, 'reqd': self.reqd_elem, 'opt': self.opt_elem}) @@ -657,7 +666,7 @@ def write_lochild_attribute_rule(self, child, lo_info): strFunctions.plural(name)) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, - 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref, 'plugin': False, 'object': self.name, 'lo': True, 'reqd': child_reqd, 'opt': child_opt, 'lo_object': lo_info[0]['name']}) @@ -722,7 +731,7 @@ def write_optional_lo_rule(self): tc = '{0}{1}EmptyLOElements'.format(self.up_package, self.name, ) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, - 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref, 'plugin': False, 'object': self.name, 'lo_object': self.opt_child_lo_elem}) @@ -783,7 +792,7 @@ def write_reqd_lo_rule(self): tc = '{0}{1}EmptyReqdLOElements'.format(self.up_package, self.name) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, - 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) ######################################################################### diff --git a/deviser/validation/ValidationRulesGeneral.py b/deviser/validation/ValidationRulesGeneral.py index ca56e6a0..51904668 100644 --- a/deviser/validation/ValidationRulesGeneral.py +++ b/deviser/validation/ValidationRulesGeneral.py @@ -69,6 +69,13 @@ def __init__(self, spec_name, number, package, pkg_ref, level, version, self.rules = [] self.tc = 'TBC' + # constants for rules + if global_variables.is_sbml: + self.lib_ref = 'L3V1 {0} V1 Section 3.1'.format(self.up_package) + self.up_package = strFunctions.upper_first(self.package) + else: + self.lib_ref = '{0} L{1}V{2} Section '.format(self.up_package.upper(), self.level, self.version) + self.up_package = self.package.upper() ######################################################################## @@ -184,16 +191,15 @@ def add_rule(self, rule): # write rule about ns @staticmethod def write_unknown_rule(self): - text = 'Unknown error from {0}'.format(self.up_package) + text = 'Unknown error from {0}'.format(self.up_package.upper()) ref = '' sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) - short = 'Unknown error from {0}'.format(self.up_package) - lib_ref = '' + short = 'Unknown error from {0}'.format(self.up_package.upper())*10 tc = global_variables.unknown_error return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, - 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) # write rules about ns @staticmethod @@ -223,11 +229,11 @@ def write_ns_rule(self): lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'The {0} namespace is not correctly ' \ 'declared.'.format(self.up_package) - lib_ref = 'L3V1 {0} V1 Section 3.1'.format(self.up_package) + tc = '{0}NSUndeclared'.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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_element_not_ns_rule(self): @@ -253,11 +259,10 @@ def write_element_not_ns_rule(self): sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Element not in {0} namespace'.format(self.up_package) - lib_ref = 'L3V1 {0} V1 Section 3.1'.format(self.up_package) tc = '{0}ElementNotInNs'.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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_id_rule(self): @@ -270,11 +275,10 @@ def write_id_rule(self): sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Duplicate \'id\' attribute value' - lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}DuplicateComponentId'.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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_id_syntax_rule(self): @@ -289,11 +293,10 @@ def write_id_syntax_rule(self): 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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_reqd_rule(self): @@ -306,11 +309,10 @@ def write_reqd_rule(self): sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Required {0}:required attribute on '.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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_reqd_bool_rule(self): @@ -323,11 +325,10 @@ def write_reqd_bool_rule(self): 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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_reqd_value_rule(self): @@ -342,11 +343,10 @@ def write_reqd_value_rule(self): 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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_metaid_syntax_rule(self): @@ -367,11 +367,10 @@ def write_metaid_syntax_rule(self): 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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_valid_ns_rule(self): @@ -382,11 +381,10 @@ def write_valid_ns_rule(self): sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Invalid namespace'.format(self.up_package) - lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = 'InvalidNamespaceOn{0}'.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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_allowed_attributes_rule(self): @@ -397,11 +395,10 @@ def write_allowed_attributes_rule(self): sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Allowed attributes'.format(self.up_package) - lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = 'AllowedAttributes'.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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_empty_list_rule(self): @@ -412,11 +409,10 @@ def write_empty_list_rule(self): sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'No empty listOf'.format(self.up_package) - lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}EmptyListElement'.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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_annotation_rule(self, num): @@ -441,10 +437,9 @@ def write_annotation_rule(self, num): strFunctions.wrap_section('annotation-use', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) - 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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) @staticmethod def write_notes_rule(self, num): @@ -469,14 +464,11 @@ def write_notes_rule(self, num): 'subobject.'.format(global_variables.language.upper(), 'Notes') short = 'Only one {0}'.format('Notes') tc = '{0}OnlyOneNotes'.format(global_variables.prefix) - - ref = '{0} {1}.' \ .format(self.pkg_ref, strFunctions.wrap_section('notes', False)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) - 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}) + 'lib_sev': lib_sev, 'short': short, 'lib_ref': self.lib_ref}) From bebe43f916558d1e8e0e5d35cf78cd5892a3ac58 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 24 Jul 2023 10:18:43 +0100 Subject: [PATCH 28/37] other library validation should be complete --- deviser/code_files/ValidationFiles.py | 29 +- deviser/pytest_files/functions.py | 2 + .../test-code/tsb/TSBErrorTable.h | 347 +++++------------- 3 files changed, 130 insertions(+), 248 deletions(-) diff --git a/deviser/code_files/ValidationFiles.py b/deviser/code_files/ValidationFiles.py index 11fb66a4..60b63859 100644 --- a/deviser/code_files/ValidationFiles.py +++ b/deviser/code_files/ValidationFiles.py @@ -454,6 +454,8 @@ def replace_name(self, i, text_string, length): # we dont want to lower the s of SBase # or name if it starts with the prefix for the language isSBase = False + is_language_prefix = False + num_letters = 0 while in_name and i < length: letter = text_string[i] if i != length-1: @@ -461,12 +463,21 @@ def replace_name(self, i, text_string, length): else: next_letter = ' ' if letter == '\\': - isSBase = self.is_sbase(text_string, i, next_letter) + if global_variables.is_sbml: + isSBase = self.is_sbase(text_string, i, next_letter) + else: + [is_language_prefix, num_letters] = self.is_language_prefix(text_string, i, next_letter) if isSBase: return_name_rep += '\'S' + i += 1 + elif is_language_prefix: + return_name_rep += '<' + for j in range(0, num_letters): + return_name_rep += '{0}'.format(text_string[i + j + 1].upper()) + i += num_letters else: return_name_rep += '<{0}'.format(next_letter.lower()) - i += 1 + i += 1 elif next_letter == ' ' or next_letter == '.': if isSBase: return_name_rep += '{0}\''.format(letter) @@ -479,7 +490,19 @@ def replace_name(self, i, text_string, length): continue return [i-1, return_name_rep] - def is_sbase(self, text, index, next_letter): + def is_language_prefix(self, text, index, next_letter): + prefix = global_variables.language.upper() + if not prefix.startswith(next_letter): + return [False, 0] + length_prefix = len(prefix) + match = True + for i in range(0, length_prefix): + if prefix[i] != text[index + i + 1]: + match = False + return [match, length_prefix] + + @staticmethod + def is_sbase(text, index, next_letter): if len(text) < index + 7: return False if next_letter == 'S' or next_letter == 's': diff --git a/deviser/pytest_files/functions.py b/deviser/pytest_files/functions.py index bcc4440a..27e7ff1e 100644 --- a/deviser/pytest_files/functions.py +++ b/deviser/pytest_files/functions.py @@ -82,6 +82,8 @@ def compare_files(infile, outfile, fails, not_tested): :returns: 0 on success, or file not present; 1 on failure. """ ret = 0 + if infile.endswith('ErrorTable.cpp'): + return 0 if not os.path.isfile(infile): # we have not added a file to compare to not_tested.append(infile) diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h b/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h index a84574ef..5516de97 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBErrorTable.h @@ -115,338 +115,195 @@ static const tsbErrorTableEntry tsbErrorTable[] = } }, - //10201 - { - TSBInvalidMathElement, - "Invalid MathML", - LIBTSB_CAT_MATHML_CONSISTENCY, - LIBTSB_SEV_ERROR, - "All MathML content in TSB must appear within a element, and the " - " element must be either explicitly or implicitly in the XML " - "namespace \"http://www.w3.org/1998/Math/MathML\".", - {"" - } - }, - - //10401 - { - TSBMissingTestAnnotationNamespace, - "Missing declaration of the XML namespace for the annotation", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "Every top-level element within an annotation element must " - "have a namespace declared.", - {"" - } - }, - - //10402 - { - TSBDuplicateTestAnnotationNamespaces, - "Multiple annotations using the same XML namespace", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "There cannot be more than one top-level element using a " - "given namespace inside a given annotation element. ", - {"" - } - }, - - //10403 - { - TSBNamespaceInTestAnnotation, - "The TSB XML namespace cannot be used in an TestAnnotation object", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "Top-level elements within an annotation element cannot use any TSB " - "namespace, whether explicitly or implicitly (by failing " - "to declare any namespace).", - {"" - } - }, - - //10404 - { - TSBMultipleTestAnnotations, - "Only one TestAnnotation object is permitted under a given TSB object", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "A given TSB object may contain at most one element.", - {"" - } - }, - - //10801 - { - TSBNotesNotInXHTMLNamespace, - "Notes must be placed in the XHTML XML namespace", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "The contents of the element must be explicitly placed in the " - "XHTML XML namespace.", - {"" - } - }, - - //10802 - { - TSBNotesContainsXMLDecl, - "XML declarations are not permitted in Notes objects", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "The contents of the element must not contain an XML declaration " - "(i.e., a string of the form \"\" " - "or similar).", - {"" - } - }, - - //10803 - { - TSBNotesContainsDOCTYPE, - "XML DOCTYPE elements are not permitted in Notes objects", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "The contents of the element must not contain an XML DOCTYPE " - "declaration (i.e., a string beginning with the characters \" element. ", - {"" - } - }, - - //10805 - { - TSBOnlyOneNotesElementAllowed, - "Only one Notes subobject is permitted on a given TSB object", - LIBTSB_CAT_TSB, - LIBTSB_SEV_ERROR, - "A given TSB object may contain at most one element. ", - {"" - } - }, - /* -------------------------------------------------------------------------- * Boundary marker. TSB specific errors. * ----------------------------------------------------------------------- */ // 10101 - { TsbNSUndeclared, - "The Tsb namespace is not correctly declared.", + { TSBNSUndeclared, + "The TSB namespace is not correctly declared.", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, "To conform to the tsb specification for TSB Level 1 Version 1, an TSB " "document must declare 'http://testsbxml.org/l1v1' as the XMLNamespace to " "use for elements of this package.", - { "L3V1 Tsb V1 Section 3.1" + { "TSB L1V1 Section " } }, // 10102 - { TsbElementNotInNs, - "Element not in Tsb namespace", + { TSBElementNotInNs, + "Element not in TSB namespace", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "Wherever they appear in an SBML document, elements and attributes from the " - "Package must use the " - "'http://www.sbml.org/sbml/level0/version1/tsb/version0' namespace, " - "declaring so either explicitly or implicitly.", - { "L3V1 Tsb V1 Section 3.1" + "Wherever they appear in a TSB document, elements and attributes from the " + "tsb must use the 'http://testsbxml.org/l1v1' namespace, declaring so " + "either explicitly or implicitly.", + { "TSB L1V1 Section " } }, - // 10301 - { TsbDuplicateComponentId, - "Duplicate 'id' attribute value", - LIBTSB_CAT_GENERAL_CONSISTENCY, - LIBTSB_SEV_ERROR, - "(Extends validation rule #10301 in the SBML Level 3 Core specification. TO " - "DO list scope of ids)", - { "L3V1 Tsb V1 Section" - } - }, - - // 10302 - { TsbIdSyntaxRule, - "Invalid SId syntax", - LIBTSB_CAT_GENERAL_CONSISTENCY, - LIBTSB_SEV_ERROR, - "The value of a 'tsb:id' must conform to the syntax of the data type " - "'SId'", - { "L3V1 Tsb V1 Section" - } - }, - - // 10303 + // 10201 { TSBInvalidMetaidSyntax, "Invalid SId syntax", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, "The value of a 'tsb:metaid' must conform to the syntax of the XML Type " "ID", - { "L3V1 Tsb V1 Section" + { "TSB L1V1 Section " } }, - // 20101 - { InvalidNamespaceOnTSB, - "Invalid namespace", + // 10301 + { TSBNoAnnotationNS, + "No ns for TestAnnotation", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "Invalid namespace declared.", - { "L3V1 Tsb V1 Section" + "Every top-level XML element within an object must have an " + "XML namespace declared.", + { "TSB L1V1 Section " } }, - // 20102 - { AllowedAttributes, - "Allowed attributes", + // 10302 + { TSBRepeatAnnotationNS, + "Repeat ns for TestAnnotation", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "Allowed attributes", - { "L3V1 Tsb V1 Section" + "A given XML namespace cannot be the namespace of more than one " + "top-levelelement within a given object.", + { "TSB L1V1 Section " } }, - // 20103 - { TSBEmptyListElement, - "No empty listOf", + // 10303 + { TSBOnlyOneAnnotation, + "Only one TestAnnotation", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "No empty lists", - { "L3V1 Tsb V1 Section" + "A given TSB element may contain at most one subobject.", + { "TSB L1V1 Section " } }, - // 20201 - { TsbDocumentAllowedCoreAttributes, - "Core attributes allowed on .", + // 10401 + { NotesInXHTML, + "Notes not in XHTML", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "A object may have the optional SBML Level 3 Core attributes " - "'metaid' and 'sboTerm'. No other attributes from the SBML Level 3 Core " - "namespaces are permitted on a .", - { "L3V1 Tsb V1 Section" + "The contents of a object must be explicitly placed in the XHTML " + "XML namespace. ", + { "TSB L1V1 Section " } }, - // 20202 - { TsbDocumentAllowedCoreElements, - "Core elements allowed on .", + // 10402 + { XMLDeclNotes, + "No XML decl in Notes", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "A object may have the optional SBML Level 3 Core subobjects for " - "notes and annotations. No other elements from the SBML Level 3 Core " - "namespaces are permitted on a .", - { "L3V1 Tsb V1 Section" + "The contents of a object must not contain an XML declaration, " + "a string of the form '' or + similar.", + { "TSB L1V1 Section " } }, - // 20203 - { TsbDocumentAllowedAttributes, - "Attributes allowed on .", + // 10403 + { DOCTYPEInNotes, + "No DOCTYPE in Notes", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "A object must have the required attributes 'tsb:level' and " - "'tsb:version'. No other attributes from the SBML Level 3 Test SB XML " - "Library namespaces are permitted on a object. ", - { "L3V1 Tsb V1 Section" + "The content of a object must not contain an XML DOCTYPE " + "declaration, a string beginning with the characters '.", + // 10404 + { TSBOnlyOneNotes, + "Only one Notes", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "A object may contain one and only one instance of the " - " element. No other elements from the SBML Level 3 Test SB " - "XML Library namespaces are permitted on a object. ", - { "L3V1 Tsb V1 Section" + "A given TSB element may contain at most one subobject.", + { "TSB L1V1 Section " } }, - // 20205 - { TsbDocumentLevelMustBeNonNegativeInteger, - "The 'level' attribute must be NonNegativeInteger.", + // 20101 + { TSBTSBDocumentAllowedAttributes, + "Attributes allowed on .", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "The attribute 'tsb:level' on a must have a value of data type " - "'integer', and must be non negative.", - { "L3V1 Tsb V1 Section" + "A object must have the required attributes 'tsb:level' and " + "'tsb:version', and may have the optional attribute 'tsb:metaid'. No other " + "attributes from the TSB Level 1 Version 1 namespaces are permitted on a " + " object. ", + { "TSB L1V1 Section " } }, - // 20206 - { TsbDocumentVersionMustBeNonNegativeInteger, - "The 'version' attribute must be NonNegativeInteger.", + // 20102 + { TSBTSBDocumentAllowedElements, + "Elements allowed on .", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "The attribute 'tsb:version' on a must have a value of data type " - "'integer', and must be non negative.", - { "L3V1 Tsb V1 Section" + "Apart from the general and subobjects permitted " + "on all TSB components, A object may contain one and only one " + "instance of the element. No other objects from the TSB " + "Level 1 Version 1 namespaces are permitted on a object. ", + { "TSB L1V1 Section " } }, - // 20207 - { TsbDocumentLOCommentsAllowedCoreElements, - "Core elements allowed on .", + // 20103 + { TSBTSBDocumentLevelMustBeNonNegativeInteger, + "The 'level' attribute must be NonNegativeInteger.", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "Apart from the general notes and annotations subobjects permitted on all " - "SBML objects, a container object may only contain " - " objects.", - { "L3V1 Tsb V1 Section" + "The attribute 'tsb:level' on a must have a value of data " + "type 'integer', and must be non negative.", + { "TSB L1V1 Section " } }, - // 20208 - { TsbDocumentLOCommentsAllowedCoreAttributes, - "Core attributes allowed on .", + // 20104 + { TSBTSBDocumentVersionMustBeNonNegativeInteger, + "The 'version' attribute must be NonNegativeInteger.", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "A object may have the optional SBML Level 3 Core " - "attributes 'metaid' and 'sboTerm'. No other attributes from the SBML Level " - "3 Core namespaces are permitted on a object.", - { "L3V1 Tsb V1 Section" + "The attribute 'tsb:version' on a must have a value of data " + "type 'integer', and must be non negative.", + { "TSB L1V1 Section " } }, - // 20301 - { TsbCommentAllowedCoreAttributes, - "Core attributes allowed on .", + // 20201 + { TSBTSBDocumentLOCommentAllowedCoreElements, + "Core elements allowed on .", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "A object may have the optional SBML Level 3 Core attributes " - "'metaid' and 'sboTerm'. No other attributes from the SBML Level 3 Core " - "namespaces are permitted on a .", - { "L3V1 Tsb V1 Section" + "Apart from the general and subobjects permitted " + "on all TSB objects, a container object may only contain " + " objects.", + { "TSB L1V1 Section " } }, - // 20302 - { TsbCommentAllowedCoreElements, - "Core elements allowed on .", + // 20202 + { TSBTSBDocumentLOCommentsAllowedCoreAttributes, + "Core attributes allowed on .", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, - "A object may have the optional SBML Level 3 Core subobjects for " - "notes and annotations. No other elements from the SBML Level 3 Core " - "namespaces are permitted on a .", - { "L3V1 Tsb V1 Section" + "A object may have the optional attribute 'metaid'. No " + "other attributes from the TSB Level 1 Version 1 namespaces are permitted " + "on a object.", + { "TSB L1V1 Section " } }, // 20301 - { TsbCommentAllowedAttributes, + { TSBCommentAllowedAttributes, "Attributes allowed on .", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, @@ -454,40 +311,40 @@ static const tsbErrorTableEntry tsbErrorTable[] = "'tsb:number', and may have the optional attributes 'tsb:point' and " "'tsb:metaid'. No other attributes from the TSB Level 1 Version 1 " "namespaces are permitted on a object. ", - { "L3V1 Tsb V1 Section" + { "TSB L1V1 Section " } }, // 20302 - { TsbCommentContributorMustBeString, + { TSBCommentContributorMustBeString, "The 'contributor' attribute must be String.", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, "The attribute 'tsb:contributor' on a must have a value of data " "type 'string'.", - { "L3V1 Tsb V1 Section" + { "TSB L1V1 Section " } }, // 20303 - { TsbCommentNumberMustBeDouble, + { TSBCommentNumberMustBeDouble, "The 'number' attribute must be Double.", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, "The attribute 'tsb:number' on a must have a value of data type " "'double'.", - { "L3V1 Tsb V1 Section" + { "TSB L1V1 Section " } }, // 20304 - { TsbCommentPointMustBeString, + { TSBCommentPointMustBeString, "The 'point' attribute must be String.", LIBTSB_CAT_GENERAL_CONSISTENCY, LIBTSB_SEV_ERROR, "The attribute 'tsb:point' on a must have a value of data type " "'string'.", - { "L3V1 Tsb V1 Section" + { "TSB L1V1 Section " } }, From e5488c2e6d461d527348ec34852a932341a842bd Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 24 Jul 2023 10:58:40 +0100 Subject: [PATCH 29/37] all cpp an template files working correctly --- deviser/pytest_files/functions.py | 2 - .../test_other_library/test_other_library.py | 43 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/deviser/pytest_files/functions.py b/deviser/pytest_files/functions.py index 27e7ff1e..bcc4440a 100644 --- a/deviser/pytest_files/functions.py +++ b/deviser/pytest_files/functions.py @@ -82,8 +82,6 @@ def compare_files(infile, outfile, fails, not_tested): :returns: 0 on success, or file not present; 1 on failure. """ ret = 0 - if infile.endswith('ErrorTable.cpp'): - return 0 if not os.path.isfile(infile): # we have not added a file to compare to not_tested.append(infile) diff --git a/deviser/pytest_files/test_other_library/test_other_library.py b/deviser/pytest_files/test_other_library/test_other_library.py index edf9f9b1..5e0a78b2 100644 --- a/deviser/pytest_files/test_other_library/test_other_library.py +++ b/deviser/pytest_files/test_other_library/test_other_library.py @@ -45,30 +45,29 @@ def teardown(): # ('combine-archive', 0, 'CaContent', 'check includes', 'CaListOfContents'), # ('combine-archive', 1, 'CaOmexManifest', 'document', ''), ('testsbxml', 1, 'TSBComment', 'comment class', 'TSBListOfComments'), - ('testsbxml', 0, 'TSBDocument', 'document', ''), - ]) + ('testsbxml', 0, 'TSBDocument', 'document', ''), +]) def test_cpp(name, num, class_name, test_case, list_of): """ - Based on old test_utils.run_templates() function. Run the 'template' file tests. + Based on old test_utils.run_templates() function. Run the 'template' file tests.# :param name: name of test group e.g. 'test_sedml', 'combine-archive'. :param class_name: name of C++ class (and thus .cpp/.h filenames), - e.g. 'SedBase' + e.g. 'SedBase' :param test_case: brief test description, e.g. 'templates'. :param list_of: class name (and thus filenames) of any corresponding - "list of" class, e.g. 'SedListOf' + "list of" class, e.g. 'SedListOf' """ - # gv.reset() - # xml_filename = functions.set_up_test(name, class_name, test_case) - # assert xml_filename is not None and xml_filename != "" - # test_utils.generate_new_cpp_header(xml_filename, num) - # assert 0 == test_utils.compare_code_headers(class_name) - # assert 0 == test_utils.compare_code_impl(class_name) - # if len(list_of) > 0: - # class_name = list_of - # assert 0 == test_utils.compare_code_headers(class_name) - # assert 0 == test_utils.compare_code_impl(class_name) - print('skip') + gv.reset() + xml_filename = functions.set_up_test(name, class_name, test_case) + assert xml_filename is not None and xml_filename != "" + test_utils.generate_new_cpp_header(xml_filename, num) + assert 0 == test_utils.compare_code_headers(class_name) + assert 0 == test_utils.compare_code_impl(class_name) + if len(list_of) > 0: + class_name = list_of + assert 0 == test_utils.compare_code_headers(class_name) + assert 0 == test_utils.compare_code_impl(class_name) @pytest.mark.parametrize('name, class_name, test_case, list_of', [ @@ -76,6 +75,15 @@ def test_cpp(name, num, class_name, test_case, list_of): # ('test_sedml', 'SedBase', 'templates', 'SedListOf'), # ('combine-archive', 'CaBase', 'templates', 'CaListOf'), ('testsbxml', 'TSBBase', 'templates', 'TSBListOf'), + ('testsbxml', 'TSBError', 'templates', ''), + ('testsbxml', 'TSBErrorTable', 'templates', ''), + ('testsbxml', 'TSBErrorLog', 'templates', ''), + ('testsbxml', 'TSBNamespaces', 'templates', ''), + ('testsbxml', 'TSBReader', 'templates', ''), + ('testsbxml', 'TSBVisitor', 'templates', ''), + ('testsbxml', 'TSBTypeCodes', 'templates', ''), + ('testsbxml', 'TSBTypes', 'templates', ''), + ('testsbxml', 'TSBWriter', 'templates', ''), ]) def test_templates(name, class_name, test_case, list_of): """ @@ -93,7 +101,8 @@ def test_templates(name, class_name, test_case, list_of): assert xml_filename is not None and xml_filename != "" test_utils.generate_templates(xml_filename) assert 0 == test_utils.compare_code_headers(class_name) - assert 0 == test_utils.compare_code_impl(class_name) + if not class_name.endswith('ErrorTable') and not class_name.endswith('Types'): + assert 0 == test_utils.compare_code_impl(class_name) assert 0 == test_utils.compare_code_headers(list_of) assert 0 == test_utils.compare_code_impl(list_of) From dbd208d7ccc508b444cfe01ff5f037598d7650ad Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 24 Jul 2023 15:54:16 +0100 Subject: [PATCH 30/37] a tests for common files --- .../tsb/TSBOperationReturnValues.cpp | 197 +++++++++++++++++ .../test-code/tsb/TSBOperationReturnValues.h | 201 ++++++++++++++++++ .../test_other_library/test-code/tsb/common.h | 122 +++++++++++ .../test_other_library/test-code/tsb/extern.h | 120 +++++++++++ .../tsb/libtsb-config-common.h.cmake | 39 ++++ .../test-code/tsb/libtsb-config.h | 54 +++++ .../test-code/tsb/libtsb-namespace.h.cmake | 40 ++++ .../test-code/tsb/libtsb-version.cpp | 71 +++++++ .../test-code/tsb/libtsb-version.h.cmake | 83 ++++++++ .../test_other_library/test-code/tsb/tsbfwd.h | 87 ++++++++ 10 files changed, 1014 insertions(+) create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.cpp create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.h create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/common.h create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/extern.h create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config-common.h.cmake create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config.h create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/libtsb-namespace.h.cmake create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.cpp create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.h.cmake create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.cpp b/deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.cpp new file mode 100644 index 00000000..1dba608b --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.cpp @@ -0,0 +1,197 @@ +/** + * @file TSBOperationReturnValues.cpp + * @brief Implementation of the TSBOperationReturnValues class. + * @author DEVISER + * + * + */ + + + +#include +#include + +LIBTSB_CPP_NAMESPACE_BEGIN + +static TSBOperationReturnValues_t TSB_OPERATION_RETURN_VALUES_INDICES[] = +{ + LIBTSB_OPERATION_SUCCESS + , LIBTSB_INDEX_EXCEEDS_SIZE + , LIBTSB_UNEXPECTED_ATTRIBUTE + , LIBTSB_OPERATION_FAILED + , LIBTSB_INVALID_ATTRIBUTE_VALUE + , LIBTSB_INVALID_OBJECT + , LIBTSB_DUPLICATE_OBJECT_ID + , LIBTSB_LEVEL_MISMATCH + , LIBTSB_VERSION_MISMATCH + , LIBTSB_INVALID_XML_OPERATION + , LIBTSB_NAMESPACES_MISMATCH + , LIBTSB_DUPLICATE_ANNOTATION_NS + , LIBTSB_ANNOTATION_NAME_NOT_FOUND + , LIBTSB_ANNOTATION_NS_NOT_FOUND + , LIBTSB_MISSING_METAID + , LIBTSB_DEPRECATED_ATTRIBUTE +}; + +static const char* TSB_OPERATION_RETURN_VALUES_STRINGS[] = +{ + /* LIBTSB_OPERATION_SUCCESS = 0 */ + "The operation was successful. " + , /*LIBTSB_INDEX_EXCEEDS_SIZE = -1 */ + "An index parameter exceeded the bounds of a data array or other " + "collection used in the operation. This return value is typically " + "returned by methods that take index numbers to refer to lists " + "of objects, when the caller has provided an index that exceeds " + "the bounds of the list. LibTSB provides methods for checking the " + "size of list/sequence/collection structures, and callers should " + "verify the sizes before calling methods that take index numbers. " + + , /*LIBTSB_UNEXPECTED_ATTRIBUTE = -2*/ + "The attribute that is the subject of this operation is not valid " + "for the combination of TSB Level and Version for the underlying " + "object. This can happen because libTSB strives to offer a uniform " + "API for all TSB Levels and Versions, but some object attributes and " + "elements are not defined for all TSB Levels and Versions. Calling " + "programs are expected to be aware of which object structures they " + "are working with, but when errors of this kind occur, they are " + "reported using this return value. " + + , /*LIBTSB_OPERATION_FAILED = -3*/ + "The requested action could not be performed. This can occur in " + "a variety of contexts, such as passing a null object as a parameter " + "in a situation where it does not make sense to permit a null object. " + " " + + , /*LIBTSB_INVALID_ATTRIBUTE_VALUE = -4*/ + "A value passed as an argument to the method is not of a type that " + "is valid for the operation or kind of object involved. For example, " + "this return code is used when a calling program attempts to set an " + "TSB object identifier to a string whose syntax does not conform to " + "the TSB identifier syntax. " + + , /*LIBTSB_INVALID_OBJECT = -5*/ + "The object passed as an argument to the method is not of a type " + "that is valid for the operation or kind of object involved. For " + "example, handing an invalidly-constructed ASTNode to a method " + "expecting an ASTNode will result in this error. " + + , /*LIBTSB_DUPLICATE_OBJECT_ID = -6*/ + "There already exists an object with this identifier in the " + "context where this operation is being attempted. This error is " + "typically returned in situations where TSB object identifiers must be " + "unique, such as attempting to add two species with the same identifier " + "to a model. " + + , /*LIBTSB_LEVEL_MISMATCH = -7*/ + "The TSB Level associated with the object does not match the Level " + "of the parent object. This error can happen when an TSB component " + "such as a species or compartment object is created outside of a model " + "and a calling program then attempts to add the object to a model that " + "has a different TSB Level defined. " + + , /*LIBTSB_VERSION_MISMATCH = -8*/ + "The TSB Version within the TSB Level associated with the object " + "does not match the Version of the parent object. This error can " + "happen when an TSB component such as a species or compartment object " + "is created outside of a model and a calling program then attempts to " + "add the object to a model that has a different TSB Level+Version " + "combination. " + + , /*LIBTSB_INVALID_XML_OPERATION = -9*/ + "The XML operation attempted is not valid for the object or context " + "involved. This error is typically returned by the XML interface layer " + "of libTSB, when a calling program attempts to construct or manipulate " + "XML in an invalid way. " + + , /*LIBTSB_NAMESPACES_MISMATCH = -10*/ + "The TSB Namespaces associated with the object " + "do not match the TSB Namespaces of the parent object. This error can " + "happen when an TSB component such as a species or compartment object " + "is created outside of a model and a calling program then attempts to " + "add the object to a model that has a different TSB Namespaces " + "combination. " + + , /*LIBTSB_DUPLICATE_ANNOTATION_NS = -11*/ + "There already exists a top level annotation with the same namespace as " + "annotation being appended. This error is " + "typically returned in situations where the appendTestAnnotation function " + "is being used to add an annotation that has a namespace that is already " + "present in the existing annotation. " + + , /*LIBTSB_ANNOTATION_NAME_NOT_FOUND = -12*/ + "The existing annotation does not have a top-level element with " + "the given name. This error is " + "typically returned in situations where the " + "replaceTopLevelTestAnnotationElement function or " + "the removeTopLevelTestAnnotationElement function " + "is being used to replace or remove an annotation with a name that does " + "not match the name of any top-level element that is already " + "present in the existing annotation. " + + , /*LIBTSB_ANNOTATION_NS_NOT_FOUND = -13*/ + "The existing annotation does not have a top-level element with " + "the given namespace. This error is " + "typically returned in situations where the " + "replaceTopLevelTestAnnotationElement function or " + "the removeTopLevelTestAnnotationElement function " + "is being used to replace or remove an annotation with a namespace that does " + "not match the namespace of any top-level element that is already " + "present in the existing annotation. " + + , /* LIBTSB_MISSING_METAID = -14*/ + "The requested action cannot be performed as the target object does not have " + "the metaid attribute set. " + + , /* LIBTSB_DEPRECATED_ATTRIBUTE = -15*/ + "The attribute that is the subject of this operation has been deprecated " + "for the combination of TSB Level and Version for the underlying " + "object. " + +}; + +LIBTSB_EXTERN +const char * +TSBOperationReturnValue_toString (int returnValue) +{ + int length = sizeof(TSB_OPERATION_RETURN_VALUES_INDICES)/sizeof(TSBOperationReturnValues_t); + for (int i = 0; i < length; ++i) + { + if (TSB_OPERATION_RETURN_VALUES_INDICES[i] == returnValue) + return TSB_OPERATION_RETURN_VALUES_STRINGS[i]; + } + + return NULL; +} + + +LIBTSB_CPP_NAMESPACE_END + diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.h b/deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.h new file mode 100644 index 00000000..4a1d748c --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/TSBOperationReturnValues.h @@ -0,0 +1,201 @@ +/** + * @file TSBOperationReturnValues.h + * @brief Definition of the TSBOperationReturnValues class. + * @author DEVISER + * + * + * + * @class TSBOperationReturnValues + * @sbmlbrief{} TODO:Definition of the TSBOperationReturnValues class. + */ + + + +#ifndef LIBTSB_OPERATION_RETURN_VALUES_H +#define LIBTSB_OPERATION_RETURN_VALUES_H + +#include +#include + + +LIBTSB_CPP_NAMESPACE_BEGIN + +BEGIN_C_DECLS + +/** + * @enum OperationReturnValues_t + * LibTSB diagnostic return codes. + * + * Many methods in libTSB return a status code to indicate whether the + * operation requested by the caller succeeded or failed. This enumeration + * lists all the possible return codes from any libTSB methods. + */ +typedef enum +{ + LIBTSB_OPERATION_SUCCESS = 0 + /*!< The operation was successful. */ + + , LIBTSB_INDEX_EXCEEDS_SIZE = -1 + /*!< An index parameter exceeded the bounds of a data array or other + * collection used in the operation. This return value is typically + * returned by methods that take index numbers to refer to lists + * of objects, when the caller has provided an index that exceeds + * the bounds of the list. LibTSB provides methods for checking the + * size of list/sequence/collection structures, and callers should + * verify the sizes before calling methods that take index numbers. */ + + , LIBTSB_UNEXPECTED_ATTRIBUTE = -2 + /*!< The attribute that is the subject of this operation is not valid + * for the combination of TSB Level and Version for the underlying + * object. This can happen because libTSB strives to offer a uniform + * API for all TSB Levels and Versions, but some object attributes and + * elements are not defined for all TSB Levels and Versions. Calling + * programs are expected to be aware of which object structures they + * are working with, but when errors of this kind occur, they are + * reported using this return value. */ + + , LIBTSB_OPERATION_FAILED = -3 + /*!< The requested action could not be performed. This can occur in + * a variety of contexts, such as passing a null object as a parameter + * in a situation where it does not make sense to permit a null object. + */ + + , LIBTSB_INVALID_ATTRIBUTE_VALUE = -4 + /*!< A value passed as an argument to the method is not of a type that + * is valid for the operation or kind of object involved. For example, + * this return code is used when a calling program attempts to set an + * TSB object identifier to a string whose syntax does not conform to + * the TSB identifier syntax. */ + + , LIBTSB_INVALID_OBJECT = -5 + /*!< The object passed as an argument to the method is not of a type + * that is valid for the operation or kind of object involved. For + * example, handing an invalidly-constructed ASTNode to a method + * expecting an ASTNode will result in this error. */ + + , LIBTSB_DUPLICATE_OBJECT_ID = -6 + /*!< There already exists an object with this identifier in the + * context where this operation is being attempted. This error is + * typically returned in situations where TSB object identifiers must be + * unique, such as attempting to add two species with the same identifier + * to a model. */ + + , LIBTSB_LEVEL_MISMATCH = -7 + /*!< The TSB Level associated with the object does not match the Level + * of the parent object. This error can happen when an TSB component + * such as a species or compartment object is created outside of a model + * and a calling program then attempts to add the object to a model that + * has a different TSB Level defined. */ + + , LIBTSB_VERSION_MISMATCH = -8 + /*!< The TSB Version within the TSB Level associated with the object + * does not match the Version of the parent object. This error can + * happen when an TSB component such as a species or compartment object + * is created outside of a model and a calling program then attempts to + * add the object to a model that has a different TSB Level+Version + * combination. */ + + , LIBTSB_INVALID_XML_OPERATION = -9 + /*!< The XML operation attempted is not valid for the object or context + * involved. This error is typically returned by the XML interface layer + * of libTSB, when a calling program attempts to construct or manipulate + * XML in an invalid way. */ + + , LIBTSB_NAMESPACES_MISMATCH = -10 + /*!< The TSB Namespaces associated with the object + * do not match the TSB Namespaces of the parent object. This error can + * happen when an TSB component such as a species or compartment object + * is created outside of a model and a calling program then attempts to + * add the object to a model that has a different TSB Namespaces + * combination. */ + + , LIBTSB_DUPLICATE_ANNOTATION_NS = -11 + /*!< There already exists a top level annotation with the same namespace as + * annotation being appended. This error is + * typically returned in situations where the appendAnnotation function + * is being used to add an annotation that has a namespace that is already + * present in the existing annotation. */ + + , LIBTSB_ANNOTATION_NAME_NOT_FOUND = -12 + /*!< The existing annotation does not have a top-level element with + * the given name. This error is + * typically returned in situations where the + * replaceTopLevelAnnotationElement function or + * the removeTopLevelAnnotationElement function + * is being used to replace or remove an annotation with a name that does + * not match the name of any top-level element that is already + * present in the existing annotation. */ + + , LIBTSB_ANNOTATION_NS_NOT_FOUND = -13 + /*!< The existing annotation does not have a top-level element with + * the given namespace. This error is + * typically returned in situations where the + * replaceTopLevelAnnotationElement function or + * the removeTopLevelAnnotationElement function + * is being used to replace or remove an annotation with a namespace that does + * not match the namespace of any top-level element that is already + * present in the existing annotation. */ + + , LIBTSB_MISSING_METAID = -14 + /*!< The requested action cannot be performed as the target object does not have + * the metaid attribute set. */ + + , LIBTSB_DEPRECATED_ATTRIBUTE = -15 + /*!< The attribute that is the subject of this operation has been deprecated + * for the combination of TSB Level and Version for the underlying + * object. */ + +} TSBOperationReturnValues_t; + +/** + * This method takes an TSB operation return value and returns a string representing + * the code. + * + * @param returnValue the operation return value to convert to a string + * + * @return a human readable name for the given + * @if clike #OperationReturnValues_t value@else operation return value @endif. + * + * @note The caller does not own the returned string and is therefore not + * allowed to modify it. + */ +LIBTSB_EXTERN +const char * +TSBOperationReturnValue_toString (int returnValue); + +END_C_DECLS + +LIBTSB_CPP_NAMESPACE_END + + +#endif /* LIBTSB_OPERATION_RETURN_VALUES_H */ + diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/common.h b/deviser/pytest_files/test_other_library/test-code/tsb/common.h new file mode 100644 index 00000000..e1c05152 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/common.h @@ -0,0 +1,122 @@ +/** + * @file common.h + * @brief Definition of the common class. + * @author DEVISER + * + * + * + * @class common + * @sbmlbrief{} TODO:Definition of the common class. + */ + + +#ifndef LIBTSB_COMMON_H +#define LIBTSB_COMMON_H 1 + + +#include + + +#include + + +#if STDC_HEADERS +# include +# include +# include +# include +# include +#endif + +#if HAVE_MATH_H +# include +#endif + +#if HAVE_IEEFP_H +# include +#endif + +#ifndef errno + extern int errno; +#endif + + +/** + * Default format used by libTSB when writing out floating-point numbers + * into the XML produced by libTSB. This is used by + * StringBuffer_appendReal. + */ +#define LIBTSB_FLOAT_FORMAT "%.15g" + +#define LIBTSB_DOUBLE_PRECISION 15 + +static const int TSB_INT_MAX = 2147483647; +static const int TSB_INT_MIN = -2147483647 - 1; + +/* + * Sometimes the line/column numbers reported by the underlying parsers are + * simply invalid. This especially occurs in error situations when the + * error is severe. Typically you're not supposed to call the parsers' + * getline()/getcolumn() functions in those situations, but it's hard to + * avoid because of the flow of control in our code. The problem is, in + * some cases, calling the parser's getline()/getcolumn() functions results + * in a segmentation fault. (Case in point: this was happening using + * Xerces 2.8 on 32-bit systems.) We need to communicate that a + * line/column number value is actually invalid or meaningless. + * + * Doing that presents a new problem: our line/column number values are + * unsigned integers, which thus only allows 2 states to be + * communicated. (Explanation: you could use 0 to communicate an invalid + * state and let all other values indicate a valid state. If we had signed + * integers, we could communicate 3 state values, using negative, 0, and + * positive values for the different states.) Unfortunately we can't use 0 + * because that value is already being used to communicate a different + * meaning between users of XMLError objects. + * + * The following is a bit of a hack, but not completely unrealistic: we use + * the largest possible value of the data type used to represent + * line/column numbers. The probability that an error in an file will + * involve these specific numbers is vanishingly small. Thus, we can say + * that if user code encounters these values as line/column numbers, they + * should assume they are actually meaningless and no valid line/column + * number could be provided by the parser. + */ + +#define LIBTSB_UNKNOWN_LINE TSB_INT_MAX +#define LIBTSB_UNKNOWN_COLUMN TSB_INT_MAX + + +#include +#include +#include + +#endif /* LIBTSB_COMMON_H */ diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/extern.h b/deviser/pytest_files/test_other_library/test-code/tsb/extern.h new file mode 100644 index 00000000..e6f9f4f2 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/extern.h @@ -0,0 +1,120 @@ +/** + * @file extern.h + * @brief Definition of the extern class. + * @author DEVISER + * + * + * + * @class extern + * @sbmlbrief{} TODO:Definition of the extern class. + */ + + + +#ifndef LIBTSB_EXTERN_H +#define LIBTSB_EXTERN_H + +#include + +#if ( defined(WIN32) && !defined(CYGWIN) && !defined(__MINGW32__)) + +#if ( ! defined LIBTSB_STATIC ) +/** + * The following ifdef block is the standard way of creating macros which + * make exporting from a DLL simpler. All files within this DLL are + * compiled with the LIBTSB_EXPORTS symbol defined on the command line. + * This symbol should not be defined on any project that uses this + * DLL. This way any other project whose source files include this file see + * LIBTSB_EXTERN functions as being imported from a DLL, wheras this DLL + * sees symbols defined with this macro as being exported. + * + * (From Andrew Finney's sbwdefs.h, with "SBW" replaced by "LIBTSB" :) + */ +#if defined(LIBTSB_EXPORTS) +# define LIBTSB_EXTERN __declspec(dllexport) +#else +# define LIBTSB_EXTERN __declspec(dllimport) +#endif + +#else +# define LIBTSB_EXTERN +#endif /* LIBTSB_STATIC */ + +/** + * Disable MSVC++ warning C4800: 'const int' : forcing value to bool 'true' + * or 'false' (performance warning). + */ +#pragma warning(disable: 4800) + +/** + * Disable MSVC++ warning C4291: no matching operator delete found. + */ +#pragma warning(disable: 4291) + +/** + * Disable MSVC++ warning C4251: class 'type' needs to have dll-interface + * to be used by clients of class 'type2'. + * + * For an explanation of why this is safe, see: + * - http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html + */ +#pragma warning(disable: 4251) +#pragma warning(disable: 4275) + +#else + +/** + * LIBTSB_EXTERN is used under Windows to simplify exporting functions + * from a DLL. When compiling under Windows, all files within this DLL are + * compiled with the LIBTSB_EXPORTS symbol defined on the command line. + * This in turn causes extern.h to define a different version of + * LIBTSB_EXTERN that is appropriate for exporting functions to client + * code that uses the DLL. + */ +#define LIBTSB_EXTERN + +#endif /* WIN32 */ + +#undef BEGIN_C_DECLS +#undef END_C_DECLS + +#if defined(__cplusplus) +# define BEGIN_C_DECLS extern "C" { +# define END_C_DECLS } +#else +# define BEGIN_C_DECLS +# define END_C_DECLS +#endif + + +#endif /** LIBTSB_EXTERN_H **/ + diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config-common.h.cmake b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config-common.h.cmake new file mode 100644 index 00000000..65ccbd3b --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config-common.h.cmake @@ -0,0 +1,39 @@ +/** + * @file libtsb-config-common.h.cmake + * @brief Configuration variables + */ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_CHECK_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_EXPAT_H 1 + +/* Define to 1 to use the Expat XML library */ +#cmakedefine USE_EXPAT + + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_IEEEFP_H 1 + +/* Define to 1 if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MATH_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the `m' library (-lm). */ +#cmakedefine HAVE_LIBM 1 + +/* Define to 1 to enable primitive memory tracing. */ +#cmakedefine TRACE_MEMORY + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +#cmakedefine WORDS_BIGENDIAN 1 diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config.h b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config.h new file mode 100644 index 00000000..ceee9e39 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-config.h @@ -0,0 +1,54 @@ +/** + * @file libtsb-config.h + * @brief Definition of the libtsb-config class. + * @author DEVISER + * + * + * + * @class libtsb-config + * @sbmlbrief{} TODO:Definition of the libtsb-config class. + */ + + + +#ifndef LIBTSB_CONFIG_H +#define LIBTSB_CONFIG_H 1 + +#include + +#include + +#include + + +#endif /* LIBTSB_CONFIG_H */ + diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-namespace.h.cmake b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-namespace.h.cmake new file mode 100644 index 00000000..8575bd23 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-namespace.h.cmake @@ -0,0 +1,40 @@ +/** + * @file libtsb-namespace.h + * @brief Defines C++ namespace of libTSB + */ + + +#ifndef LIBTSB_NAMESPACE_H +#define LIBTSB_NAMESPACE_H 1 + +/* + * + * The idea of the following marcors are borrowed from + * Xerces-C++ XML Parser (http://xerces.apache.org/xerces-c/). + * + */ + +/* Define to enable libTSB C++ namespace */ +#cmakedefine LIBTSB_USE_CPP_NAMESPACE 1 + + +#if defined(__cplusplus) && defined(LIBTSB_USE_CPP_NAMESPACE) && !defined(SWIG) + /* C++ namespace of libTSB */ + #define LIBTSB_CPP_NAMESPACE libtsb + #define LIBTSB_CPP_NAMESPACE_BEGIN namespace LIBTSB_CPP_NAMESPACE { + #define LIBTSB_CPP_NAMESPACE_END } + #define LIBTSB_CPP_NAMESPACE_USE using namespace LIBTSB_CPP_NAMESPACE; + #define LIBTSB_CPP_NAMESPACE_QUALIFIER LIBTSB_CPP_NAMESPACE:: + + namespace LIBTSB_CPP_NAMESPACE {} +#else + #define LIBTSB_CPP_NAMESPACE + #define LIBTSB_CPP_NAMESPACE_BEGIN + #define LIBTSB_CPP_NAMESPACE_END + #define LIBTSB_CPP_NAMESPACE_USE + #define LIBTSB_CPP_NAMESPACE_QUALIFIER +#endif + + +#endif /* LIBTSB_NAMESPACE_H */ + diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.cpp b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.cpp new file mode 100644 index 00000000..6f94e549 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.cpp @@ -0,0 +1,71 @@ +/** + * @file libtsb-version.cpp + * @brief Implementation of the libtsb-version class. + * @author DEVISER + * + * + */ + + + +#include "tsb/common/libtsb-version.h" +#include + + +LIBTSB_CPP_NAMESPACE_BEGIN + +LIBTSB_EXTERN +int +getLibTSBVersion() +{ + return LIBTSB_VERSION; +} + + +LIBTSB_EXTERN +const char* +getLibTSBDottedVersion() +{ + return LIBTSB_DOTTED_VERSION; +} + + +LIBTSB_EXTERN +const char* +getLibTSBVersionString() +{ + return LIBTSB_VERSION_STRING; +} + +LIBTSB_CPP_NAMESPACE_END + + diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.h.cmake b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.h.cmake new file mode 100644 index 00000000..89456fc3 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/libtsb-version.h.cmake @@ -0,0 +1,83 @@ +/** + * @file libtsb-version.h + * @brief Define libTSB version numbers for access from client software. + * + */ + + +#ifndef LIBTSB_VERSION_H +#define LIBTSB_VERSION_H + +#include + + +/** + * LIBTSB_DOTTED_VERSION: + * + * A version string of the form "1.2.3". + */ +#define LIBTSB_DOTTED_VERSION "@PACKAGE_VERSION@" + + +/** + * LIBTSB_VERSION: + * + * The version as an integer: version 1.2.3 becomes 10203. Since the major + * number comes first, the overall number will always increase when a new + * libTSB is released, making it easy to use less-than and greater-than + * comparisons when testing versions numbers. + */ +#define LIBTSB_VERSION @LIBTSB_VERSION_NUMERIC@ + + +/** + * LIBTSB_VERSION_STRING: + * + * The numeric version as a string: version 1.2.3 becomes "10203". + */ +#define LIBTSB_VERSION_STRING "@LIBTSB_VERSION_NUMERIC@" + + +LIBTSB_CPP_NAMESPACE_BEGIN +BEGIN_C_DECLS + +/** + * Returns the version number of this copy of libTSB as an integer. + * + * @return the libTSB version as an integer; version 1.2.3 becomes 10203. + */ +LIBTSB_EXTERN +int +getLibTSBVersion(); + + +/** + * Returns the version number of this copy of libTSB as a string. + * + * @return the libTSB version as a string; version 1.2.3 becomes + * "1.2.3". + * + * @see getLibTSBVersionString() + */ +LIBTSB_EXTERN +const char* +getLibTSBDottedVersion(); + + +/** + * Returns the version number of this copy of libTSB as a string without + * periods. + * + * @return the libTSB version as a string: version 1.2.3 becomes "10203". + * + * @see getLibTSBDottedVersion() + */ +LIBTSB_EXTERN +const char* +getLibTSBVersionString(); + + +END_C_DECLS +LIBTSB_CPP_NAMESPACE_END + +#endif /* LIBTSB_VERSION_H */ diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h b/deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h new file mode 100644 index 00000000..076a438d --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h @@ -0,0 +1,87 @@ +/** + * @file tsbfwd.h + * @brief Definition of tsbfwd. + * @author DEVISER + * + * + */ + + +#ifndef tsbfwd_H__ +#define tsbfwd_H__ + + +#include + +/** + * Forward declaration of all opaque C types. + * + * Declaring all types up-front avoids "redefinition of type Foo" compile + * errors and allows our combined C/C++ headers to depend minimally upon each + * other. Put another way, the type definitions below serve the same purpose as + * "class Foo;" forward declarations in C++ code. + */ + +#ifdef __cplusplus +# define CLASS_OR_STRUCT class +#else +# define CLASS_OR_STRUCT struct +#endif /* __cplusplus */ + + +LIBTSB_CPP_NAMESPACE_BEGIN + + +typedef CLASS_OR_STRUCT TSBDocument TSBDocument_t; +typedef CLASS_OR_STRUCT TSBComment TSBComment_t; +typedef CLASS_OR_STRUCT TSBBase TSBBase_t; +typedef CLASS_OR_STRUCT TSBListOf TSBListOf_t; +typedef CLASS_OR_STRUCT TSBReader TSBReader_t; +typedef CLASS_OR_STRUCT TSBWriter TSBWriter_t; +typedef CLASS_OR_STRUCT TSBNamespaces TSBNamespaces_t; +typedef CLASS_OR_STRUCT TSBError TSBError_t; +typedef CLASS_OR_STRUCT List List_t; +typedef CLASS_OR_STRUCT ListNode ListNode_t; +typedef CLASS_OR_STRUCT ExpectedAttributes ExpectedAttributes_t; + + + +LIBTSB_CPP_NAMESPACE_END + + + +#undef CLASS_OR_STRUCT + + +#endif /* !tsbfwd_H__ */ + + From 19243ab9abd88f579abafe0aef57887ad91f0474 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 25 Jul 2023 09:11:32 +0100 Subject: [PATCH 31/37] common files sorted --- deviser/code_files/templates/common.h | 11 ++++------- deviser/code_files/templates/lib-namespace.h.cmake | 8 -------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/deviser/code_files/templates/common.h b/deviser/code_files/templates/common.h index c3118b46..9ffe50d8 100644 --- a/deviser/code_files/templates/common.h +++ b/deviser/code_files/templates/common.h @@ -2,7 +2,7 @@ #define LIBSBML_COMMON_H 1 -#include +#include #include @@ -74,11 +74,8 @@ static const int SBML_INT_MIN = -2147483647 - 1; #define LIBSBML_UNKNOWN_COLUMN SBML_INT_MAX -#include - -#include -#include - -#include +#include +#include +#include #endif /* LIBSBML_COMMON_H */ diff --git a/deviser/code_files/templates/lib-namespace.h.cmake b/deviser/code_files/templates/lib-namespace.h.cmake index f1bb23ff..ff79fd4f 100644 --- a/deviser/code_files/templates/lib-namespace.h.cmake +++ b/deviser/code_files/templates/lib-namespace.h.cmake @@ -7,14 +7,6 @@ #ifndef LIBSBML_NAMESPACE_H #define LIBSBML_NAMESPACE_H 1 - -#ifndef SWIG -#include - -LIBSBML_CPP_NAMESPACE_USE - -#endif - /* * * The idea of the following marcors are borrowed from From c895ef98adb3c92b945994d7365bc6f8f5f0f540 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 25 Jul 2023 09:15:06 +0100 Subject: [PATCH 32/37] tests running so far --- .../test_other_library/test_other_library.py | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/deviser/pytest_files/test_other_library/test_other_library.py b/deviser/pytest_files/test_other_library/test_other_library.py index 5e0a78b2..f85d1dd8 100644 --- a/deviser/pytest_files/test_other_library/test_other_library.py +++ b/deviser/pytest_files/test_other_library/test_other_library.py @@ -107,37 +107,37 @@ def test_templates(name, class_name, test_case, list_of): assert 0 == test_utils.compare_code_impl(list_of) -# @pytest.mark.parametrize('name, class_name, test_case, prefix, lib', [ +@pytest.mark.parametrize('name, class_name, test_case, prefix, lib', [ # ('test_sedml', 'SedBase', 'common', 'Sed', 'sedml'), # ('combine-archive', 'CaBase', 'common', 'Ca', 'combine'), -# # ('testsbxml', 'TSBBase', 'common', 'TSB', 'libTSB'), -# ]) -# def test_common_templates(name, class_name, test_case, prefix, lib): -# """ -# Based on test_utils.test_common_templates() function. -# Compare 'common' template files. -# -# :param name: e.g. 'test_sedml' -# :param class_name: C++ class/filenames, e.g. 'SedBase' -# :param test_case: e.g. 'common' -# :param prefix: e.g. 'Sed' -# :param lib: used for comparing lib files, e.g. 'sedml' for 'libsedml-*'. -# :return: number of failed tests. -# """ -# gv.reset() -# xml_filename = functions.set_up_test(name, class_name, test_case) -# test_utils.generate_common_templates(xml_filename) -# assert 0 == test_utils.compare_code_headers('common') -# assert 0 == test_utils.compare_code_headers('extern') -# assert 0 == test_utils.compare_code_headers('lib{0}-config'.format(lib)) -# assert 0 == test_utils.compare_code_impl('lib{0}-version'.format(lib)) -# assert 0 == test_utils.compare_code_headers('{0}OperationReturnValues'. -# format(prefix)) -# assert 0 == test_utils.compare_code_impl('{0}OperationReturnValues'. -# format(prefix)) -# assert 0 == test_utils.compare_code_cmake('lib{0}-version.h'.format(lib)) -# assert 0 == test_utils.compare_code_cmake('lib{0}-config-common.h'.format(lib)) -# assert 0 == test_utils.compare_code_cmake('lib{0}-namespace.h'.format(lib)) + ('testsbxml', 'TSBBase', 'common', 'TSB', 'tsb'), +]) +def test_common_templates(name, class_name, test_case, prefix, lib): + """ + Based on test_utils.test_common_templates() function. + Compare 'common' template files. + + :param name: e.g. 'test_sedml' + :param class_name: C++ class/filenames, e.g. 'SedBase' + :param test_case: e.g. 'common' + :param prefix: e.g. 'Sed' + :param lib: used for comparing lib files, e.g. 'sedml' for 'libsedml-*'. + :return: number of failed tests. + """ + gv.reset() + xml_filename = functions.set_up_test(name, class_name, test_case) + test_utils.generate_common_templates(xml_filename) + assert 0 == test_utils.compare_code_headers('common') + assert 0 == test_utils.compare_code_headers('extern') + assert 0 == test_utils.compare_code_headers('lib{0}-config'.format(lib)) + assert 0 == test_utils.compare_code_impl('lib{0}-version'.format(lib)) + assert 0 == test_utils.compare_code_headers('{0}OperationReturnValues'. + format(prefix)) + assert 0 == test_utils.compare_code_impl('{0}OperationReturnValues'. + format(prefix)) + assert 0 == test_utils.compare_code_cmake('lib{0}-version.h'.format(lib)) + assert 0 == test_utils.compare_code_cmake('lib{0}-config-common.h'.format(lib)) + assert 0 == test_utils.compare_code_cmake('lib{0}-namespace.h'.format(lib)) # # # @pytest.mark.parametrize('name, class_name, test_case', [ @@ -204,28 +204,28 @@ def test_templates(name, class_name, test_case, list_of): # binding, "") # # -# @pytest.mark.parametrize('name, class_name', [ +@pytest.mark.parametrize('name, class_name', [ # # ('test_sedml', 'libsedml'), # ('combine-archive', 'libcombine'), -# ('testsbxml', 'libTSB') -# ]) -# def test_cmake(name, class_name): -# """ -# Based on old test_cmake() function in run_other_library_tests.py -# Generate and compare CMake files. -# -# TODO the following need more details: -# -# :param name: name of test, e.g. 'test_sedml' or 'combine-archive'. -# :param class_name: e.g. 'libsedml' or 'libcombine' -# """ -# gv.reset() -# xml_filename = functions.set_up_test(name, class_name, "cmake") -# test_utils.generate_cmake(xml_filename, "cmake") -# assert 0 == test_utils.compare_cmake_file('') -# assert 0 == test_utils.compare_cmake_file('src') -# assert 0 == test_utils.compare_cmake_file('src/bindings') -# assert 0 == test_utils.compare_cmake_file('src/{0}'.format(gv.language)) + ('testsbxml', 'libTSB') +]) +def test_cmake(name, class_name): + """ + Based on old test_cmake() function in run_other_library_tests.py + Generate and compare CMake files. + + TODO the following need more details: + + :param name: name of test, e.g. 'test_sedml' or 'combine-archive'. + :param class_name: e.g. 'libsedml' or 'libcombine' + """ + gv.reset() + xml_filename = functions.set_up_test(name, class_name, "cmake") + test_utils.generate_cmake(xml_filename, "cmake") + assert 0 == test_utils.compare_cmake_file('') + assert 0 == test_utils.compare_cmake_file('src') + assert 0 == test_utils.compare_cmake_file('src/bindings') + assert 0 == test_utils.compare_cmake_file('src/{0}'.format(gv.language)) # # # @pytest.mark.parametrize('name, class_name, test_case', [ From 52495e35d76a37649a172433150e3c31e206e513 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 25 Jul 2023 11:14:44 +0100 Subject: [PATCH 33/37] add global tests --- .../test-code/tsb/README.md | 33 +++++++++++++++ .../test-code/tsb/VERSION.txt | 2 + .../test_other_library/test_other_library.py | 40 +++++++++---------- 3 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/README.md create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/VERSION.txt diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/README.md b/deviser/pytest_files/test_other_library/test-code/tsb/README.md new file mode 100644 index 00000000..289da4e4 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/README.md @@ -0,0 +1,33 @@ +# LibTSB + +## Dependencies +This library requires either liblx or libSBML to be present, as its XML parsing layer will be used. For that either expat, xerces-c or libXML2 needs to be available. + +## Building +This library uses [CMake](http://cmake.org) to build the library, so from an initial checkout all you would need todo is to run: + + + mkdir build + cd build + cmake -DLIBSBML_LIBRARY=< path to libsbml lib> -DLIBSBML_INCLUDE_DIR=< path to includes > ... -DEXTRA_LIBS= < comma separated list of xml libraries> + make + make install + + mkdir build + cd build + cmake -DLIBSBML_LIBRARY=< path to libsbml lib> -DLIBSBML_INCLUDE_DIR=< path to includes > ... -DEXTRA_LIBS= < comma separated list of xml libraries> + make + make install + +Should libSBML be installed in a default location it will be found automatically. Note that you do need to list the xml libraries that libSBML was linked against. In most cases libSBML is compiled against libXML and have compression enabled, so your `EXTRA_LIBS` would be: + + EXTRA_LIBS=xml2;bz2;z;iconv + +note the semicolon denoting the listing of several libraries. Of course you could also enter the full path to each individual file, just to give an example, on windows I use: + + EXTRA_LIBS=D:/dependencies/lib/expat.lib + +for linking against `expat` and indicating, that libSBML was compiled without compression. + +## License +This project is open source and freely available under \ No newline at end of file diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/VERSION.txt b/deviser/pytest_files/test_other_library/test-code/tsb/VERSION.txt new file mode 100644 index 00000000..332145cb --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/VERSION.txt @@ -0,0 +1,2 @@ +1.0.0 + diff --git a/deviser/pytest_files/test_other_library/test_other_library.py b/deviser/pytest_files/test_other_library/test_other_library.py index f85d1dd8..0d1dcd8b 100644 --- a/deviser/pytest_files/test_other_library/test_other_library.py +++ b/deviser/pytest_files/test_other_library/test_other_library.py @@ -226,26 +226,26 @@ def test_cmake(name, class_name): assert 0 == test_utils.compare_cmake_file('src') assert 0 == test_utils.compare_cmake_file('src/bindings') assert 0 == test_utils.compare_cmake_file('src/{0}'.format(gv.language)) -# -# -# @pytest.mark.parametrize('name, class_name, test_case', [ -# ('test_sedml', 'libsedml', 'global files'), -# ]) -# def test_global(name, class_name, test_case): -# """ -# Based on old test_utils.test_global() function. -# Generate and compare 'global' files, e.g. VERSION.txt, README.md. -# -# :param name: test file stub, e.g. 'test_sedml' for test_sedml.xml -# :param class_name: test class e.g. 'libsedml' -# :param test_case: brief description of test, e.g. 'global files' -# """ -# xml_filename = functions.set_up_test(name, class_name, test_case) -# test_utils.generate_global(xml_filename) -# assert 0 == test_utils.compare_code_txt('VERSION') -# assert 0 == test_utils.compare_code_txt('README', '.md') -# -# + + +@pytest.mark.parametrize('name, class_name, test_case', [ + ('testsbxml', 'libTSB', 'global files'), +]) +def test_global(name, class_name, test_case): + """ + Based on old test_utils.test_global() function. + Generate and compare 'global' files, e.g. VERSION.txt, README.md. + + :param name: test file stub, e.g. 'test_sedml' for test_sedml.xml + :param class_name: test class e.g. 'libsedml' + :param test_case: brief description of test, e.g. 'global files' + """ + xml_filename = functions.set_up_test(name, class_name, test_case) + test_utils.generate_global(xml_filename) + assert 0 == test_utils.compare_code_txt('VERSION') + assert 0 == test_utils.compare_code_txt('README', '.md') + + # @pytest.mark.parametrize('name, class_name, test_case', [ # ('test_sedml', 'sedmlfwd', 'forward declarations'), # ]) From cb1d91e90eae12b898225190b6f991d24c6a20c1 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 25 Jul 2023 12:55:07 +0100 Subject: [PATCH 34/37] Sort common files --- .../test-code/tsb/LICENSE.txt | 2 ++ .../test-code/tsb/README.md | 13 +++++++++---- deviser/util/templates/README.md | 19 +++++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 deviser/pytest_files/test_other_library/test-code/tsb/LICENSE.txt diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/LICENSE.txt b/deviser/pytest_files/test_other_library/test-code/tsb/LICENSE.txt new file mode 100644 index 00000000..b2398099 --- /dev/null +++ b/deviser/pytest_files/test_other_library/test-code/tsb/LICENSE.txt @@ -0,0 +1,2 @@ +LICENSE + diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/README.md b/deviser/pytest_files/test_other_library/test-code/tsb/README.md index 289da4e4..883843cc 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/README.md +++ b/deviser/pytest_files/test_other_library/test-code/tsb/README.md @@ -4,7 +4,7 @@ This library requires either liblx or libSBML to be present, as its XML parsing layer will be used. For that either expat, xerces-c or libXML2 needs to be available. ## Building -This library uses [CMake](http://cmake.org) to build the library, so from an initial checkout all you would need todo is to run: +This library uses [CMake](http://cmake.org) to build the library, so from an initial checkout all you would need to do is to run: mkdir build @@ -13,13 +13,18 @@ This library uses [CMake](http://cmake.org) to build the library, so from an ini make make install +OR + + mkdir build cd build - cmake -DLIBSBML_LIBRARY=< path to libsbml lib> -DLIBSBML_INCLUDE_DIR=< path to includes > ... -DEXTRA_LIBS= < comma separated list of xml libraries> + cmake -DLIBLX_LIBRARY=< path to liblx lib> -DLIBLX_INCLUDE_DIR=< path to includes > ... -DEXTRA_LIBS= < comma separated list of xml libraries> make make install -Should libSBML be installed in a default location it will be found automatically. Note that you do need to list the xml libraries that libSBML was linked against. In most cases libSBML is compiled against libXML and have compression enabled, so your `EXTRA_LIBS` would be: + + +Should libSBML/liblx be installed in a default location it will be found automatically. Note that you do need to list the xml libraries that libSBML was linked against. In most cases libSBML is compiled against libXML and have compression enabled, so your `EXTRA_LIBS` would be: EXTRA_LIBS=xml2;bz2;z;iconv @@ -27,7 +32,7 @@ note the semicolon denoting the listing of several libraries. Of course you coul EXTRA_LIBS=D:/dependencies/lib/expat.lib -for linking against `expat` and indicating, that libSBML was compiled without compression. +for linking against `expat` and indicating, that libSBML/liblx was compiled without compression. ## License This project is open source and freely available under \ No newline at end of file diff --git a/deviser/util/templates/README.md b/deviser/util/templates/README.md index 8df04fec..022133ac 100644 --- a/deviser/util/templates/README.md +++ b/deviser/util/templates/README.md @@ -2,10 +2,10 @@ ## Dependencies -This library requires libSBML to be present, as its XML parsing layer will be used. for that either expat, xerces-c or libXML2 needs to be available. +This library requires either liblx or libSBML to be present, as its XML parsing layer will be used. For that either expat, xerces-c or libXML2 needs to be available. ## Building -This library uses [CMake](http://cmake.org) to build the library, so from an initial checkout all you would need todo is to run: +This library uses [CMake](http://cmake.org) to build the library, so from an initial checkout all you would need to do is to run: mkdir build @@ -14,7 +14,18 @@ This library uses [CMake](http://cmake.org) to build the library, so from an ini make make install -Should libSBML be installed in a default location it will be found automatically. Note that you do need to list the xml libraries that libSBML was linked against. In most cases libSBML is compiled against libXML and have compression enabled, so your `EXTRA_LIBS` would be: +OR + + + mkdir build + cd build + cmake -DLIBLX_LIBRARY=< path to liblx lib> -DLIBLX_INCLUDE_DIR=< path to includes > ... -DEXTRA_LIBS= < comma separated list of xml libraries> + make + make install + + + +Should libSBML/liblx be installed in a default location it will be found automatically. Note that you do need to list the xml libraries that libSBML was linked against. In most cases libSBML is compiled against libXML and have compression enabled, so your `EXTRA_LIBS` would be: EXTRA_LIBS=xml2;bz2;z;iconv @@ -22,7 +33,7 @@ note the semicolon denoting the listing of several libraries. Of course you coul EXTRA_LIBS=D:/dependencies/lib/expat.lib -for linking against `expat` and indicating, that libSBML was compiled without compression. +for linking against `expat` and indicating, that libSBML/liblx was compiled without compression. ## License From ea64f39cf8e265d3e364d7bf7680ad39cb3b1d14 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 25 Jul 2023 12:57:06 +0100 Subject: [PATCH 35/37] Add forward file testing --- .../test_other_library/test_other_library.py | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/deviser/pytest_files/test_other_library/test_other_library.py b/deviser/pytest_files/test_other_library/test_other_library.py index 0d1dcd8b..520b8693 100644 --- a/deviser/pytest_files/test_other_library/test_other_library.py +++ b/deviser/pytest_files/test_other_library/test_other_library.py @@ -246,20 +246,20 @@ def test_global(name, class_name, test_case): assert 0 == test_utils.compare_code_txt('README', '.md') -# @pytest.mark.parametrize('name, class_name, test_case', [ -# ('test_sedml', 'sedmlfwd', 'forward declarations'), -# ]) -# def test_forward(name, class_name, test_case): -# """ -# Based on old run_forward() function. -# Run 'forward declaration' tests. -# -# :param name: stub of XML filename, e.g. 'test_sedml' -# for file test_sedml.xml. -# :param class_name: test class, e.g. 'sedmlfwd' -# :param test_case: brief test description, e.g. 'forward declarations' -# """ -# gv.reset() -# xml_filename = functions.set_up_test(name, class_name, test_case) -# test_utils.generate_forward(xml_filename) -# assert 0 == test_utils.compare_code_headers(class_name) +@pytest.mark.parametrize('name, class_name, test_case', [ + ('testsbxml', 'tsbfwd', 'forward declarations'), +]) +def test_forward(name, class_name, test_case): + """ + Based on old run_forward() function. + Run 'forward declaration' tests. + + :param name: stub of XML filename, e.g. 'test_sedml' + for file test_sedml.xml. + :param class_name: test class, e.g. 'sedmlfwd' + :param test_case: brief test description, e.g. 'forward declarations' + """ + gv.reset() + xml_filename = functions.set_up_test(name, class_name, test_case) + test_utils.generate_forward(xml_filename) + assert 0 == test_utils.compare_code_headers(class_name) From 5d4c8f0407ee8f4c6ffbdc059c8839bee833fe4b Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 25 Jul 2023 13:28:05 +0100 Subject: [PATCH 36/37] Forward files done --- deviser/code_files/ExtensionHeaderFile.py | 7 +++++- .../test_other_library/test-code/tsb/tsbfwd.h | 24 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/deviser/code_files/ExtensionHeaderFile.py b/deviser/code_files/ExtensionHeaderFile.py index 8ba06b5e..afde01b8 100644 --- a/deviser/code_files/ExtensionHeaderFile.py +++ b/deviser/code_files/ExtensionHeaderFile.py @@ -419,6 +419,10 @@ def write_all_elements(self): prefixed_name = '{0}{1}'.format(global_variables.prefix, name) new_element = dict({'name': prefixed_name}) elements.append(new_element) + others = ['List', 'ListNode', 'ExpectedAttributes'] + for name in others: + new_element = dict({'name': name}) + elements.append(new_element) self.write_classes(elements) new_length = len(elements) for i in range(new_length, no_elements, -1): @@ -483,7 +487,8 @@ def write_fwd_file(self): self.write_cppns_end() # if we are in another library and using either ASTNode or XMLNode # we need to declare these here - if global_variables.uses_ASTNode or global_variables.uses_XMLNode: + # don't need xmlnode for now + if global_variables.uses_ASTNode: self.write_libsbml_fwd() self.write_end_class_or_struct() self.write_defn_end() diff --git a/deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h b/deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h index 076a438d..2ef8f15f 100644 --- a/deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h +++ b/deviser/pytest_files/test_other_library/test-code/tsb/tsbfwd.h @@ -61,24 +61,22 @@ LIBTSB_CPP_NAMESPACE_BEGIN -typedef CLASS_OR_STRUCT TSBDocument TSBDocument_t; -typedef CLASS_OR_STRUCT TSBComment TSBComment_t; -typedef CLASS_OR_STRUCT TSBBase TSBBase_t; -typedef CLASS_OR_STRUCT TSBListOf TSBListOf_t; -typedef CLASS_OR_STRUCT TSBReader TSBReader_t; -typedef CLASS_OR_STRUCT TSBWriter TSBWriter_t; -typedef CLASS_OR_STRUCT TSBNamespaces TSBNamespaces_t; -typedef CLASS_OR_STRUCT TSBError TSBError_t; -typedef CLASS_OR_STRUCT List List_t; -typedef CLASS_OR_STRUCT ListNode ListNode_t; -typedef CLASS_OR_STRUCT ExpectedAttributes ExpectedAttributes_t; - +typedef CLASS_OR_STRUCT TSBDocument TSBDocument_t; +typedef CLASS_OR_STRUCT TSBComment TSBComment_t; +typedef CLASS_OR_STRUCT TSBBase TSBBase_t; +typedef CLASS_OR_STRUCT TSBListOf TSBListOf_t; +typedef CLASS_OR_STRUCT TSBReader TSBReader_t; +typedef CLASS_OR_STRUCT TSBWriter TSBWriter_t; +typedef CLASS_OR_STRUCT TSBNamespaces TSBNamespaces_t; +typedef CLASS_OR_STRUCT TSBError TSBError_t; +typedef CLASS_OR_STRUCT List List_t; +typedef CLASS_OR_STRUCT ListNode ListNode_t; +typedef CLASS_OR_STRUCT ExpectedAttributes ExpectedAttributes_t; LIBTSB_CPP_NAMESPACE_END - #undef CLASS_OR_STRUCT From 66032b277fbbc0ee85acd67782b65013d8fc295b Mon Sep 17 00:00:00 2001 From: skeating Date: Sat, 28 Oct 2023 13:57:28 +0100 Subject: [PATCH 37/37] change needed to run --- deviser/util/generateCode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deviser/util/generateCode.py b/deviser/util/generateCode.py index 2d8550af..e3a93549 100644 --- a/deviser/util/generateCode.py +++ b/deviser/util/generateCode.py @@ -358,7 +358,7 @@ def generate_other_library_code_files(name, ob): working_class['document'] = True all_files = CppFiles.CppFiles(working_class, True) all_files.write_files() - base_files = OtherLibraryFiles(prefix, ob['baseElements'], True) + base_files = OtherLibraryFiles.OtherLibraryFiles(prefix, ob['baseElements'], True) base_files.write_files() os.chdir(this_dir)