diff --git a/src/Mod/Fem/femtest/testccxtools.py b/src/Mod/Fem/femtest/testccxtools.py index 49195a3885..cfde7dbd13 100644 --- a/src/Mod/Fem/femtest/testccxtools.py +++ b/src/Mod/Fem/femtest/testccxtools.py @@ -31,6 +31,8 @@ import unittest from . import utilstest as testtools from .utilstest import fcc_print +from os.path import join + class TestCcxTools(unittest.TestCase): fcc_print('import TestCcxTools') @@ -46,7 +48,7 @@ class TestCcxTools(unittest.TestCase): self.active_doc = FreeCAD.ActiveDocument self.mesh_name = 'Mesh' self.temp_dir = testtools.get_fem_test_tmp_dir() - self.test_file_dir = testtools.get_fem_test_home_dir() + 'ccx/' + self.test_file_dir = join(testtools.get_fem_test_home_dir(), 'ccx') def test_1_static_analysis(self): fcc_print('--------------- Start of FEM tests ---------------') @@ -119,33 +121,38 @@ class TestCcxTools(unittest.TestCase): self.active_doc.recompute() - static_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_static/') + static_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_static') fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True) fea.update_objects() fcc_print('Setting up working directory {}'.format(static_analysis_dir)) fea.setup_working_dir(static_analysis_dir) - self.assertTrue(True if fea.working_dir == static_analysis_dir else False, + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == static_analysis_dir + '/' else False, "Setting working directory {} failed".format(static_analysis_dir)) fcc_print('Checking FEM inp file prerequisites for static analysis...') error = fea.check_prerequisites() self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error)) + static_base_name = 'cube_static' + inpfile_given = join(self.test_file_dir, (static_base_name + '.inp')) + inpfile_totest = join(static_analysis_dir, (self.mesh_name + '.inp')) fcc_print('Checking FEM inp file write...') - fcc_print('Writing {}/{}.inp for static analysis'.format(static_analysis_dir, self.mesh_name)) + fcc_print('Writing {} for static analysis'.format(inpfile_totest)) error = fea.write_inp_file() self.assertFalse(error, "Writing failed") - static_base_name = 'cube_static' - static_analysis_inp_file = self.test_file_dir + static_base_name + '.inp' - fcc_print('Comparing {} to {}/{}.inp'.format(static_analysis_inp_file, static_analysis_dir, self.mesh_name)) - ret = testtools.compare_inp_files(static_analysis_inp_file, static_analysis_dir + self.mesh_name + '.inp') + fcc_print('Comparing {} to {}'.format(inpfile_given, inpfile_totest)) + ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) fcc_print('Setting up working directory to {} in order to read simulated calculations'.format(self.test_file_dir)) fea.setup_working_dir(self.test_file_dir) - self.assertTrue(True if fea.working_dir == self.test_file_dir else False, + fcc_print(fea.working_dir) + fcc_print(self.test_file_dir) + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == self.test_file_dir + '/' else False, "Setting working directory {} failed".format(self.test_file_dir)) fcc_print('Setting base name to read test {}.frd file...'.format('cube_static')) @@ -155,15 +162,15 @@ class TestCcxTools(unittest.TestCase): fcc_print('Setting inp file name to read test {}.frd file...'.format('cube_static')) fea.set_inp_file_name() - self.assertTrue(True if fea.inp_file_name == static_analysis_inp_file else False, - "Setting inp file name to {} failed".format(static_analysis_inp_file)) + self.assertTrue(True if fea.inp_file_name == inpfile_given else False, + "Setting inp file name to {} failed".format(inpfile_given)) fcc_print('Checking FEM frd file read from static analysis...') fea.load_results() self.assertTrue(fea.results_present, "Cannot read results from {}.frd frd file".format(fea.base_name)) fcc_print('Reading stats from result object for static analysis...') - static_expected_values = self.test_file_dir + "cube_static_expected_values" + static_expected_values = join(self.test_file_dir, "cube_static_expected_values") ret = testtools.compare_stats(fea, static_expected_values, 'CalculiX_static_results') self.assertFalse(ret, "Invalid results read from .frd file") @@ -265,14 +272,16 @@ class TestCcxTools(unittest.TestCase): error = fea.check_prerequisites() self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error)) + static_base_name = 'multimat' + inpfile_given = join(self.test_file_dir, (static_base_name + '.inp')) + inpfile_totest = join(static_multiplemat_dir, (self.mesh_name + '.inp')) fcc_print('Checking FEM inp file write...') - fcc_print('Writing {}/{}.inp for static multiple material'.format(static_multiplemat_dir, self.mesh_name)) + fcc_print('Writing {} for static multiple material'.format(inpfile_totest)) error = fea.write_inp_file() self.assertFalse(error, "Writing failed") - static_base_name = 'multimat' - static_analysis_inp_file = self.test_file_dir + static_base_name + '.inp' - fcc_print('Comparing {} to {}/{}.inp'.format(static_analysis_inp_file, static_multiplemat_dir, self.mesh_name)) - ret = testtools.compare_inp_files(static_analysis_inp_file, static_multiplemat_dir + self.mesh_name + '.inp') + + fcc_print('Comparing {} to {}'.format(inpfile_given, inpfile_totest)) + ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) static_save_fc_file = static_multiplemat_dir + static_base_name + '.FCStd' @@ -326,33 +335,36 @@ class TestCcxTools(unittest.TestCase): self.active_doc.recompute() - frequency_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_frequency/') + frequency_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_frequency') fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True) fea.update_objects() fcc_print('Setting up working directory {}'.format(frequency_analysis_dir)) fea.setup_working_dir(frequency_analysis_dir) - self.assertTrue(True if fea.working_dir == frequency_analysis_dir else False, + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == frequency_analysis_dir + '/' else False, "Setting working directory {} failed".format(frequency_analysis_dir)) fcc_print('Checking FEM inp file prerequisites for frequency analysis...') error = fea.check_prerequisites() self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error)) + frequency_base_name = 'cube_frequency' + inpfile_given = join(self.test_file_dir, (frequency_base_name + '.inp')) + inpfile_totest = join(frequency_analysis_dir, (self.mesh_name + '.inp')) fcc_print('Checking FEM inp file write...') - fcc_print('Writing {}/{}.inp for frequency analysis'.format(frequency_analysis_dir, self.mesh_name)) + fcc_print('Writing {} for frequency analysis'.format(inpfile_totest)) error = fea.write_inp_file() self.assertFalse(error, "Writing failed") - frequency_base_name = 'cube_frequency' - frequency_analysis_inp_file = self.test_file_dir + frequency_base_name + '.inp' - fcc_print('Comparing {} to {}/{}.inp'.format(frequency_analysis_inp_file, frequency_analysis_dir, self.mesh_name)) - ret = testtools.compare_inp_files(frequency_analysis_inp_file, frequency_analysis_dir + self.mesh_name + '.inp') + fcc_print('Comparing {} to {}'.format(inpfile_given, inpfile_totest)) + ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) fcc_print('Setting up working directory to {} in order to read simulated calculations'.format(self.test_file_dir)) fea.setup_working_dir(self.test_file_dir) - self.assertTrue(True if fea.working_dir == self.test_file_dir else False, + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == self.test_file_dir + '/' else False, "Setting working directory {} failed".format(self.test_file_dir)) fcc_print('Setting base name to read test {}.frd file...'.format(frequency_base_name)) @@ -362,15 +374,15 @@ class TestCcxTools(unittest.TestCase): fcc_print('Setting inp file name to read test {}.frd file...'.format('cube_frequency')) fea.set_inp_file_name() - self.assertTrue(True if fea.inp_file_name == frequency_analysis_inp_file else False, - "Setting inp file name to {} failed".format(frequency_analysis_inp_file)) + self.assertTrue(True if fea.inp_file_name == inpfile_given else False, + "Setting inp file name to {} failed".format(inpfile_given)) fcc_print('Checking FEM frd file read from frequency analysis...') fea.load_results() self.assertTrue(fea.results_present, "Cannot read results from {}.frd frd file".format(fea.base_name)) fcc_print('Reading stats from result object for frequency analysis...') - frequency_expected_values = self.test_file_dir + "cube_frequency_expected_values" + frequency_expected_values = join(self.test_file_dir, "cube_frequency_expected_values") ret = testtools.compare_stats(fea, frequency_expected_values, 'CalculiX_frequency_mode_1_results') self.assertFalse(ret, "Invalid results read from .frd file") @@ -456,33 +468,36 @@ class TestCcxTools(unittest.TestCase): self.active_doc.recompute() - thermomech_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_thermomech/') + thermomech_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_thermomech') fea = ccxtools.FemToolsCcx(analysis, test_mode=True) fea.update_objects() fcc_print('Setting up working directory {}'.format(thermomech_analysis_dir)) fea.setup_working_dir(thermomech_analysis_dir) - self.assertTrue(True if fea.working_dir == thermomech_analysis_dir else False, + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == thermomech_analysis_dir + '/' else False, "Setting working directory {} failed".format(thermomech_analysis_dir)) fcc_print('Checking FEM inp file prerequisites for thermo-mechanical analysis...') error = fea.check_prerequisites() self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error)) + thermomech_base_name = 'spine_thermomech' + inpfile_given = join(self.test_file_dir, (thermomech_base_name + '.inp')) + inpfile_totest = join(thermomech_analysis_dir, (self.mesh_name + '.inp')) fcc_print('Checking FEM inp file write...') - fcc_print('Writing {}/{}.inp for thermomech analysis'.format(thermomech_analysis_dir, self.mesh_name)) + fcc_print('Writing {} for thermomech analysis'.format(inpfile_totest)) error = fea.write_inp_file() self.assertFalse(error, "Writing failed") - thermomech_base_name = 'spine_thermomech' - thermomech_analysis_inp_file = self.test_file_dir + thermomech_base_name + '.inp' - fcc_print('Comparing {} to {}/{}.inp'.format(thermomech_analysis_inp_file, thermomech_analysis_dir, self.mesh_name)) - ret = testtools.compare_inp_files(thermomech_analysis_inp_file, thermomech_analysis_dir + self.mesh_name + '.inp') + fcc_print('Comparing {} to {}'.format(inpfile_given, inpfile_totest)) + ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) fcc_print('Setting up working directory to {} in order to read simulated calculations'.format(self.test_file_dir)) fea.setup_working_dir(self.test_file_dir) - self.assertTrue(True if fea.working_dir == self.test_file_dir else False, + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == self.test_file_dir + '/' else False, "Setting working directory {} failed".format(self.test_file_dir)) fcc_print('Setting base name to read test {}.frd file...'.format('spine_thermomech')) @@ -492,15 +507,15 @@ class TestCcxTools(unittest.TestCase): fcc_print('Setting inp file name to read test {}.frd file...'.format('spine_thermomech')) fea.set_inp_file_name() - self.assertTrue(True if fea.inp_file_name == thermomech_analysis_inp_file else False, - "Setting inp file name to {} failed".format(thermomech_analysis_inp_file)) + self.assertTrue(True if fea.inp_file_name == inpfile_given else False, + "Setting inp file name to {} failed".format(inpfile_given)) fcc_print('Checking FEM frd file read from thermomech analysis...') fea.load_results() self.assertTrue(fea.results_present, "Cannot read results from {}.frd frd file".format(fea.base_name)) fcc_print('Reading stats from result object for thermomech analysis...') - thermomech_expected_values = self.test_file_dir + "spine_thermomech_expected_values" + thermomech_expected_values = join(self.test_file_dir, "spine_thermomech_expected_values") ret = testtools.compare_stats(fea, thermomech_expected_values, 'CalculiX_thermomech_results') self.assertFalse(ret, "Invalid results read from .frd file") @@ -706,33 +721,36 @@ class TestCcxTools(unittest.TestCase): self.active_doc.recompute() - Flow1D_thermomech_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_Flow1D_thermomech/') + Flow1D_thermomech_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_Flow1D_thermomech') fea = ccxtools.FemToolsCcx(analysis, test_mode=True) fea.update_objects() fcc_print('Setting up working directory {}'.format(Flow1D_thermomech_analysis_dir)) fea.setup_working_dir(Flow1D_thermomech_analysis_dir) - self.assertTrue(True if fea.working_dir == Flow1D_thermomech_analysis_dir else False, + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == Flow1D_thermomech_analysis_dir + '/' else False, "Setting working directory {} failed".format(Flow1D_thermomech_analysis_dir)) fcc_print('Checking FEM inp file prerequisites for thermo-mechanical analysis...') error = fea.check_prerequisites() self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error)) + Flow1D_thermomech_base_name = 'Flow1D_thermomech' + inpfile_given = join(self.test_file_dir, (Flow1D_thermomech_base_name + '.inp')) + inpfile_totest = join(Flow1D_thermomech_analysis_dir, (self.mesh_name + '.inp')) fcc_print('Checking FEM inp file write...') - fcc_print('Writing {}/{}.inp for thermomech analysis'.format(Flow1D_thermomech_analysis_dir, self.mesh_name)) + fcc_print('Writing {} for thermomech analysis'.format(inpfile_totest)) error = fea.write_inp_file() self.assertFalse(error, "Writing failed") - Flow1D_thermomech_base_name = 'Flow1D_thermomech' - Flow1D_thermomech_analysis_inp_file = self.test_file_dir + Flow1D_thermomech_base_name + '.inp' - fcc_print('Comparing {} to {}/{}.inp'.format(Flow1D_thermomech_analysis_inp_file, Flow1D_thermomech_analysis_dir, self.mesh_name)) - ret = testtools.compare_inp_files(Flow1D_thermomech_analysis_inp_file, Flow1D_thermomech_analysis_dir + self.mesh_name + '.inp') + fcc_print('Comparing {} to {}'.format(inpfile_given, inpfile_totest)) + ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) fcc_print('Setting up working directory to {} in order to read simulated calculations'.format(self.test_file_dir)) fea.setup_working_dir(self.test_file_dir) - self.assertTrue(True if fea.working_dir == self.test_file_dir else False, + # setup_working_dir adds an / TODO: fix + self.assertTrue(True if fea.working_dir == self.test_file_dir + '/' else False, "Setting working directory {} failed".format(self.test_file_dir)) fcc_print('Setting base name to read test {}.frd file...'.format('Flow1D_thermomech')) @@ -742,15 +760,15 @@ class TestCcxTools(unittest.TestCase): fcc_print('Setting inp file name to read test {}.frd file...'.format('Flow1D_thermomech')) fea.set_inp_file_name() - self.assertTrue(True if fea.inp_file_name == Flow1D_thermomech_analysis_inp_file else False, - "Setting inp file name to {} failed".format(Flow1D_thermomech_analysis_inp_file)) + self.assertTrue(True if fea.inp_file_name == inpfile_given else False, + "Setting inp file name to {} failed".format(inpfile_given)) fcc_print('Checking FEM frd file read from Flow1D thermomech analysis...') fea.load_results() self.assertTrue(fea.results_present, "Cannot read results from {}.frd frd file".format(fea.base_name)) fcc_print('Reading stats from result object for Flow1D thermomech analysis...') - Flow1D_thermomech_expected_values = self.test_file_dir + "Flow1D_thermomech_expected_values" + Flow1D_thermomech_expected_values = join(self.test_file_dir, "Flow1D_thermomech_expected_values") stat_types = ["U1", "U2", "U3", "Uabs", "Sabs", "MaxPrin", "MidPrin", "MinPrin", "MaxShear", "Peeq", "Temp", "MFlow", "NPress"] ret = testtools.compare_stats(fea, Flow1D_thermomech_expected_values, stat_types, 'CalculiX_thermomech_time_1_0_results') self.assertFalse(ret, "Invalid results read from .frd file") diff --git a/src/Mod/Fem/femtest/testcommon.py b/src/Mod/Fem/femtest/testcommon.py index a1b7de19dc..ea9c08fe84 100644 --- a/src/Mod/Fem/femtest/testcommon.py +++ b/src/Mod/Fem/femtest/testcommon.py @@ -29,6 +29,8 @@ import unittest from . import utilstest as testtools from .utilstest import fcc_print +from os.path import join + class TestFemCommon(unittest.TestCase): fcc_print('import TestFemCommon') @@ -74,10 +76,10 @@ class TestFemCommon(unittest.TestCase): pymodules += testtools.collect_python_modules('femcommands') pymodules += testtools.collect_python_modules('femguiobjects') pymodules += testtools.collect_python_modules('femsolver') - pymodules += testtools.collect_python_modules('femsolver/elmer') - pymodules += testtools.collect_python_modules('femsolver/elmer/equations') - pymodules += testtools.collect_python_modules('femsolver/z88') - pymodules += testtools.collect_python_modules('femsolver/calculix') + pymodules += testtools.collect_python_modules(join('femsolver', 'elmer')) + pymodules += testtools.collect_python_modules(join('femsolver', 'elmer', 'equations')) + pymodules += testtools.collect_python_modules(join('femsolver', 'z88')) + pymodules += testtools.collect_python_modules(join('femsolver', 'calculix')) # import all collected modules # fcc_print(pymodules) diff --git a/src/Mod/Fem/femtest/testmesh.py b/src/Mod/Fem/femtest/testmesh.py index e71d7b9358..74b7973072 100644 --- a/src/Mod/Fem/femtest/testmesh.py +++ b/src/Mod/Fem/femtest/testmesh.py @@ -29,6 +29,8 @@ import unittest from . import utilstest as testtools from .utilstest import fcc_print +from os.path import join + class TestMeshCommon(unittest.TestCase): fcc_print('import TestMeshCommon') @@ -152,8 +154,8 @@ class TestMeshEleTetra10(unittest.TestCase): self.active_doc = FreeCAD.ActiveDocument self.elem = 'tetra10' - self.base_testfile = testtools.get_fem_test_home_dir() + 'mesh/' + self.elem + '_mesh.' - self.base_outfile = testtools.get_fem_test_tmp_dir() + '/' + self.elem + '_mesh.' + self.base_testfile = join(testtools.get_fem_test_home_dir(), 'mesh', (self.elem + '_mesh.')) + self.base_outfile = join(testtools.get_fem_test_tmp_dir(), (self.elem + '_mesh.')) # 10 node tetrahedron --> tetra10 femmesh = Fem.FemMesh() femmesh.addNode(6, 12, 18, 1) diff --git a/src/Mod/Fem/femtest/testresult.py b/src/Mod/Fem/femtest/testresult.py index 34424be929..cbd88ab4fc 100644 --- a/src/Mod/Fem/femtest/testresult.py +++ b/src/Mod/Fem/femtest/testresult.py @@ -28,6 +28,8 @@ import unittest from . import utilstest as testtools from .utilstest import fcc_print +from os.path import join + class TestResult(unittest.TestCase): fcc_print('import TestResult') @@ -44,7 +46,7 @@ class TestResult(unittest.TestCase): def test_read_frd_massflow_networkpressure(self): # read data from frd file - frd_file = testtools.get_fem_test_home_dir() + 'ccx/Flow1D_thermomech.frd' + frd_file = join(testtools.get_fem_test_home_dir(), 'ccx', 'Flow1D_thermomech.frd') from feminout.importCcxFrdResults import read_frd_result as read_frd frd_content = read_frd(frd_file) diff --git a/src/Mod/Fem/femtest/testsolverframework.py b/src/Mod/Fem/femtest/testsolverframework.py index de1b5f50fa..e7a090afba 100644 --- a/src/Mod/Fem/femtest/testsolverframework.py +++ b/src/Mod/Fem/femtest/testsolverframework.py @@ -30,6 +30,8 @@ import unittest from . import utilstest as testtools from .utilstest import fcc_print +from os.path import join + class TestSolverFrameWork(unittest.TestCase): fcc_print('import TestSolverFrameWork') @@ -45,7 +47,7 @@ class TestSolverFrameWork(unittest.TestCase): self.active_doc = FreeCAD.ActiveDocument self.mesh_name = 'Mesh' self.temp_dir = testtools.get_fem_test_tmp_dir() - self.test_file_dir = testtools.get_fem_test_home_dir() + 'ccx/' + self.test_file_dir = join(testtools.get_fem_test_home_dir(), 'ccx') def test_solver_framework(self): fcc_print('\n--------------- Start of FEM tests solver frame work ---------------') @@ -106,6 +108,7 @@ class TestSolverFrameWork(unittest.TestCase): self.active_doc.recompute() # solver frame work ccx solver + # calculix solver object fcc_print('\nChecking FEM CalculiX solver for solver frame work...') solver_ccx_object = ObjectsFem.makeSolverCalculix(self.active_doc, 'SolverCalculiX') solver_ccx_object.AnalysisType = 'static' @@ -120,7 +123,9 @@ class TestSolverFrameWork(unittest.TestCase): analysis.addObject(solver_ccx_object) static_base_name = 'cube_static' - solverframework_analysis_dir = testtools.get_unit_test_tmp_dir(testtools.get_fem_test_tmp_dir(), 'FEM_solverframework/') + solverframework_analysis_dir = testtools.get_unit_test_tmp_dir(testtools.get_fem_test_tmp_dir(), 'FEM_solverframework') + + # write input file fcc_print('Checking FEM ccx solver for solver frame work......') fcc_print('machine_ccx') machine_ccx = solver_ccx_object.Proxy.createMachine(solver_ccx_object, solverframework_analysis_dir) @@ -128,12 +133,15 @@ class TestSolverFrameWork(unittest.TestCase): machine_ccx.target = femsolver.run.PREPARE machine_ccx.start() machine_ccx.join() # wait for the machine to finish. - static_analysis_inp_file = testtools.get_fem_test_home_dir() + 'ccx/' + static_base_name + '.inp' - fcc_print('Comparing {} to {}/{}.inp'.format(static_analysis_inp_file, solverframework_analysis_dir, self.mesh_name)) - ret = testtools.compare_inp_files(static_analysis_inp_file, solverframework_analysis_dir + self.mesh_name + '.inp') + + infile_given = join(testtools.get_fem_test_home_dir(), 'ccx', (static_base_name + '.inp')) + inpfile_totest = join(solverframework_analysis_dir, (self.mesh_name + '.inp')) + fcc_print('Comparing {} to {}'.format(infile_given, inpfile_totest)) + ret = testtools.compare_inp_files(infile_given, inpfile_totest) self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) # use solver frame work elmer solver + # elmer solver object solver_elmer_object = ObjectsFem.makeSolverElmer(self.active_doc, 'SolverElmer') self.assertTrue(solver_elmer_object, "FemTest of elmer solver failed") analysis.addObject(solver_elmer_object) @@ -153,6 +161,7 @@ class TestSolverFrameWork(unittest.TestCase): self.active_doc.removeObject(mesh_object.Name) # solver frame work Elmer solver + # write input files fcc_print('\nChecking FEM Elmer solver for solver frame work...') machine_elmer = solver_elmer_object.Proxy.createMachine(solver_elmer_object, solverframework_analysis_dir, True) fcc_print('Machine testmode: ' + str(machine_elmer.testmode)) @@ -160,20 +169,28 @@ class TestSolverFrameWork(unittest.TestCase): machine_elmer.start() machine_elmer.join() # wait for the machine to finish. - test_file_dir_elmer = testtools.get_fem_test_home_dir() + 'elmer/' + # compare startinfo, case and gmsh input files + test_file_dir_elmer = join(testtools.get_fem_test_home_dir(), 'elmer') + fcc_print('Test writing STARTINFO file') - fcc_print('Comparing {} to {}'.format(test_file_dir_elmer + 'ELMERSOLVER_STARTINFO', solverframework_analysis_dir + 'ELMERSOLVER_STARTINFO')) - ret = testtools.compare_files(test_file_dir_elmer + 'ELMERSOLVER_STARTINFO', solverframework_analysis_dir + 'ELMERSOLVER_STARTINFO') + startinfo_given = join(test_file_dir_elmer, 'ELMERSOLVER_STARTINFO') + startinfo_totest = join(solverframework_analysis_dir, 'ELMERSOLVER_STARTINFO') + fcc_print('Comparing {} to {}'.format(startinfo_given, startinfo_totest)) + ret = testtools.compare_files(startinfo_given, startinfo_totest) self.assertFalse(ret, "STARTINFO write file test failed.\n{}".format(ret)) fcc_print('Test writing case file') - fcc_print('Comparing {} to {}'.format(test_file_dir_elmer + 'case.sif', solverframework_analysis_dir + 'case.sif')) - ret = testtools.compare_files(test_file_dir_elmer + 'case.sif', solverframework_analysis_dir + 'case.sif') + casefile_given = join(test_file_dir_elmer, 'case.sif') + casefile_totest = join(solverframework_analysis_dir, 'case.sif') + fcc_print('Comparing {} to {}'.format(casefile_given, casefile_totest)) + ret = testtools.compare_files(casefile_given, casefile_totest) self.assertFalse(ret, "case write file test failed.\n{}".format(ret)) fcc_print('Test writing GMSH geo file') - fcc_print('Comparing {} to {}'.format(test_file_dir_elmer + 'group_mesh.geo', solverframework_analysis_dir + 'group_mesh.geo')) - ret = testtools.compare_files(test_file_dir_elmer + 'group_mesh.geo', solverframework_analysis_dir + 'group_mesh.geo') + gmshgeofile_given = join(test_file_dir_elmer, 'group_mesh.geo') + gmshgeofile_totest = join(solverframework_analysis_dir, 'group_mesh.geo') + fcc_print('Comparing {} to {}'.format(gmshgeofile_given, gmshgeofile_totest)) + ret = testtools.compare_files(gmshgeofile_given, gmshgeofile_totest) self.assertFalse(ret, "GMSH geo write file test failed.\n{}".format(ret)) save_fc_file = solverframework_analysis_dir + static_base_name + '.FCStd' diff --git a/src/Mod/Fem/femtest/utilstest.py b/src/Mod/Fem/femtest/utilstest.py index 8987c06f70..160661c910 100644 --- a/src/Mod/Fem/femtest/utilstest.py +++ b/src/Mod/Fem/femtest/utilstest.py @@ -31,21 +31,22 @@ import os import unittest import tempfile import FreeCAD +from os.path import join def get_fem_test_home_dir(): - return FreeCAD.getHomePath() + 'Mod/Fem/femtest/testfiles/' # getHomePath() returns path with backslash + return join(FreeCAD.getHomePath(), 'Mod', 'Fem', 'femtest', 'testfiles') def get_fem_test_tmp_dir(): - temp_dir = tempfile.gettempdir() + '/FEM_unittests/' # gettempdir() returns path without backslash + temp_dir = join(tempfile.gettempdir(), 'FEM_unittests') if not os.path.exists(temp_dir): os.makedirs(temp_dir) return(temp_dir) def get_unit_test_tmp_dir(temp_dir, unittestdir): - testdir = temp_dir + unittestdir + testdir = join(temp_dir, unittestdir) if not os.path.exists(testdir): os.makedirs(testdir) return testdir @@ -61,7 +62,7 @@ def get_defmake_count(fem_vtk_post=True): could also be done in bash with grep -c "def make" src/Mod/Fem/ObjectsFem.py ''' - name_modfile = FreeCAD.getHomePath() + 'Mod/Fem/ObjectsFem.py' + name_modfile = join(FreeCAD.getHomePath(), 'Mod', 'Fem', 'ObjectsFem.py') modfile = open(name_modfile, 'r') lines_modefile = modfile.readlines() modfile.close() @@ -164,9 +165,9 @@ def force_unix_line_ends(line_list): def collect_python_modules(femsubdir=None): if not femsubdir: - pydir = FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/' + pydir = join(FreeCAD.ConfigGet("AppHomePath"), 'Mod', 'Fem') else: - pydir = FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/' + femsubdir + '/' + pydir = join(FreeCAD.ConfigGet("AppHomePath"), 'Mod', 'Fem', femsubdir) collected_modules = [] fcc_print(pydir) for pyfile in sorted(os.listdir(pydir)): @@ -191,28 +192,28 @@ def all_test_files(): def cube_frequency(): testname = "femtest.testccxtools.TestCcxTools.test_3_freq_analysis" unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName(testname)) - return FreeCAD.open(get_fem_test_tmp_dir() + 'FEM_ccx_frequency/cube_frequency.FCStd') + return FreeCAD.open(join(get_fem_test_tmp_dir(), 'FEM_ccx_frequency', 'cube_frequency.FCStd')) def cube_static(): testname = "femtest.testccxtools.TestCcxTools.test_1_static_analysis" unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName(testname)) - return FreeCAD.open(get_fem_test_tmp_dir() + 'FEM_ccx_static/cube_static.FCStd') + return FreeCAD.open(join(get_fem_test_tmp_dir(), 'FEM_ccx_static', 'cube_static.FCStd')) def Flow1D_thermomech(): testname = "femtest.testccxtools.TestCcxTools.test_5_Flow1D_thermomech_analysis" unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName(testname)) - return FreeCAD.open(get_fem_test_tmp_dir() + 'FEM_ccx_Flow1D_thermomech/Flow1D_thermomech.FCStd') + return FreeCAD.open(join(get_fem_test_tmp_dir(), 'FEM_ccx_Flow1D_thermomech', 'Flow1D_thermomech.FCStd')) def multimat(): testname = "femtest.testccxtools.TestCcxTools.test_2_static_multiple_material" unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName(testname)) - return FreeCAD.open(get_fem_test_tmp_dir() + 'FEM_ccx_multimat/multimat.FCStd') + return FreeCAD.open(join(get_fem_test_tmp_dir(), 'FEM_ccx_multimat', 'multimat.FCStd')) def spine_thermomech(): testname = "femtest.testccxtools.TestCcxTools.test_4_thermomech_analysis" unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName(testname)) - return FreeCAD.open(get_fem_test_tmp_dir() + 'FEM_ccx_thermomech/spine_thermomech.FCStd') + return FreeCAD.open(join(get_fem_test_tmp_dir(), 'FEM_ccx_thermomech', 'spine_thermomech.FCStd'))