示例#1
0
def main():

    test_all = True
    #    test_all = False

    # Set up the environment.
    this_dir = os.path.dirname(os.path.abspath(__file__))
    (path_to_tests, other) = os.path.split(this_dir)
    test_functions.set_path_to_tests(path_to_tests)
    if not os.path.isdir('temp'):
        os.mkdir('temp')
    fail = 0
    gv.reset()

    if test_all:
        fail = testSedML(fail)
        fail = testCombine(fail)
    else:
        name = 'test_sedml'
        num = 33
        class_name = 'SedRepeatedTask'
        list_of = ''
        test_case = 'attribute with different xml name'
        fail += run_test(name, num, class_name, test_case, list_of)

    test_functions.report('OTHER LIBRARY', fail, fails, not_tested)
    return fail
示例#2
0
def testCombine(fail):
    """
    Run the 'combine' tests.

    :param fail: integer number of tests failed so far
    :returns: updated value of `fail` after running these tests.
    """
    gv.reset()

    name = 'combine-archive'
    num = 0
    class_name = 'CaContent'
    list_of = 'CaListOfContents'
    test_case = 'check includes'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'combine-archive'
    class_name = 'CaBase'
    list_of = 'CaListOf'
    test_case = 'templates'
    fail += run_templates(name, class_name, test_case, list_of)
    fail += test_other_templates('Ca')

    name = 'combine-archive'
    class_name = 'CaBase'
    test_case = 'common'
    fail += test_common_templates(name, class_name, test_case, 'Ca', 'combine')

    name = 'combine-archive'
    num = 1
    class_name = 'CaOmexManifest'
    list_of = ''
    test_case = 'document'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'combine-archive'
    class_name = 'libcombine'
    test_case = 'csharp dir'
    binding = 'csharp'
    fail += test_bindings(name, class_name, test_case, binding, 'combine')

    name = 'combine-archive'
    class_name = 'libcombine'
    test_case = 'swig dir'
    binding = 'swig'
    fail += test_bindings(name, class_name, test_case, binding, 'combine')

    name = 'combine-archive'
    class_name = 'libcombine'
    # test_case = 'cmake'
    # binding = 'cmake'
    fail += test_cmake(name,
                       class_name)  # , test_case, binding)  # , 'combine')

    return fail
def testCombine(fail):
    global_variables.reset()

    name = 'combine-archive'
    num = 0
    class_name = 'CaContent'
    list_of = 'CaListOfContents'
    test_case = 'check includes'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'combine-archive'
    class_name = 'CaBase'
    list_of = 'CaListOf'
    test_case = 'templates'
    fail += run_templates(name, class_name, test_case, list_of)
    fail += test_other_templates('Ca')


    name = 'combine-archive'
    class_name = 'CaBase'
    test_case = 'common'
    fail += test_common_templates(name, class_name, test_case, 'Ca', 'combine')

    name = 'combine-archive'
    num = 1
    class_name = 'CaOmexManifest'
    list_of = ''
    test_case = 'document'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'combine-archive'
    class_name = 'libcombine'
    test_case = 'csharp dir'
    binding = 'csharp'
    fail += test_bindings(name, class_name, test_case, binding, 'combine')

    name = 'combine-archive'
    class_name = 'libcombine'
    test_case = 'swig dir'
    binding = 'swig'
    fail += test_bindings(name, class_name, test_case, binding, 'combine')

    name = 'combine-archive'
    class_name = 'libcombine'
    test_case = 'cmake'
    binding = 'cmake'
    fail += test_cmake(name, class_name, test_case, binding, 'combine')

    return fail
