From aefffd74fb9518a991c8229308ffc281150d06c4 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sat, 23 May 2020 08:57:57 +0200 Subject: [PATCH] FEM: unit test, fix not closed documents --- src/Mod/Fem/femtest/app/test_open.py | 34 ++++++++++++++++------------ src/Mod/Fem/femtest/gui/test_open.py | 31 ++++++++++++++----------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/Mod/Fem/femtest/app/test_open.py b/src/Mod/Fem/femtest/app/test_open.py index 1b1a8de6f6..a003725f5d 100644 --- a/src/Mod/Fem/femtest/app/test_open.py +++ b/src/Mod/Fem/femtest/app/test_open.py @@ -76,9 +76,20 @@ class TestObjectOpen(unittest.TestCase): "open" ) + # ******************************************************************************************** + def tearDown( + self + ): + # tearDown is executed after every test + FreeCAD.closeDocument(self.document.Name) + + # ******************************************************************************************** def test_00print( self ): + # since method name starts with 00 this will be run first + # this test just prints a line with stars + fcc_print("\n{0}\n{1} run FEM TestObjectOpen tests {2}\n{0}".format( 100 * "*", 10 * "*", @@ -93,17 +104,18 @@ class TestObjectOpen(unittest.TestCase): # get a document with all FEM objects from .test_object import create_all_fem_objects_doc - doc = create_all_fem_objects_doc(self.document) + self.document = create_all_fem_objects_doc(self.document) # save and load the document file_path = join(tempfile.gettempdir(), "all_objects_head.FCStd") - doc.saveAs(file_path) + self.document.saveAs(file_path) + FreeCAD.closeDocument(self.document.Name) self.document = FreeCAD.open(file_path) # C++ objects - self.compare_cpp_objs(doc) + self.compare_cpp_objs(self.document) # FeaturePythons objects - self.compare_feature_pythons_class_app(doc) + self.compare_feature_pythons_class_app(self.document) # ******************************************************************************************** def test_femobjects_open_de9b3fb438( @@ -118,13 +130,13 @@ class TestObjectOpen(unittest.TestCase): # the document was created by running the object create unit test # FreeCAD --run-test "femtest.app.test_object.TestObjectCreate.test_femobjects_make" fcc_print("load old document objects") + FreeCAD.closeDocument(self.document.Name) # close the empty document from setUp first self.document = FreeCAD.open(join(self.test_file_dir, "all_objects_de9b3fb438.FCStd")) - doc = self.document # C++ objects - self.compare_cpp_objs(doc) + self.compare_cpp_objs(self.document) # FeaturePythons objects - self.compare_feature_pythons_class_app(doc) + self.compare_feature_pythons_class_app(self.document) # ******************************************************************************************** def compare_cpp_objs( @@ -329,14 +341,6 @@ class TestObjectOpen(unittest.TestCase): doc.Heat.Proxy.__class__ ) - # ******************************************************************************************** - def tearDown( - self - ): - # setUp is executed after every test - # FreeCAD.closeDocument(self.document.Name) - pass - """ # code was generated by the following code from a document with all objects diff --git a/src/Mod/Fem/femtest/gui/test_open.py b/src/Mod/Fem/femtest/gui/test_open.py index cd08c23ecc..4c7816d772 100644 --- a/src/Mod/Fem/femtest/gui/test_open.py +++ b/src/Mod/Fem/femtest/gui/test_open.py @@ -77,9 +77,20 @@ class TestObjectOpen(unittest.TestCase): "open" ) + # ******************************************************************************************** + def tearDown( + self + ): + # tearDown is executed after every test + FreeCAD.closeDocument(self.document.Name) + + # ******************************************************************************************** def test_00print( self ): + # since method name starts with 00 this will be run first + # this test just prints a line with stars + fcc_print("\n{0}\n{1} run FEM TestObjectOpen tests {2}\n{0}".format( 100 * "*", 10 * "*", @@ -93,15 +104,17 @@ class TestObjectOpen(unittest.TestCase): fcc_print("load master head document objects") # get a document with all FEM objects - doc = create_all_fem_objects_doc(self.document) + from femtest.app.test_object import create_all_fem_objects_doc + self.document = create_all_fem_objects_doc(self.document) # save and load the document file_path = join(tempfile.gettempdir(), "all_objects_head.FCStd") - doc.saveAs(file_path) + self.document.saveAs(file_path) + FreeCAD.closeDocument(self.document.Name) self.document = FreeCAD.open(file_path) # FeaturePythons view provider - self.compare_feature_pythons_class_gui(doc) + self.compare_feature_pythons_class_gui(self.document) # ******************************************************************************************** def test_femobjects_open_de9b3fb438( @@ -116,11 +129,11 @@ class TestObjectOpen(unittest.TestCase): # the document was created by running the object create unit test # FreeCAD --run-test "femtest.app.test_object.TestObjectCreate.test_femobjects_make" fcc_print("load old document objects") + FreeCAD.closeDocument(self.document.Name) # close the empty document from setUp first self.document = FreeCAD.open(join(self.test_file_dir, "all_objects_de9b3fb438.FCStd")) - doc = self.document # FeaturePythons view provider - self.compare_feature_pythons_class_gui(doc) + self.compare_feature_pythons_class_gui(self.document) # ******************************************************************************************** def compare_feature_pythons_class_gui( @@ -303,14 +316,6 @@ class TestObjectOpen(unittest.TestCase): doc.Heat.ViewObject.Proxy.__class__ ) - # ******************************************************************************************** - def tearDown( - self - ): - # setUp is executed after every test - # FreeCAD.closeDocument(self.document.Name) - pass - """ # code was generated by the following code from a document with all objects