コード例 #1
0
ファイル: test_validator.py プロジェクト: opencor/libcellml
    def test_inheritance(self):
        import libcellml
        from libcellml import Validator

        # Test inheritance
        x = Validator()
        self.assertIsInstance(x, libcellml.logger.Logger)

        # Test access to inherited methods
        self.assertIsNone(x.issue(0))
        self.assertIsNone(x.issue(-1))
        self.assertEqual(x.issueCount(), 0)
コード例 #2
0
    for i in range(0, importer.issueCount()):
        issue = importer.issue(i)
        print(issue.description())

    # Flatten the model.
    model = importer.flattenModel(model)

    # STEP 3
    # Create an Validator instance and pass the model to it for processing.
    validator = Validator()
    validator.validateModel(model)

    # Print any issues to the terminal.
    print('The validator found {} issues.'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        issue = validator.issue(i)
        print(issue.description())

    # STEP 4
    # Fix the validation errors.

    # Add units to the variable 'b' in component 'validationErrors'.
    model.component('validationErrors').variable('b').setUnits('dimensionless')

    # Change the name of the variable 'iShouldBeNamed_c' to be 'c'.
    model.component('validationErrors').variable('iShouldBeNamed_c').setName('c')

    # Check again.
    validator.validateModel(model)
    print('The validator found {} issues.'.format(validator.issueCount()))
コード例 #3
0
    #      Create a Validator and pass the model into it.
    validator = Validator()
    validator.validateModel(model)

    #  2.b
    #      Check the number of issues returned from the validator.
    num_validation_issues = validator.issueCount()
    print('The validator has found {} issues!'.format(num_validation_issues))

    #  2.c
    #      Retrieve the issues, and print their description, url, reference, and
    #      type of item stored to the terminal.  The type of stored item is
    #      available as an enum, which can be turned into a string for output using
    #      the utility function, getItemTypeFromEnum(type).
    for e in range(0, num_validation_issues):
        issue = validator.issue(e)
        reference = issue.referenceHeading()
        print('  Validator issue[{}]:'.format(e))
        print('     Description: {}'.format(issue.description()))
        print('     Type of item stored: {}'.format(
            cellmlElementTypeAsString(issue.item().type())))
        print('     URL: {}'.format(issue.url()))
        if reference != '':
            print('    See section {} in the CellML specification.'.format(
                reference))

    #  end 2

    print('---------------------------------')
    print(' STEP 3: Fix the issues reported')
    print('---------------------------------')
コード例 #4
0
    #      containing:
    #          - a description string explaining the problem
    #          - a URL at which more information is available
    #          - an std.any item relevant to the problem, if available
    #          - a level indicator and
    #          - a cause indicator relevant to the stored item.
    #  We can use these issues as we need to.  The simplest way is to print the descriptions
    #  to the terminal.

    #  2.d
    #      Retrieve the number of issues encountered using the validator.issueCount() function,
    #      then retrieve the issue items from the validator using their index and the validator.issue(index)
    #      function.
    print('The validator has found {} issues.'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        print(validator.issue(i).description())
    print()

    #  2.e 
    #      Create the variables needed and add them to the potassium channel component.
    #      Revalidate and expect errors related to variables without units.
    k_channel_equations.addVariable(Variable('E_K'))
    k_channel_equations.addVariable(Variable('i_K'))
    k_channel_equations.addVariable(Variable('g_K'))
    k_channel_equations.addVariable(Variable('V'))
    k_channel_equations.addVariable(Variable('t'))
    k_channel_equations.addVariable(Variable('n'))

    validator.validateModel(model)
    print_issues(validator)
コード例 #5
0
    #  end 2.a

    #      Each Validator issue contains:
    #          - a description of the problem
    #          - the reference heading in the normative specification which affects this issue
    #          - a URL at which the informative specification notes can be found
    #          - an std.any item storing the CellML element most relevant to the issue and
    #          - a level indication.

    #  2.b
    #      Retrieve any issues from the validator and print their descriptions and help URL to the terminal.
    #      If you're already familiar with these you can use the print_issues function instead.
    print('The validator found {} issues.'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        issue = validator.issue(i)
        print('Issue {}: {}'.format(i, issue.description()))
        print('  reference: {}'.format(issue.referenceHeading()))
        print('  see: {}'.format(issue.url()))
        print('  stored item type: {}'.format(
            get_cellml_element_type_from_enum(issue.cellmlElementType())))
        print()

    #  end 2

    print('----------------------------------------------------------')
    print('   STEP 3: Repair the parsed model                        ')
    print('----------------------------------------------------------')

    #      The messages returned from the validator (and other classes) should (!) have enough information
    #      to enable you to know what the problem is.  In the case of the validator class, the URL listed
コード例 #6
0
    #  end 2.a

    #      Each Validator issue contains:
    #          - a description of the problem
    #          - the reference heading in the normative specification which affects this issue
    #          - a URL at which the informative specification notes can be found
    #          - an std.any item storing the CellML element most relevant to the issue and
    #          - a level indication.

    #  2.b
    #      Retrieve any issues from the validator and print their descriptions and help URL to the terminal.
    #      If you're already familiar with these you can use the print_issues function instead.
    print('The validator found {} issues.'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        issue = validator.issue(i)
        print('Issue {}: {}'.format(i, issue.description()))
        print('  reference: {}'.format(issue.referenceHeading()))
        print('  see: {}'.format(issue.url()))
        print('  stored item type: {}'.format(
            cellmlElementTypeAsString(issue.item().type())))
        print()

    #  end 2

    print('---------------------------------')
    print(' STEP 3: Repair the parsed model')
    print('---------------------------------')

    #      The messages returned from the validator (and other classes) should (!) have enough information
    #      to enable you to know what the problem is.  In the case of the validator class, the URL listed
コード例 #7
0
    # STEP 3
    # The analysis tools - the Validator and Analyser - will read only the submitted
    # model they do not look into any of the imported items, so they can't check them.
    # In order to retain the import structure but be able to use the diagnostic tools, 
    # we can create a flattened copy of the model for testing.  This can be used to
    # identify mistakes in the unflattened model too.  

    # Create a Validator and Analyser and submit the original, unflattened model.
    # We don't expect either of these to report any issues.
    validator = Validator()
    validator.validateModel(original_model)

    print('Investigating the original model:')
    print(' - the validator found {} issues'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        print('    - {}'.format(validator.issue(i).description()))
    
    analyser = Analyser()
    analyser.analyseModel(original_model)
    print(' - the analyser found {} issues'.format(analyser.issueCount()))
    for i in range(0, analyser.issueCount()):
        print('    - {}'.format(analyser.issue(i).description()))
    print()

    # Create a flattened version for diagnostics.
    flat_model = importer.flattenModel(original_model)

    # Repeat the validation and analysis above on the flattened model.
    validator.validateModel(flat_model)
    print('Investigating the flattened model:')
    print(' - the validator found {} issues'.format(validator.issueCount()))