示例#4
0
def testSedML(fail):
    """
    Run the sedml tests.

    :param fail: integer number of tests failed so far
    :returns: updated value of `fail` after running these tests.
    """
    gv.reset()

    name = 'test_sedml'
    num = 1
    class_name = 'SedModel'
    list_of = 'SedListOfModels'
    test_case = 'model'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 0
    class_name = 'SedDocument'
    list_of = ''
    test_case = 'document'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    class_name = 'SedBase'
    list_of = 'SedListOf'
    test_case = 'templates'
    fail += run_templates(name, class_name, test_case, list_of)
    fail += test_other_templates('Sed')

    name = 'test_sedml'
    class_name = 'SedBase'
    test_case = 'common'
    fail += test_common_templates(name, class_name, test_case, 'Sed', 'sedml')

    name = 'test_sedml'
    class_name = 'SedmlEnumerations'
    test_case = 'enumerations'
    fail += run_enum(name, class_name, test_case)

    name = 'test_sedml'
    class_name = 'sedmlfwd'
    test_case = 'forward declarations'
    fail += run_forward(name, class_name, test_case)

    name = 'test_sedml'
    num = 3
    class_name = 'SedAddXML'
    list_of = ''
    test_case = 'xmlnode used'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 26
    class_name = 'SedSetValue'
    list_of = ''
    test_case = 'astnode used'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 12
    class_name = 'SedDataGenerator'
    list_of = ''
    test_case = 'astnode in getElementBySId bug'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 33
    class_name = 'SedRepeatedTask'
    list_of = ''
    test_case = 'attribute with different xml name'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 7
    class_name = 'SedSimulation'
    list_of = ''
    test_case = 'child element'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 28
    class_name = 'SedVectorRange'
    list_of = ''
    test_case = 'deal with vectors'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 10
    class_name = 'SedAbstractTask'
    list_of = 'SedListOfTasks'
    test_case = 'catch different abstract types'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 13
    class_name = 'SedOutput'
    list_of = 'SedListOfOutputs'
    test_case = 'catch different abstract types'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    class_name = 'libsedml'
    test_case = 'swig dir'
    binding = 'swig'
    fail += test_bindings(name, class_name, test_case, binding, 'sedml')

    name = 'test_sedml'
    class_name = 'libsedml'
    test_case = 'csharp dir'
    binding = 'csharp'
    fail += test_bindings(name, class_name, test_case, binding, 'sedml')

    name = 'test_sedml'
    class_name = 'libsedml'
    # test_case = 'cmake'
    # binding = 'cmake'
    fail += test_cmake(name, class_name)  # , test_case, binding)  # , 'sedml')

    name = 'test_sedml'
    class_name = 'libsedml'
    test_case = 'global files'
    fail += test_global(name, class_name, test_case)

    return fail
示例#5
0
    def parse_deviser_xml(self):
        """
        Parses the given filename and returns a dictionary with
        the definition contained in it
        """

        enums = []

        temp = self.get_value(self.dom.documentElement, 'name')
        # we expect this to be lower case
        self.package_name = temp.lower()
        number = self.get_int_value(self, self.dom.documentElement, 'number')
        offset = self.get_int_value(self, self.dom.documentElement, 'offset')
        fname = self.get_value(self.dom.documentElement, 'fullname')
        fullname = fname
        if fname.endswith('.'):
            l = len(fname)
            fullname = fname[0:l - 1]
        required = self.get_bool_value(self, self.dom.documentElement,
                                       'required')
        custom_copyright = self.get_add_code_value(self,
                                                   self.dom.documentElement,
                                                   'customCopyright')
        add_declarations = self.get_add_code_value(self,
                                                   self.dom.documentElement,
                                                   'additionalDecls')
        add_implementation = self.get_add_code_value(self,
                                                     self.dom.documentElement,
                                                     'additionalDefs')

        # setup global variables
        languages = self.dom.getElementsByTagName('language')
        if len(languages) > 0:
            # read the first element
            node = languages[0]
            self.read_language_element(node)
        else:
            # just in case we generate a new thing
            global_variables.reset()

        global_variables.set_global_fullname(fullname)
        global_variables.set_custom_copyright(custom_copyright)
        global_variables.add_additional_implementation(add_implementation)
        global_variables.add_additional_declaration(add_declarations)

        # get package information
        sbml_level = 3
        sbml_version = 1
        pkg_version = 1
        self.num_versions = len(self.dom.getElementsByTagName('pkgVersion'))
        self.version_count = 0

        lv_info = []
        for node in self.dom.getElementsByTagName('pkgVersion'):
            sbml_level = self.get_int_value(self, node, 'level')
            sbml_version = self.get_int_value(self, node, 'version')
            pkg_version = self.get_int_value(self, node, 'pkg_version')
            self.get_elements_for_version(node)
            self.get_plugins_for_version(node)
            lv_info.append(
                dict({
                    'core_level': sbml_level,
                    'core_version': sbml_version,
                    'pkg_version': pkg_version
                }))
            self.version_count = self.version_count + 1

        names_listed = []
        for node in self.dom.getElementsByTagName('enum'):
            values = []
            enum_name = self.get_enum_name(self, node)
            [cname, tname] = self.analyse_enumname(enum_name)

            if enum_name not in names_listed:
                for val in node.getElementsByTagName('enumValue'):
                    values.append(
                        dict({
                            'name':
                            self.get_enum_value(val, 'name', cname, tname),
                            'value':
                            self.get_value(val, 'value')
                        }))

                enums.append(dict({'name': enum_name, 'values': values}))
                names_listed.append(enum_name)

        mappings = []
        classes_listed = []
        for node in self.dom.getElementsByTagName('mapping'):
            [cname, package] = self.get_mapping(self, node)

            if cname not in classes_listed:
                mappings.append(dict({'class': cname, 'package': package}))
                classes_listed.append(cname)

        package = dict({
            'name': self.package_name,
            'elements': self.elements,
            'plugins': self.plugins,
            'number': number,
            'baseElements': self.sbml_elements,
            'enums': enums,
            'offset': offset,
            'fullname': fullname,
            'base_level': sbml_level,
            'base_version': sbml_version,
            'pkg_version': pkg_version,
            'required': required,
            'num_versions': self.num_versions,
            'lv_info': lv_info
        })

        list_all_element = ['SBase', 'XMLNode', 'ASTNode', 'UncertMLNode']
        # link elements
        for elem in package['elements']:
            list_all_element.append(elem['name'])
            elem['root'] = package
            if 'attribs' in elem:
                for attr in elem['attribs']:
                    attr['parent'] = elem
                    attr['root'] = package
            if 'lo_attribs' in elem:
                for attr in elem['lo_attribs']:
                    attr['parent'] = elem
                    attr['root'] = package

        for elem in package['baseElements']:
            elem['root'] = package
            if 'attribs' in elem:
                for attr in elem['attribs']:
                    attr['parent'] = elem
                    attr['root'] = package
                    if attr['type'] == 'lo_element':
                        if 'element' in attr and attr['element'] != '' and attr[
                                'element'] not in list_all_element:
                            self.report_error(
                                global_variables.
                                return_codes['unknown type used'],
                                'Unrecognized element: {0}'.format(
                                    attr['element']))
                    if 'element' in attr and attr['element'] in classes_listed:
                        for map in mappings:
                            if map['class'] == attr['element']:
                                attr['other_package'] = map['package']

            if 'concrete' in elem:
                for attr in elem['concrete']:
                    attr['parent'] = elem
                    attr['root'] = package
            if 'lo_attribs' in elem:
                for attr in elem['lo_attribs']:
                    attr['parent'] = elem
                    attr['root'] = package

        for elem in package['plugins']:
            elem['root'] = package
            if 'attribs' in elem:
                for attr in elem['attribs']:
                    attr['parent'] = elem
                    attr['root'] = package

        self.add_parent_elements(package)

        return package
