def test_warnings_1_0(self): # Tests warnings are logged # Create model that will generate warnings x = ('<?xml version="1.0" encoding="UTF-8"?>' '<model name="test" xmlns="http://www.cellml.org/cellml/1.0#">' '<component name="a">' ' <variable name="hello" units="ampere"' ' public_interface="in"/>' '</component>' '</model>') # Write to disk and import with TemporaryDirectory() as d: path = d.path('test.celllml') with open(path, 'w') as f: f.write(x) # Import i = formats.importer('cellml') with WarningCollector() as w: i.model(path) # Check warning was raised self.assertIn('not connected', w.text())
def test_model(self): i = formats.importer('sbml') self.assertTrue(i.supports_model()) m = i.model(os.path.join(myotest.DIR_DATA, 'HodgkinHuxley.xml')) try: m.validate() except myokit.MissingTimeVariableError: # SBML models don't specify the time variable pass
def test_component(self): path = os.path.join(myotest.DIR_DATA, '43.channelml') i = formats.importer('channelml') self.assertTrue(i.supports_component()) m = myokit.Model() c = m.add_component('membrane') v = c.add_variable('V') self.assertRaises(myokit.ImportError, i.component, path, m) v.set_label('membrane_potential') i.component(path, m) cs = [c for c in m.components()] self.assertEqual(len(cs), 2)
def test_not_a_model(self): # Test loading something other than a CellML file # Different XML file i = formats.importer('cellml') self.assertRaisesRegex( CellMLImporterError, 'not a CellML document', i.model, os.path.join(DIR_FORMATS, 'sbml', 'HodgkinHuxley.xml')) # Not an XML file self.assertRaisesRegex(CellMLImporterError, 'Unable to parse XML', i.model, os.path.join(DIR_FORMATS, 'lr-1991.mmt'))
def test_stimulus_generation(self): # Tests if protocols allow a stimulus current to be added e = formats.exporter('cellml') i = formats.importer('cellml') # Load input model m1, p1, _ = myokit.load('example') org_code = m1.code() # 1. Export without a protocol with TemporaryDirectory() as d: path = d.path('model.cellml') with WarningCollector() as w: e.model(path, m1) m2 = i.model(path) self.assertFalse(w.has_warnings()) self.assertTrue(isinstance(m2.get('engine.pace').rhs(), myokit.Number)) # 2. Export with protocol, but without variable bound to pacing m1.get('engine.pace').set_binding(None) with TemporaryDirectory() as d: path = d.path('model.cellml') with WarningCollector() as w: e.model(path, m1, p1) m2 = i.model(path) self.assertTrue(w.has_warnings()) self.assertTrue(isinstance(m2.get('engine.pace').rhs(), myokit.Number)) # 3. Export with protocol and variable bound to pacing m1.get('engine.pace').set_binding('pace') with TemporaryDirectory() as d: path = d.path('model.cellml') with WarningCollector() as w: e.model(path, m1, p1) m2 = i.model(path) self.assertFalse(w.has_warnings()) rhs = m2.get('membrane.i_stim').rhs() self.assertTrue(rhs, myokit.Multiply) self.assertTrue(isinstance(rhs[0], myokit.Piecewise)) # Check original model is unchanged self.assertEqual(org_code, m1.code())
def test_model_2_0_errors(self): # CellML 2.0 files with errors should raise CellMLImporterErrors # Create model that will generate warnings x = ('<?xml version="1.0" encoding="UTF-8"?>' '<model name="test" xmlns="http://www.cellml.org/cellml/2.0#">' '<component name="a">' ' <variable name="hello" units="ampere"' ' public_interface="in"/>' '</component>' '</model>') # Write to disk and import with TemporaryDirectory() as d: path = d.path('test.celllml') with open(path, 'w') as f: f.write(x) # Import i = formats.importer('cellml') self.assertRaisesRegex(CellMLImporterError, 'Unexpected attribute', i.model, path)
def test_model_2_0(self): # Decker 2009 in CellML 2.0 i = formats.importer('cellml') m = i.model(os.path.join(DIR, 'decker-2009.cellml')) m.validate()
def test_model_1_0_simple(self): # Beeler-Reuter is a simple model i = formats.importer('cellml') m = i.model(os.path.join(DIR, 'br-1977.cellml')) m.validate()
def test_model__1_0_nesting(self): # The corrias model has multiple levels of nesting (encapsulation) i = formats.importer('cellml') m = i.model(os.path.join(DIR, 'corrias.cellml')) m.validate()
def test_model_1_0_errors(self): # Files with errors raise CellMLImporterErrors (not parser errors) i = formats.importer('cellml') m = os.path.join(DIR, 'invalid-file.cellml') self.assertRaisesRegex(CellMLImporterError, 'valid CellML identifier', i.model, m)
def test_model_dot(self): # This is beeler-reuter but with a dot() in an expression i = formats.importer('cellml') self.assertTrue(i.supports_model()) m = i.model(os.path.join(myotest.DIR_DATA, 'br-1977-dot.cellml')) m.validate()
def test_capability_reporting(self): # Test if the right capabilities are reported. i = formats.importer('cellml') self.assertFalse(i.supports_component()) self.assertTrue(i.supports_model()) self.assertFalse(i.supports_protocol())
def test_protocol(self): i = formats.importer('abf') self.assertTrue(i.supports_protocol()) i.protocol(os.path.join(DIR_FORMATS, 'abf-v1.abf'))
def test_protocol(self): i = formats.importer('abf') self.assertTrue(i.supports_protocol()) i.protocol(os.path.join(myotest.DIR_DATA, 'proto.abf'))
def test_model(self): i = formats.importer('channelml') self.assertTrue(i.supports_model()) m = i.model(os.path.join(myotest.DIR_DATA, '43.channelml')) m.validate()
def test_model_nesting(self): # The corrias model has multiple levels of nesting (encapsulation) i = formats.importer('cellml') self.assertTrue(i.supports_model()) m = i.model(os.path.join(myotest.DIR_DATA, 'corrias.cellml')) m.validate()
def test_model_1_0_dot(self): # This is beeler-reuter but with a dot() in an expression i = formats.importer('cellml') m = i.model(os.path.join(DIR, 'br-1977-dot.cellml')) m.validate()
def test_model_simple(self): # Beeler-Reuter is a simple model i = formats.importer('cellml') self.assertTrue(i.supports_model()) m = i.model(os.path.join(myotest.DIR_DATA, 'br-1977.cellml')) m.validate()