def test_setSinglePackage(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) rt.include_fmu_tests(True) self.assertEqual(0, rt.get_number_of_tests())
def _runUnitTests(batch, tool, package, path, n_pro, show_gui, skip_verification): import buildingspy.development.regressiontest as u ut = u.Tester(tool=tool, skip_verification=skip_verification) ut.batchMode(batch) ut.setLibraryRoot(path) if package is not None: ut.setSinglePackage(package) ut.setNumberOfThreads(n_pro) ut.pedanticModelica(True) ut.showGUI(show_gui) # Below are some option that may occassionally be used. # These are currently not exposed as command line arguments. # ut.setNumberOfThreads(1) # ut.deleteTemporaryDirectories(False) # ut.useExistingResults(['/tmp/tmp-Buildings-0-fagmeZ']) # ut.writeOpenModelicaResultDictionary() # Run the regression tests retVal = ut.run() # Display HTML report if not run in batch mode. # (For buildingspy.__version__ >= 2) if not batch: try: if not skip_verification: ut.report() except AttributeError: pass return retVal
def test_regressiontest(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) # Verify that invalid packages raise a ValueError. self.assertRaises(ValueError, rt.setSinglePackage, "this.package.does.not.exist")
def _runUnitTests(batch, tool, package, path, n_pro, show_gui): import buildingspy.development.regressiontest as u ut = u.Tester(tool=tool) ut.batchMode(batch) ut.setLibraryRoot(path) if package is not None: ut.setSinglePackage(package) ut.setNumberOfThreads(n_pro) ut.pedanticModelica(False) ut.showGUI(show_gui) # ut.get_test_example_coverage() # Below are some option that may occassionally be used. # These are currently not exposed as command line arguments. # ut.setNumberOfThreads(1) # ut.deleteTemporaryDirectories(False) # ut.useExistingResults(['/tmp/tmp-Buildings-0-fagmeZ']) # ut.writeOpenModelicaResultDictionary() # Run the regression tests retVal = ut.run() # comment out this line for local usage ut.get_test_example_coverage() return retVal
def test_test_OpenModelica(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) rt._deleteTemporaryDirectories = False myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) rt.test_OpenModelica(simulate=True)
def isValidLibrary(lib_home): import buildingspy.development.regressiontest as t try: t.Tester().isValidLibrary(lib_home) except ValueError as e: s = "{!s}\n Did not do anything.".format(e.args[0]) raise ValueError(s)
def _runOpenModelicaUnitTests(): import buildingspy.development.regressiontest as u ut = u.Tester() ut.batchMode(batch) ut.test_OpenModelica(cmpl=True, simulate=True, packages=['Examples'], number=-1)
def _run_coverage_only(batch, tool, package, path): # Specifies which models are tested import buildingspy.development.regressiontest as u ut = u.Tester(tool=tool) ut.batchMode(batch) ut.setLibraryRoot(path) if package is not None: ut.setSinglePackage(package) ut.get_test_example_coverage() return 0
def test_setExcludeTest(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") skpFil = os.path.join(myMoLib, "Resources", "Scripts", "skipUnitTestList.txt") rt.setLibraryRoot(myMoLib) rt.setExcludeTest(skpFil) rt.run() self.assertEqual(1, rt.get_number_of_tests())
def test_setSinglePackage_4(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) rt.include_fmu_tests(True) # No new tests should be found as FMUs is a subdirectory of Examples. self.assertRaises( ValueError, rt.setSinglePackage, "MyModelicaLibrary.Examples,MyModelicaLibrary.Examples.FMUs")
def test_setLibraryRoot(self): import buildingspy.development.regressiontest as r rt = r.Tester() myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") # This call should succeed, even if used twice rt.setLibraryRoot(myMoLib) rt.setLibraryRoot(myMoLib) # This call must raise an exception self.assertRaises(ValueError, \ rt.setLibraryRoot, "this_is_not_the_root_dir_of_a_library")
def _runUnitTests(): import buildingspy.development.regressiontest as u ut = u.Tester() ut.batchMode(batch) # ut.setNumberOfThreads(1) # ut.deleteTemporaryDirectories(False) # ut.useExistingResults(['/tmp/tmp-Buildings-0-fagmeZ']) # #print ut.getDataDictionary() # ut.setSinglePackage("Annex60.Fluid.MassExchangers") retVal = ut.run() exit(retVal)
def test_regressiontest(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False, tool="jmodelica") myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.deleteTemporaryDirectories(True) rt.setLibraryRoot(myMoLib) ret_val = rt.run() # Check return value to see if test suceeded self.assertEqual(0, ret_val, "Test failed with return value {}".format(ret_val)) # Delete temporary files os.remove(rt.get_unit_test_log_file())
def test_regressiontest(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) rt.include_fmu_tests(True) rt.writeOpenModelicaResultDictionary() ret_val = rt.run() # Check return value to see if test suceeded self.assertEqual(0, ret_val, "Test failed with return value {}".format(ret_val)) # Delete temporary files os.remove(rt.get_unit_test_log_file())
def _CreateIBPSALog(self): from dymola.dymola_interface import DymolaInterface from dymola.dymola_exception import DymolaException import buildingspy.development.regressiontest as u """ Check the IBPSA Model Automatical """ cmd = "git clone https://github.com/ibpsa/modelica-ibpsa.git" returned_value = os.system(cmd) # returns the exit code in unix print('returned value:', returned_value) cmd = "cd modelica-ibpsa-master" os.system(cmd) Library = IBPSA/package.mo ut = u.Tester(tool = self.tool) ### Set Number of Threads ut.setNumberOfThreads(self.n_pro) ### Set GUI Show ut.showGUI(self.show_gui) ### Set in Batch Mode ut.batchMode(self.batch) ### Sets the Dymola path to activate the GUI dymola = DymolaInterface(dymolapath="/usr/local/bin/dymola") ### Writes all information in the log file, not only the last entries dymola.ExecuteCommand("Advanced.TranslationInCommandLog:=true;") dym_sta_lic_available = dymola.ExecuteCommand('RequestOption("Standard");') if not dym_sta_lic_available: dymola.ExecuteCommand('DymolaCommands.System.savelog("Log_NO_DYM_STANDARD_LIC_AVAILABLE.txt");') print("No Dymola License is available") dymola.close() exit(1) else: print("Dymola License is available") PackageCheck = dymola.openModel(Library) if PackageCheck == True: print("Found AixLib Library and start Checkmodel Tests \n Check Package " + self.Package+" \n") elif PackageCheck == None: print("Library Path is wrong. Please Check Path of AixLib Library Path") exit(1) result=dymola.checkModel(self.Package) dymola.savelog(self.Package+"-log.txt") Log = dymola.getLastError() if result == True: print('\n Check of Package '+self.Package+' was Successful! \n') dymola.close() #exit(0) if result == False: print('\n ModelCheck Failed in Package ' + self.Package+ ' Show Savelog \n') print(Log) dymola.clearlog() dymola.close()
def _run_coverage_only(batch, tool, package, path, n_pro, show_gui): import buildingspy.development.regressiontest as u ut = u.Tester(tool=tool) ut.batchMode(batch) ut.setLibraryRoot(path) if package is not None: ut.setSinglePackage(package) # ut.setNumberOfThreads(n_pro) # ut.pedanticModelica(True) # ut.showGUI(show_gui) ut.get_test_example_coverage() return 0
def test_format_float(self): import buildingspy.development.regressiontest as r rt = r.Tester() self.assertEqual(float(rt.format_float(1.0)), float(1)) self.assertEqual(float(rt.format_float(0.5)), float(0.5)) self.assertEqual(float(rt.format_float(1.234)), float(1.234)) self.assertEqual(float(rt.format_float(100)), float(100)) self.assertEqual(float(rt.format_float(100.)), float(100.)) self.assertEqual(float(rt.format_float(100.01230)), float(100.01230)) self.assertEqual(float(rt.format_float(-100.01230)), float(-100.01230)) self.assertEqual(float(rt.format_float(-100.0123)), float(-100.0123))
def test_statistics_are_equal(self): import buildingspy.development.regressiontest as r rt = r.Tester() self.assertTrue(rt.are_statistics_equal("0", "0")) self.assertTrue(rt.are_statistics_equal("", "")) self.assertTrue(rt.are_statistics_equal(" ", " ")) self.assertFalse(rt.are_statistics_equal(" ", "0")) self.assertFalse(rt.are_statistics_equal("1", "1 1")) # 1, 2 is equal to 2, 1 self.assertTrue(rt.are_statistics_equal("1, 2", "2, 1")) self.assertTrue(rt.are_statistics_equal("1, 40, 2", "2, 1, 40")) self.assertFalse(rt.are_statistics_equal("1, 40", "1, 40, 0"))
def test_regressiontest(self): import os import buildingspy.development.regressiontest as r rt = r.Tester() myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) rt.run() # Delete temporary files os.remove('dymola.log') os.remove('unitTests.log') # Verify that invalid packages raise a ValueError. self.assertRaises(ValueError, rt.setSinglePackage, "this.package.does.not.exist")
def test_regressiontest(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) rt.include_fmu_tests(True) rt.writeOpenModelicaResultDictionary() rt.run() # Delete temporary files os.remove('unitTests.log') # Verify that invalid packages raise a ValueError. self.assertRaises(ValueError, rt.setSinglePackage, "this.package.does.not.exist")
def test_setExcludeTest(self): import buildingspy.development.regressiontest as r print("*** Running test_setExcludeTest that excludes files from unit test.\n") rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") skpFil = os.path.join(myMoLib, "Resources", "Scripts", "skipUnitTestList.txt") rt.setLibraryRoot(myMoLib) rt.setExcludeTest(skpFil) ret_val = rt.run() # Check return value to see if test suceeded # ret_val must be two because excluding files triggers a warning. self.assertEqual( 2, ret_val, "Test failed with return value {}, expected 2.".format(ret_val)) # Check for correct number of tests self.assertEqual(1, rt.get_number_of_tests())
def _runUnitTests(batch, single_package, n_pro): import buildingspy.development.regressiontest as u ut = u.Tester() ut.batchMode(batch) if single_package is not None: ut.setSinglePackage(single_package) ut.setNumberOfThreads(n_pro) ut.pedanticModelica(True) # Below are some option that may occassionally be used. # These are currently not exposed as command line arguments. # ut.setNumberOfThreads(1) # ut.deleteTemporaryDirectories(False) # ut.useExistingResults(['/tmp/tmp-Buildings-0-fagmeZ']) # Run the regression tests retVal = ut.run() return retVal
def test_areResultsEqual(self): import buildingspy.development.regressiontest as r rt = r.Tester() tMin = 10 tMax = 50 nPoi = 101 tOld = [tMin, tMax] yOld = [10, 10] tNew = [tMin + float(i) / (nPoi - 1) * (tMax - tMin) for i in range(nPoi)] yNew = [10.0 for i in range(nPoi)] varNam = "testVariable" filNam = "testFilename" (equ, _, _) = rt.areResultsEqual(tOld, yOld, tNew, yNew, varNam, filNam) self.assertTrue(equ, "Test 1 for equality failed.") # Test with arguments reversed. (equ, _, _) = rt.areResultsEqual(tNew, yNew, tOld, yOld, varNam, filNam) self.assertTrue(equ, "Test 2 for equality failed.") # Modify arguments, now both tests should return false yNew[2] = 11.0 (equ, timMaxErr, _) = rt.areResultsEqual(tOld, yOld, tNew, yNew, varNam, filNam) self.assertFalse(equ, "Test 1 for equality should have returned false.") self.assertEqual(tNew[2], timMaxErr, "Time of maximum error is wrong for test 1.") # Test with arguments reversed. (equ, timMaxErr, _) = rt.areResultsEqual(tNew, yNew, tOld, yOld, varNam, filNam) self.assertFalse(equ, "Test 2 for equality should have returned false.") self.assertEqual(tNew[2], timMaxErr, "Time of maximum error is wrong for test 2.") # Test the case where the simulation may have failed and hence the end # time is smaller than the end time of the reference results tNew = [tMin + float(i) / (nPoi - 1) * 0.9 * (tMax - tMin) for i in range(nPoi)] yNew = [10.0 for i in range(nPoi)] (equ, timMaxErr, _) = rt.areResultsEqual(tNew, yNew, tOld, yOld, varNam, filNam) self.assertFalse(equ, "Test with smaller simulation end time should have returned false.") # Test for different start time tNew = [0.1 + tMin + float(i) / (nPoi - 1) * (tMax - tMin) for i in range(nPoi)] (equ, timMaxErr, _) = rt.areResultsEqual(tNew, yNew, tOld, yOld, varNam, filNam) self.assertFalse(equ, "Test with smaller simulation start time should have returned false.")
def _runTests(tool, package, lib_dir, bp_dir): ''' Run regression test, return the temporary directory path for the test. ''' sys.path.insert(0, bp_dir) import buildingspy.development.regressiontest as u ut = u.Tester(tool=tool, skip_verification=True) ut.batchMode(True) ut.pedanticModelica(True) ut.showGUI(False) ut.deleteTemporaryDirectories(False) path = os.path.join(lib_dir, 'Buildings') ut.setLibraryRoot(path) if package is not None: ut.setSinglePackage(package) # Run the regression tests retVal = ut.run() # List of temporary directories that were used to run the simulations tempDir = ut._temDir return tempDir
def __init__(self, package, library, n_pro, tool, batch, show_gui, path): self.package = package self.library = library self.n_pro = n_pro self.tool = tool self.batch = batch self.show_gui = show_gui self.path = path sys.path.append('../bin/CITests') from _config import ref_file_dir, resource_dir, exit_file, ref_file, ref_whitelist_file, update_ref_file self.ref_file_path = ref_file_dir self.resource_file_path = resource_dir self.ref_whitelist = f'..{os.sep}{ref_whitelist_file}' self.update_ref_file = update_ref_file self.exit_file = f'..{os.sep}{exit_file}' self.ref_file = f'..{os.sep}{ref_file}' self.CRED = '\033[91m' # Color self.CEND = '\033[0m' self.green = "\033[0;32m" import buildingspy.development.regressiontest as u # Buildingspy self.ut = u.Tester(tool=self.tool)
def test_regressiontest_diagnostics(self): """ Test that warnings and errors reported by optimica are reported. """ import shutil import buildingspy.development.regressiontest as r tests = [{ 'ret_val': 0, 'mo_content': """parameter Real x = 0;""", 'description': "Correct model." }, { 'ret_val': 2, 'mo_content': """parameter Real[2] x(unit="m") = {0, 0};""", 'description': "Missing each on variable." }, { 'ret_val': 2, 'mo_content': """parameter Real x(each unit="m") = 0;""", 'description': "Wrong each on scalar." }, { 'ret_val': 2, 'mo_content': """Modelica.Blocks.Sources.Constant b(each k=0) ;""", 'description': "Wrong each on scalar component." }, { 'ret_val': 2, 'mo_content': """Modelica.Blocks.Sources.Constant b[2](k=0) ;""", 'description': "Missing each on array of components." }, { 'ret_val': 0, 'mo_content': """ Real x; equation Modelica.Math.exp(x)=1;""", 'description': "Missing start value, which should be ignored." }, { 'ret_val': 0, 'mo_content': """ Real x(start=0); equation der(x)^3 = 0;""", 'description': "Missing start value for der(x), which should be ignored." }, { 'ret_val': 2, 'mo_content': """parameter Real[2] x(unit="m") = {0, 0}; parameter Real y(each unit="m") = 0;""", 'description': "Two errors." }, { 'ret_val': 1, 'mo_content': """x; """, 'description': "Syntax error that should cause a failure in translation." }, { 'ret_val': 1, 'mo_content': """Real x(start=0); equation Modelica.Math.exp(x)=-1;""", 'description': "Model that has no solution." }] # Run all test cases for test in tests: des = test['description'] print("*** Running test for '{}'".format(des)) mo_content = test['mo_content'] dir_name = self._write_test(mo_content) rt = r.Tester(skip_verification=True, check_html=False, tool="optimica") rt.setLibraryRoot(dir_name) ret_val = rt.run() # Check return value to see if test suceeded self.assertEqual(test['ret_val'], ret_val, "Test for '{}' failed, return value {}".format( des, ret_val)) # Delete temporary files # Get parent dir of dir_name, because dir_name contains the Modelica library name par = os.path.split(dir_name)[0] os.remove(rt.get_unit_test_log_file()) shutil.rmtree(par)
def test_unit_test_log_file(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False, tool="optimica") self.assertEqual('unitTests-optimica.log', rt.get_unit_test_log_file())
def test_setDataDictionary(self): import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary") rt.setLibraryRoot(myMoLib) rt.setDataDictionary()
import os import buildingspy.development.regressiontest as r rt = r.Tester(check_html=False) myMoLib = os.path.join("TRANSFORM") rt.setLibraryRoot(myMoLib) #rt.showGUI(False) rt.setNumberOfThreads(2) rt.run()
@author: u0088104 """ import buildingspy as BP import buildingspy.development.regressiontest as r import os import sys # sys.path.append("E:\work\python\BuildingsPy") import buildingspy as BP import buildingspy.development.regressiontest as rt """ If this file is not ran from the Modelicalibrary home directory (which contains the package.mo-file) Set working directory to that directory. The working directory is copied to a temp directory where the simulations are run. Output from the temperorary directories is gathered and stored in the current directory under dymola.log. """ # os.chdir("E:\work\modelica\IDEAS\IDEAS") tester = r.Tester() """ number of parallel processes started.""" #tester.setSinglePackage("IBPSA.Fluid.Geothermal") #tester.setNumberOfThreads(4) """ Html validation on/off""" # tester.validate_html = False """ Run the unittest Outputs will be rendered""" tester.run()