def testSedML(fail):
    global_variables.reset()

    name = 'test_sedml'
    num = 1
    class_name = 'SedModel'
    list_of = 'SedListOfModels'
    test_case = 'model'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 0
    class_name = 'SedDocument'
    list_of = ''
    test_case = 'document'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    class_name = 'SedBase'
    list_of = 'SedListOf'
    test_case = 'templates'
    fail += run_templates(name, class_name, test_case, list_of)
    fail += test_other_templates('Sed')

    name = 'test_sedml'
    class_name = 'SedBase'
    test_case = 'common'
    fail += test_common_templates(name, class_name, test_case, 'Sed', 'sedml')

    name = 'test_sedml'
    class_name = 'sedmlfwd'
    test_case = 'forward declarations'
    fail += run_forward(name, class_name, test_case)

    name = 'test_sedml'
    num = 3
    class_name = 'SedAddXML'
    list_of = ''
    test_case = 'xmlnode used'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 4
    class_name = 'SedSetValue'
    list_of = ''
    test_case = 'astnode used'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 5
    class_name = 'SedDataGenerator'
    list_of = ''
    test_case = 'astnode in getElementBySId bug'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 6
    class_name = 'SedRepeatedTask'
    list_of = ''
    test_case = 'attribute with different xml name'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 7
    class_name = 'SedSimulation'
    list_of = ''
    test_case = 'child element'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    num = 8
    class_name = 'SedVectorRange'
    list_of = ''
    test_case = 'deal with vectors'
    fail += run_test(name, num, class_name, test_case, list_of)

    name = 'test_sedml'
    class_name = 'libsedml'
    test_case = 'swig dir'
    binding = 'swig'
    fail += test_bindings(name, class_name, test_case, binding, 'sedml')

    name = 'test_sedml'
    class_name = 'libsedml'
    test_case = 'csharp dir'
    binding = 'csharp'
    fail += test_bindings(name, class_name, test_case, binding, 'sedml')

    name = 'test_sedml'
    class_name = 'libsedml'
    test_case = 'cmake'
    binding = 'cmake'
    fail += test_cmake(name, class_name, test_case, binding, 'sedml')

    name = 'test_sedml'
    class_name = 'libsedml'
    test_case = 'global files'
    fail += test_global(name, class_name, test_case)

    return fail
