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) x.addIssue(libcellml.Issue()) self.assertEqual(x.issueCount(), 1)
# Check for issues. print('The importer found {} issues.'.format(importer.issueCount())) 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_model(model, True) # end 1 print('----------------------------') print(' STEP 2: Validate the model') print('----------------------------') # 2.a # 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()))
print() # 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)