def test_importer(self): from libcellml import Importer, Parser, Printer parser = Parser() i = Importer() m = parser.parseModel(file_contents('importer/diamond.cellml')) printer = Printer() i.resolveImports(m, resource_path('importer/')) self.assertFalse(m.hasUnresolvedImports()) # Library should contain left, right, and one instance (not two) of the point. self.assertEqual(3, i.libraryCount()) self.assertEqual(resource_path('importer/diamond_left.cellml'), i.key(0)) self.assertEqual(resource_path('importer/diamond_point.cellml'), i.key(1)) self.assertEqual(resource_path('importer/diamond_right.cellml'), i.key(2)) # Access library items by their URL. left = i.library(resource_path('importer/diamond_left.cellml')) self.assertEqual(file_contents('importer/diamond_left.cellml'), printer.printModel(left))
model.component('uncomputedVariable').setMath(mathml) # Variable 'a' in component 'validationErrors' is not computed. # Variable 'c' in component 'validationErrors' is not computed. model.component('validationErrors').variable('c').setInitialValue(1.0) # Check again. validator.validateModel(model) print('The validator found {} issues.'.format(validator.issueCount())) for i in range(0, validator.issueCount()): issue = validator.issue(i) print(issue.description()) analyser.analyseModel(model) print('The analyser found {} issues.'.format(analyser.issueCount())) for i in range(0, analyser.issueCount()): issue = analyser.issue(i) print(issue.description()) # STEP 7 # Write the flattened, validated, analysed model to a serialised CellML string. printer = Printer() model_string = printer.printModel(model) # Write the serialised string to a file. write_file = open("debugAnalysisExampleFixed.cellml", "w") write_file.write(model_string) # END
print(' STEP 4: Check and output the corrected model') print('----------------------------------------------') # 4.a # Validate the corrected model again and check that there are no more issues. validator.validateModel(model) print('The validator found {} issues in the model.'.format( validator.issueCount())) # 4.b # Print the corrected model to the terminal. print_model(model, True) # 4.c # Print corrected model to a file. printer = Printer() serialised_model = printer.printModel(model) out_filename = 'tutorial2_printed.cellml' with open(out_filename, 'w') as f: f.write(serialised_model) # end 4 print( f"The corrected '{model.name()}' model has been printed to: {out_filename}" ) # 4.d # Go and have a cuppa, you're done!
# to do the final check before serialising our model for output, we will use the Importer # to create a flattened version of the model to submit for analysis. # 10.i # Create a flattened version of the final model using the Importer.flattenModel(model) # function. Run this through the analyser and expect there to be no issues reported. flatModel = importer.flattenModel(model) analyser.analyseModel(flatModel) print_issues(analyser) # end 10.i # Note that at this point an analysis of the unflattened model will still show errors, # but that's totally fine. print('------------------------------------------------------------') print(' STEP 11: Output the model ') print('------------------------------------------------------------') # 11.a # Create a Printer instance and use it to serialise the model. This creates a string # containing the CellML-formatted version of the model. Write this to a file called # 'PotassiumChannelModel.cellml'. printer = Printer() write_file = open('PotassiumChannelModel.cellml', 'w') write_file.write(printer.printModel(model)) write_file.close() # end print('The created model has been written to PotassiumChannelModel.cellml')
def test_print_model(self): from libcellml import Printer, Model # std::string printModel(ModelPtr model) p = Printer() self.assertIsInstance(p.printModel(Model()), str)
for i in range(0, validator.issueCount()): print(' - '.format(validator.issue(i).description())) analyser.analyseModel(flat_model) print('The analyser found {} issues.'.format(analyser.issueCount())) for i in range(0, analyser.issueCount()): print(' - '.format(analyser.issue(i).description())) # STEP 7 # Print the collection of repaired import models to files. # To avoid over-writing existing files, we'll write the corrected files to a separate # directory called "repaired/". Note that the relationship between the files needs # to be maintained, so even files that have not been changed need to be written # to the new location. # Write the original model to a file. printer = Printer() model_string = printer.printModel(original_model) write_file = open("repaired/import_debugger/importExample1.cellml", "w") write_file.write(model_string) # Write the dependency models in the importer library to files. for m in range(0, importer.libraryCount()): write_file = open("repaired/"+importer.key(m), "w") model_string = printer.printModel(importer.library(m)) write_file.write(model_string) print('The corrected models has been written to the \'repaired/resources/\' directory') # END