示例#7
0
    def parse_deviser_xml(self):
        """
        Parses the given filename and returns a dictionary with
        the definition contained in it
        """

        enums = []

        temp = self.get_value(self.dom.documentElement, 'name')
        # we expect this to be lower case
        self.package_name = temp.lower()
        number = self.get_int_value(self, self.dom.documentElement, 'number')
        offset = self.get_int_value(self, self.dom.documentElement, 'offset')
        fullname = self.get_value(self.dom.documentElement, 'fullname')
        required = self.get_bool_value(self, self.dom.documentElement, 
                                       'required')
        custom_copyright = self.get_add_code_value(self,
                                                   self.dom.documentElement,
                                                   'customCopyright')

        # setup global variables
        languages = self.dom.getElementsByTagName('language')
        if len(languages) > 0: 
            # read the first element
            node = languages[0]
            self.read_language_element(node)
        else:
            # just in case we generate a new thing
            global_variables.reset()

        global_variables.set_global_fullname(fullname)
        global_variables.set_custom_copyright(custom_copyright)

        # get package information
        sbml_level = 3
        sbml_version = 1
        pkg_version = 1
        self.num_versions = len(self.dom.getElementsByTagName('pkgVersion'))

        for node in self.dom.getElementsByTagName('pkgVersion'):
            sbml_level = self.get_int_value(self, node, 'level')
            sbml_version = self.get_int_value(self, node, 'version')
            self.get_elements_for_version(node)
            self.get_plugins_for_version(node)

        names_listed = []
        for node in self.dom.getElementsByTagName('enum'):
            values = []
            enum_name = self.get_enum_name(self, node)

            if enum_name not in names_listed:
                for val in node.getElementsByTagName('enumValue'):
                    values.append(dict({'name': self.get_value(val, 'name'),
                                        'value': self.get_value(val, 'value')}))

                enums.append(dict({'name': enum_name, 'values': values}))
                names_listed.append(enum_name)

        package = dict({'name': self.package_name,
                        'elements': self.elements,
                        'plugins': self.plugins,
                        'number': number,
                        'baseElements': self.sbml_elements,
                        'enums': enums,
                        'offset': offset,
                        'fullname': fullname,
                        'base_level': sbml_level,
                        'base_version': sbml_version,
                        'pkg_version': pkg_version,
                        'required': required,
                        'num_versions': self.num_versions
                        })

        # link elements
        for elem in package['elements']:
            elem['root'] = package
            if 'attribs' in elem:
                for attr in elem['attribs']:
                    attr['parent'] = elem
                    attr['root'] = package

        for elem in package['baseElements']:
            elem['root'] = package
            if 'attribs' in elem:
                for attr in elem['attribs']:
                    attr['parent'] = elem
                    attr['root'] = package
            if 'concrete' in elem:
                for attr in elem['concrete']:
                    attr['parent'] = elem
                    attr['root'] = package

        self.add_parent_elements(package)

        return package
示例#8
0
def main():

    # NOTE: the test sets below are in the same order as the functions
    # appear in strFunctions.py. Please maintain that. Thanks.

    # Set up variables
    fails = []
    not_tested = []
    fail = 0

    #######################################################
    # Start of tests

    # upper_first() tests
    fail += run_strfunc_test(sf.upper_first, 'cat', 'Cat', fails)
    # fail += run_strfunc_test(sf.upper_first, 'cat', 'CAT')  # A failure test
    data = {'cat': 'Cat', 'csgsomething': 'CSGsomething', 'csgcat': 'CSGcat',
            'cscat': 'Cscat', 'csgeometry': 'CSGeometry',
            'csGeometry': 'CSGeometry', 'a': 'A'}
    fail += execute_tests(sf.upper_first, data, fails)

    # lower_first() tests - it's virtually the exact opposite of upper_first()
    data2 = swap_dictionary(data)
    fail += execute_tests(sf.lower_first, data2, fails)

    # abbrev_name() tests
    data = {"thisIsATest": "iat", "CAT": "cat", "cat": "c", "c": "c", "C": "c"}
    fail += execute_tests(sf.abbrev_name, data, fails)

    # abbrev_lo_name() tests
    data = {"spaghetti": "", "ListOfFoo": "LOFoo", "ListOfFOO": "LOFOO"}
    fail += execute_tests(sf.abbrev_lo_name, data, fails)

    # list_of_name() tests
    gv.reset()
    data = {"FooParameter": "ListOfFooParameters"}
    fail += execute_tests(sf.list_of_name, data, fails, add_prefix=True)
    fail += execute_tests(sf.list_of_name, data, fails, add_prefix=False)
    # print(f"gv is package: {gv.is_package}, gv prefix: {gv.prefix}")
    gv.is_package = False
    fail += execute_tests(sf.list_of_name, data, fails, add_prefix=False)
    data = {"FooParameter": "SBMLListOfFooParameters"}
    fail += execute_tests(sf.list_of_name, data, fails, add_prefix=True)

    # lower_list_of_name_no_prefix() tests
    gv.reset()
    data = {"fox": "listOfFoxes", "cat": "listOfCats",
            "child": "listOfChildren"}
    fail += execute_tests(sf.lower_list_of_name_no_prefix, data, fails)
    gv.is_package = False
    fail += execute_tests(sf.lower_list_of_name_no_prefix, data, fails)

    # cap_list_of_name() tests
    gv.reset()
    data = {"FooParameter": "ListOfFooParameters", "cat": "ListOfCats"}
    fail += execute_tests(sf.cap_list_of_name, data, fails, add_prefix=False)
    fail += execute_tests(sf.cap_list_of_name, data, fails, add_prefix=True)
    gv.is_package = False
    fail += execute_tests(sf.cap_list_of_name, data, fails, add_prefix=False)
    data = {"FooParameter": "SBMLListOfFooParameters", "cat": "SBMLListOfCats"}
    fail += execute_tests(sf.cap_list_of_name, data, fails, add_prefix=True)

    # cap_list_of_name_no_prefix() tests
    gv.reset()
    data = {"FooParameter": "ListOfFooParameters", "cat": "ListOfCats",
            "SBMLFooParameter": "ListOfSBMLFooParameters"}
    fail += execute_tests(sf.cap_list_of_name_no_prefix, data, fails)
    gv.is_package = False
    # this gets wrongly dealt with by the remove prefix function
    # TODO sort
    data = {"FooParameter": "ListOfFooParameters", "cat": "ListOfCats",
            "SBMLFooParameter": "ListOfFooParameters"}
