def test_inheritance(self): import libcellml from libcellml import Importer # Test inheritance. x = Importer() 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)
# Parse an existing CellML model from a file. read_file = open('debugAnalysisExample.cellml', 'r') parser = Parser() model = parser.parseModel(read_file.read()) # STEP 2 # Resolve any imports and flatten the model for analysis. importer = Importer() # Resolve the imports. importer.resolveImports(model, '') # 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())
# Retrieve these and print to the terminal (you can do this manually or using the # convenience function as before). print_issues(importer) # end 4.b # Importer error[0]: # Description: Import of component 'importedGateH' from 'GateModel.cellml' requires # component named 'i_dont_exist' which cannot be found. # We need to change the import reference for the component to be 'gateEquations' instead # of 'i_dont_exist'. You can either retrieve the component using its name or directly # from the issue. Use the Component.setImportReference() function to fix the issue. # 4.c # Fix the issues reported by the importer. This needs to be an iterative process as # more files become available to the importer. issue0 = importer.issue(0) issue0.component().setImportReference('gateEquations') # end 4.c # The second issue reported is a circular dependency. This is contained in files that # haven't (yet) been seen at all by you, the user. It's included here to highlight the # fact that the Importer class opens and instantates all required dependencies, and that # some of those dependencies may have problems of their own. # Issue [1] is a WARNING: # description: Cyclic dependencies were found when attempting to resolve components in model 'CircularReferences'. The dependency loop is: # - component 'importedGateH' is imported from 'i_dont_exist' in 'GateModel.cellml' # - component 'importedGateM' is imported from 'gateEquations' in 'GateModel.cellml' # - component 'controller' is imported from 'controller' in 'CircularControllerReference.cellml' # - component 'controller' is imported from 'controller2' in 'CircularControllerReference2.cellml' # - component 'controller2' is imported from 'controller' in 'CircularControllerReference.cellml' and
# Parse an existing CellML model from a file. read_file = open('resources/importExample1.cellml', 'r') parser = Parser() original_model = parser.parseModel(read_file.read()) # STEP 2 # Create an Importer to resolve the imports in the model. importer = Importer() # Resolve the imports. importer.resolveImports(original_model, 'resources/') # Check for issues. print('The importer found {} issues.'.format(importer.issueCount())) for i in range(0,importer.issueCount()): print(importer.issue(i).description()) 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:')