def checkKisaoIntegrator(self, inline_omex, kisao, name): """ Helper function for checking kisao integrator. """ omex_file = os.path.join(self.test_dir, "test.omex") te.exportInlineOmex(inline_omex, omex_file) omex.extractCombineArchive(omex_file, directory=self.test_dir, method="zip") locations = omex.getLocationsByFormat(omex_file, "sed-ml") sedml_files = [os.path.join(self.test_dir, loc) for loc in locations] sedml_file = sedml_files[0] # check the SED-ML doc = libsedml.readSedMLFromFile(sedml_file) # test_str = libsedml.writeSedMLToString(doc) # print(test_str) simulation = doc.getSimulation('sim0') algorithm = simulation.getAlgorithm() assert algorithm.getKisaoID() == kisao # check the generated code pystr = tesedml.sedmlToPython(sedml_file, workingDir=self.test_dir) # is integrator/solver set in python code if simulation.getTypeCode() is libsedml.SEDML_SIMULATION_STEADYSTATE: assert ".setSteadyStateSolver('{}')".format(name) in pystr else: assert ".setIntegrator('{}')".format(name) in pystr
def checkKisaoIntegrator(self, inline_omex, kisao, name): """ Helper function for checking kisao integrator. """ omex_file = os.path.join(self.test_dir, "test.omex") te.exportInlineOmex(inline_omex, omex_file) omex.extractCombineArchive(omex_file, directory=self.test_dir, method="zip") locations = omex.getLocationsByFormat(omex_file, "sed-ml") sedml_files = [os.path.join(self.test_dir, loc) for loc in locations] sedml_file = sedml_files[0] # check the SED-ML doc = libsedml.readSedMLFromFile(sedml_file) # test_str = libsedml.writeSedMLToString(doc) # print(test_str) simulation = doc.getSimulation('sim0') algorithm = simulation.getAlgorithm() assert algorithm.getKisaoID() == kisao # check the generated code pystr = tesedml.sedmlToPython(sedml_file, workingDir=self.test_dir) # is integrator/solver set in python code if simulation.getTypeCode() is libsedml.SEDML_SIMULATION_STEADYSTATE: assert ".setSteadyStateSolver('{}')".format(name) in pystr else: assert ".setIntegrator('{}')".format(name) in pystr
def test_omex_extractCombineArchive4(tmpdir): tmp_dir = tempfile.mkdtemp() omex.extractCombineArchive(omexPath=OMEX_SHOWCASE, directory=str(tmpdir), method="omex") files = [ f for f in os.listdir(tmp_dir) if os.path.isfile(os.path.join(tmp_dir, f)) ] assert files is not None
def checkKisaoAlgorithmParameter(self, inline_omex, kisao, name, value): """ Helper function for checking kisao parameter. """ # check that set AlgorithmParameter set correctly in SED-ML omex_file = os.path.join(self.test_dir, "test.omex") te.exportInlineOmex(inline_omex, omex_file) omex.extractCombineArchive(omex_file, directory=self.test_dir, method="zip") locations = omex.getLocationsByFormat(omex_file, "sed-ml") sedml_files = [os.path.join(self.test_dir, loc) for loc in locations] sedml_file = sedml_files[0] doc = libsedml.readSedMLFromFile(sedml_file) simulation = doc.getSimulation('sim0') algorithm = simulation.getAlgorithm() pdict = { p.getKisaoID(): p for p in algorithm.getListOfAlgorithmParameters() } self.assertTrue(kisao in pdict) pkey = tesedml.SEDMLCodeFactory.algorithmParameterToParameterKey( pdict[kisao]) if pkey.dtype == str: self.assertEqual(pkey.value, value) else: # numerical parameter self.assertAlmostEqual(float(pkey.value), value) # check that integrator is set in python code pystr = tesedml.sedmlToPython(sedml_file, workingDir=self.test_dir) print(simulation.getElementName()) print(pystr) if simulation.getTypeCode() is libsedml.SEDML_SIMULATION_STEADYSTATE: if pkey.dtype == str: self.assertTrue( ".steadyStateSolver.setValue('{}', '{}')".format( name, value) in pystr) else: # numerical parameter self.assertTrue(".steadyStateSolver.setValue('{}', {})".format( name, value) in pystr) else: if pkey.dtype == str: self.assertTrue(".integrator.setValue('{}', '{}')".format( name, value) in pystr) else: # numerical parameter self.assertTrue(".integrator.setValue('{}', {})".format( name, value) in pystr)
def checkKisaoAlgorithmParameter(self, inline_omex, kisao, name, value): """ Helper function for checking kisao parameter. """ # check that set AlgorithmParameter set correctly in SED-ML omex_file = os.path.join(self.test_dir, "test.omex") te.exportInlineOmex(inline_omex, omex_file) omex.extractCombineArchive(omex_file, directory=self.test_dir, method="zip") locations = omex.getLocationsByFormat(omex_file, "sed-ml") sedml_files = [os.path.join(self.test_dir, loc) for loc in locations] sedml_file = sedml_files[0] doc = libsedml.readSedMLFromFile(sedml_file) simulation = doc.getSimulation('sim0') algorithm = simulation.getAlgorithm() pdict = {p.getKisaoID(): p for p in algorithm.getListOfAlgorithmParameters()} self.assertTrue(kisao in pdict) pkey = tesedml.SEDMLCodeFactory.algorithmParameterToParameterKey(pdict[kisao]) if pkey.dtype == str: self.assertEqual(pkey.value, value) else: # numerical parameter self.assertAlmostEqual(float(pkey.value), value) # check that integrator is set in python code pystr = tesedml.sedmlToPython(sedml_file, workingDir=self.test_dir) print(simulation.getElementName()) print(pystr) if simulation.getTypeCode() is libsedml.SEDML_SIMULATION_STEADYSTATE: if pkey.dtype == str: self.assertTrue(".steadyStateSolver.setValue('{}', '{}')".format(name, value) in pystr) else: # numerical parameter self.assertTrue(".steadyStateSolver.setValue('{}', {})".format(name, value) in pystr) else: if pkey.dtype == str: self.assertTrue(".integrator.setValue('{}', '{}')".format(name, value) in pystr) else: # numerical parameter self.assertTrue(".integrator.setValue('{}', {})".format(name, value) in pystr)
def test_omex_extractCombineArchive4(tmpdir): tmp_dir = tempfile.mkdtemp() omex.extractCombineArchive(omexPath=OMEX_SHOWCASE, directory=str(tmpdir), method="omex") files = [f for f in os.listdir(tmp_dir) if os.path.isfile(os.path.join(tmp_dir, f))] assert files is not None
def test_omex_extractCombineArchive2(tmpdir): omex.extractCombineArchive(omexPath=OMEX_SHOWCASE, directory=str(tmpdir), method="omex")