#    fail += execute_tests(sf.cap_list_of_name_no_prefix, data, fails)

    # plural_no_prefix() tests
    gv.reset()
    data = {"fox": "foxes", "child": "children", "SBMLchild": "SBMLchildren"}
    fail += execute_tests(sf.plural_no_prefix, data, fails)
    gv.is_package = False
    gv.prefix = "Rosie"
    data = {"RosieFox": "Foxes", "RosieChild": "Children", "RosieCat": "Cats",
            "Rosiefox": "Rosiefoxes"}  # prefix only removed if capital after
    fail += execute_tests(sf.plural_no_prefix, data, fails)
    gv.is_package = True
    data = {"Rosiefox": "Rosiefoxes", "Rosiechild": "Rosiechildren",
            "RosieCat": "RosieCats"}
    fail += execute_tests(sf.plural_no_prefix, data, fails)

    # plural() tests
    data = {"cat": "cats", "dogs": "dogs", "child": "children",
            "disinformation": "disinformation", "fox": "foxes",
            "party": "parties", "cloud": "clouds", "something": "somethings",
            "apple": "apples"}
    fail += execute_tests(sf.plural, data, fails)

    # singular() tests
    data2 = swap_dictionary(data)
    data2['dogs'] = 'dog'  # Just need to tweak this one entry. Otherwise OK.
    fail += execute_tests(sf.singular, data2, fails)

    # single -> plural -> single
    data = {"cat": "cat", "dog": "dog", "child": "child",
            "disinformation": "disinformation", "fox": "fox",
            "party": "party", "cloud": "cloud", "something": "something",
            "apple": "apple"}
    fail += execute_tests(plural_then_single, data, fails)

    data = {"cats": "cats", "dogs": "dogs", "children": "children",
            "disinformation": "disinformation", "foxes": "foxes",
            "parties": "parties", "clouds": "clouds",
            "somethings": "somethings", "apples": "apples"}
    fail += execute_tests(single_then_plural, data, fails)

    # remove_prefix() tests - this is a complicated function to test!
    # tests removing a package prefix
    gv.reset()  # gv.prefix now "SBML"
    gv.is_package = True
    gv.package_prefix = 'Fbc'
    data = {"FbcType": "Type", "FluxObjective": "FluxObjective",
            "FbcSBMLDocument": "FbcSBMLDocument"}
    fail += execute_tests(sf.remove_prefix, data, fails)
    fail += execute_tests(sf.remove_prefix, data, fails, remove_package=True)

    doc_data = {"FbcSBMLDocument": "SBMLDocument"}
    fail += execute_tests(sf.remove_prefix, doc_data, fails,
                          remove_doc_prefix=True)

    gv.reset()  # gv.prefix now "SBML"
    gv.is_package = True
    gv.package_prefix = ''  # package prefix has not been specified
    fail += execute_tests(sf.remove_prefix, data, fails, prefix='Fbc')

    # no prefix to remove has been specified or explicitly told not to remove
    data = {"FbcType": "FbcType", "FluxObjective": "FluxObjective",
            "FbcSBMLDocument": "FbcSBMLDocument"}
    fail += execute_tests(sf.remove_prefix, data, fails, prefix='')
    fail += execute_tests(sf.remove_prefix, data, fails, prefix='Fbc',
                          remove_package=False)
    fail += execute_tests(sf.remove_prefix, data, fails,
                          remove_doc_prefix=True)
    fail += execute_tests(sf.remove_prefix, data, fails, prefix='',
                          remove_doc_prefix=True)
    fail += execute_tests(sf.remove_prefix, data, fails, prefix='Fbc',
                          remove_doc_prefix=False, remove_package=False)

    doc_data = {"FbcSBMLDocument": "SBMLDocument"}
    fail += execute_tests(sf.remove_prefix, doc_data, fails, prefix='Fbc',
                          remove_doc_prefix=True)

    gv.reset()  # gv.prefix now "SBML"
    gv.prefix = "Rosie"
    gv.is_package = False

    data = {"RosieFbcType": "FbcType", "RosieDocument": "RosieDocument"}
    fail += execute_tests(sf.remove_prefix, data, fails, prefix='Rosie')

    data_doc = {"RosieFbcType": "FbcType", "RosieDocument": "Document"}
    fail += execute_tests(sf.remove_prefix, data_doc, fails, prefix='Rosie',
                          remove_doc_prefix=True)

    gv.reset()  # gv.prefix now "SBML"
    data = {}

    # is_prefixed_name_test
    data = {"RosieFox": True, "rosieFoo": True, "rosiefoo": False,
            "RosiFox": False, "RoSiEFoo": True, "RoSiEfoo": False}
    fail += execute_tests(sf.is_prefixed_name, data, fails, prefix='Rosie')

    # is_prefixed_document_class test
    data = {"RosieDocument": True, "rosieDocument": True,
            "rosiedocument": False, "RosiDocument": False,
            "RoSiEDocument": True, "RoSiEDocment": False}
    fail += execute_tests(sf.is_prefixed_document_class, data, fails,
                          prefix='Rosie')

    # get_indefinite() tests
    data = {"apple": "an", "biscuit": "a", "elephant": "an", "image": "an",
            "polar bear": "a", "orangutan": "an", "under secretary": "an",
            "zither": "a"}
    fail += execute_tests(sf.get_indefinite, data, fails)

    # standard_element_name() tests
    data = {"listOfFoxes,": "Fox", "ListOfApples": "Apple",
            "XMLNode*": "XMLNode", "Rosie,": "Rosie", "rosie,": "Rosie",
            "name_t": "Name", "Name": "Name", "name": "Name"}
    fail += execute_tests(sf.standard_element_name, data, fails)

    # get_library_suffix() tests
    data = {"library": "Rary", "libSBML": "Sbml", "cat": "Cat", "lib": ""}
    fail += execute_tests(sf.get_library_suffix, data, fails)

    # A varargs example - wrap_token
    fail += run_strfunc_test(sf.wrap_token, 'fred',
                             '\\token{cat:\\-fred}', fails, pkg='cat')
    fail += run_strfunc_test(sf.wrap_token, 'fred',
                             '\\token{fred}', fails)

    # wrap_type() tests - I don't really understand this one!

    # wrap_section() tests - or this one!

    # make_class() tests
    fail += run_strfunc_test(sf.make_class, 'Irenaeus',
                             'irenaeus-class', fails)
    fail += run_strfunc_test(sf.make_class, 'Irenaeus',
                             'extended-irenaeus-class',
                             fails, add_extended=True)

    # wrap_enum() tests
    fail += run_strfunc_test(sf.wrap_enum, 'cat', '\\primtype{cat}', fails)

    # get_sid_refs() tests 'cat': 'Cat', 'csgsomething': 'CSGsomething',
    data = {'': ['', 'SId'], 'cat': ['Cat', 'Cat'],
            'csgsomething': ['CSGsomething', 'CSGsomething'],
            'cat,dog': ["Cat or \\Dog", "CatOrDog"]}
    fail += execute_tests(sf.get_sid_refs, data, fails)

    # get_element_name() tests
    gv.reset()
    gv.prefix = 'Bar'
    gv.is_package = False
    attribute1 = {'something': 'something else'}
    attribute2 = {'type': 'element', 'element': 'ASTNode*', 'texname': 'tex'}
    attribute3 = {'isListOf': True, 'name': 'Foo'}
    attribute4 = {'type': 'element', 'element': 'Unit', 'texname': 'Unit'}
    attribute5 = {'type': 'lo_element', 'element': 'Unit', 'texname': 'Unit'}
    attribute6 = {'type': 'double', 'element': 'Unit', 'texname': 'Unit'}
    attribute7 = {'isListOf': False, 'name': 'Foo'}
    attribute8 = {'type': 'lo_element', 'element': 'Unit', 'name': 'Unit',
                  'listOfClassName': 'ListOfAnything'}
    fail += run_strfunc_test(sf.get_element_name, attribute1, "FIX_ME", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute2, "MathML math",
                             fails)
    fail += run_strfunc_test(sf.get_element_name, attribute3,
                             "\\BarListOfFoos", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute4, "Unit", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute5,
                             "\\BarListOfUnits", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute5,
                             "\\ListOfUnits", fails,
                             add_prefix_if_not_pkg=False)
    fail += run_strfunc_test(sf.get_element_name, attribute5,
                             "\\ListOfUnits", fails, leave_pkg_prefix=False)
    fail += run_strfunc_test(sf.get_element_name, attribute6, "FIX_ME", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute7, "\\Foo", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute8,
                             "\\BarListOfUnits", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute8,
                             "\\ListOfAnything", fails, leave_pkg_prefix=False)

    gv.reset()
    gv.prefix = 'Bar'
    gv.is_package = True
    gv.package_prefix = 'Foo'
    attribute1 = {'type': 'lo_element', 'element': 'Unit',
                  'name': 'FooUnit',
                  'isListOf': True}
    attribute2 = {'type': 'lo_element', 'element': 'Unit',
                  'name': 'Unit',
                  'isListOf': True, 'listOfClassName': 'ListOfUnits'}
    fail += run_strfunc_test(sf.get_element_name, attribute1,
                             "\\ListOfFooUnits", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute1,
                             "\\ListOfFooUnits", fails,
                             add_prefix_if_not_pkg=False)
    fail += run_strfunc_test(sf.get_element_name, attribute2,
                             "\\ListOfUnits", fails)
    fail += run_strfunc_test(sf.get_element_name, attribute2,
                             "\\ListOfUnits", fails, leave_pkg_prefix=False)
    fail += run_strfunc_test(sf.get_element_name, attribute2,
                             "\\ListOfUnits", fails,
                             add_prefix_if_not_pkg=False)

    # replace_digits() tests
    fail += run_strfunc_test(sf.replace_digits, "John 3:16",
                             "John Three:OneSix", fails)

    # replace_underscore() tests
    data = {"this_is_a_test": "this\\_is\\_a\\_test", "cat": "cat", "_": "\\_"}
    fail += execute_tests(sf.replace_underscore, data, fails)

    # remove_spaces() tests
    data = {"   hello   world  ": "helloworld", "dogfish": "dogfish"}
    fail += execute_tests(sf.remove_spaces, data, fails)

    # remove_hyphens() tests
    data = {"this-is-a-test": ["thisIsATest", True], "cat": ["cat", False],
            "cat-": ["cat", True], "-cat": ["Cat", True]}
    fail += execute_tests(sf.remove_hyphens, data, fails)

    # texify() tests
    fail += run_strfunc_test(sf.texify, "012_27 cat44_8 ",
                             "ZeroOneTwo\\_TwoSevencatFourFour\\_Eight", fails)

    # compare_no_case() tests
    fail += run_strfunc_test(sf.compare_no_case, "This iS a TEST", True, fails,
                             reference="this is a test")
    fail += run_strfunc_test(sf.compare_no_case, "This iS a bad TEST", False,
                             fails,
                             reference="this is a test")

    # get_class_from_plugin() tests
    fail += run_strfunc_test(sf.get_class_from_plugin, "CompModelPlugin",
                             "Model",
                             fails,
                             package="Comp")
    fail += run_strfunc_test(sf.get_class_from_plugin, "CompModelPlug",
                             "",
                             fails,
                             package="Comp")
    fail += run_strfunc_test(sf.get_class_from_plugin, "Plugin",
                             "",
                             fails,
                             package="Comp")

    # prefix_name() tests
    gv.reset()
    gv.prefix = "DABS"
    data = {"DABS": "DABS", "DABSCAT": "DABSCAT", "dabs": "DABSdabs",
            "SBase": "DABSBase", "XMLNode": "XMLNode",
            "XMLNodeAgain": "DABSXMLNodeAgain", "ASTNode": "ASTNode"}
    fail += execute_tests(sf.prefix_name, data, fails)

    # prefix_classes() tests
    # This func doesn't return anything at the moment. So we have to
    # compare "changing" dictionary with what we expect it to be once
    # it's changed.
    gv.reset()  # gv.prefix is now "SBML"
    changing_dict = {'name': 'Colin', 'baseClass': gv.baseClass}
    expected_dict = {'name': 'SBMLColin', 'baseClass': gv.baseClass,
                     'elementName': 'colin'}
    # Do not consume return value
    run_strfunc_test(sf.prefix_classes, changing_dict, None, fails)
    fail += compare_dictionaries(changing_dict, expected_dict, fails)

    # Now a test of the same function,
    # this time with a list of attribute dictionaries
    # as a value in `changing_dict` and `expected_dict`:
    attrib1_before = {'type': 'lo_element', 'element': 'Dabs'}
    attrib1_after = {'type': 'lo_element', 'element': 'SBMLDabs'}
    attrib2_before = {'type': 'inline_lo_element', 'element': 'ASTNode'}
    attrib2_after = {'type': 'inline_lo_element', 'element': 'ASTNode'}
    concrete_before = [{'element': 'test'}]
    concrete_after = [{'element': 'SBMLtest'}]
    attrib2_before['concrete'] = concrete_before
    attrib2_after['concrete'] = concrete_after
    attribs_before = [attrib1_before, attrib2_before]
    attribs_after = [attrib1_after, attrib2_after]
    changing_dict = {'name': 'Colin', 'baseClass': gv.baseClass,
                     'lo_class_name': 'Dabs', 'attribs': attribs_before}
    expected_dict = {'name': 'SBMLColin', 'baseClass': gv.baseClass,
                     'elementName': 'colin', 'lo_class_name': 'SBMLDabs',
                     'attribs': attribs_after}
    # Do not consume return value
    run_strfunc_test(sf.prefix_classes, changing_dict, None, fails)
    fail += compare_dictionaries(changing_dict, expected_dict, fails)

    # is_camel_case() tests
    data = {'FooParameter': True, 'fooParameter': True, 'fooparameter': False,
            'Fooparameter': False}
    fail += execute_tests(sf.is_camel_case, data, fails)

    # Tests completed
    #############################################

    test_functions.report('strfunc', fail, fails, not_tested)
    return fail
示例#9
0
    def parse_deviser_xml(self):
        """
        Parses the given filename and returns a dictionary with
        the definition contained in it
        """

        enums = []

        temp = self.get_value(self.dom.documentElement, 'name')
        # we expect this to be lower case
        self.package_name = temp.lower()
        number = self.get_int_value(self, self.dom.documentElement, 'number')
        offset = self.get_int_value(self, self.dom.documentElement, 'offset')
        fullname = self.get_value(self.dom.documentElement, 'fullname')
        required = self.get_bool_value(self, self.dom.documentElement,
                                       'required')
        custom_copyright = self.get_add_code_value(self,
                                                   self.dom.documentElement,
                                                   'customCopyright')

        # setup global variables
        languages = self.dom.getElementsByTagName('language')
        if len(languages) > 0:
            # read the first element
            node = languages[0]
            self.read_language_element(node)
        else:
            # just in case we generate a new thing
            global_variables.reset()

        global_variables.set_global_fullname(fullname)
        global_variables.set_custom_copyright(custom_copyright)

        # get package information
        sbml_level = 3
        sbml_version = 1
        pkg_version = 1
        self.num_versions = len(self.dom.getElementsByTagName('pkgVersion'))

        for node in self.dom.getElementsByTagName('pkgVersion'):
            sbml_level = self.get_int_value(self, node, 'level')
            sbml_version = self.get_int_value(self, node, 'version')
            self.get_elements_for_version(node)
            self.get_plugins_for_version(node)

        names_listed = []
        for node in self.dom.getElementsByTagName('enum'):
            values = []
            enum_name = self.get_enum_name(self, node)

            if enum_name not in names_listed:
                for val in node.getElementsByTagName('enumValue'):
                    values.append(
                        dict({
                            'name': self.get_value(val, 'name'),
                            'value': self.get_value(val, 'value')
                        }))

                enums.append(dict({'name': enum_name, 'values': values}))
                names_listed.append(enum_name)

        package = dict({
            'name': self.package_name,
            'elements': self.elements,
            'plugins': self.plugins,
            'number': number,
            'baseElements': self.sbml_elements,
            'enums': enums,
            'offset': offset,
            'fullname': fullname,
            'base_level': sbml_level,
            'base_version': sbml_version,
            'pkg_version': pkg_version,
            'required': required,
            'num_versions': self.num_versions
        })

        # link elements
        for elem in package['elements']:
            elem['root'] = package
            if 'attribs' in elem:
                for attr in elem['attribs']:
                    attr['parent'] = elem
                    attr['root'] = package

        for elem in package['baseElements']:
            elem['root'] = package
            if 'attribs' in elem:
                for attr in elem['attribs']:
                    attr['parent'] = elem
                    attr['root'] = package
            if 'concrete' in elem:
                for attr in elem['concrete']:
                    attr['parent'] = elem
                    attr['root'] = package

        self.add_parent_elements(package)

        return package