From d1f107f65614f23ec8e3445c907c34be6a0c4738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Br=C3=A6strup=20Sayoc?= Date: Mon, 25 Jul 2022 00:08:06 +0200 Subject: [PATCH] [TechDraw] Make hatch test a unittest --- src/Mod/TechDraw/CMakeLists.txt | 2 +- src/Mod/TechDraw/TDTest/DHatchTest.py | 60 ----------------------- src/Mod/TechDraw/TDTest/DrawHatchTest.py | 62 ++++++++++++++++++++++++ src/Mod/TechDraw/TestTechDrawApp.py | 10 +--- 4 files changed, 64 insertions(+), 70 deletions(-) delete mode 100644 src/Mod/TechDraw/TDTest/DHatchTest.py create mode 100644 src/Mod/TechDraw/TDTest/DrawHatchTest.py diff --git a/src/Mod/TechDraw/CMakeLists.txt b/src/Mod/TechDraw/CMakeLists.txt index 1f0e7e90cc..cea612d665 100644 --- a/src/Mod/TechDraw/CMakeLists.txt +++ b/src/Mod/TechDraw/CMakeLists.txt @@ -141,7 +141,7 @@ endif(BUILD_GUI) #unit test files SET(TDTest_SRCS TDTest/__init__.py - TDTest/DHatchTest.py + TDTest/DrawHatchTest.py TDTest/DProjGroupTest.py TDTest/DVAnnoSymImageTest.py TDTest/DVDimensionTest.py diff --git a/src/Mod/TechDraw/TDTest/DHatchTest.py b/src/Mod/TechDraw/TDTest/DHatchTest.py deleted file mode 100644 index d08bbf17e5..0000000000 --- a/src/Mod/TechDraw/TDTest/DHatchTest.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# test script for TechDraw module -# creates a page and 1 views -# adds a hatch area to view1 -from __future__ import print_function - -import FreeCAD -import os - - -def DHatchTest(): - path = os.path.dirname(os.path.abspath(__file__)) - print("TDHatch path: " + path) - templateFileSpec = path + "/TestTemplate.svg" - hatchFileSpec = path + "/TestHatch.svg" - - FreeCAD.newDocument("TDHatch") - FreeCAD.setActiveDocument("TDHatch") - FreeCAD.ActiveDocument = FreeCAD.getDocument("TDHatch") - - # make source feature - box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box") - - # make a page - page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page") - FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template") - FreeCAD.ActiveDocument.Template.Template = templateFileSpec - FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template - page.Scale = 5.0 - # page.ViewObject.show() #unit tests run in console mode - - # make Views - view1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View") - FreeCAD.ActiveDocument.View.Source = [box] - page.addView(view1) - FreeCAD.ActiveDocument.recompute() - - # make hatch - print("making hatch") - hatch = FreeCAD.ActiveDocument.addObject("TechDraw::DrawHatch", "Hatch") - hatch.Source = (view1, ["Face0"]) - hatch.HatchPattern = hatchFileSpec # comment out to use default from preferences - print("adding hatch to page") - page.addView(hatch) - print("finished hatch") - - FreeCAD.ActiveDocument.recompute() - - rc = False - if "Up-to-date" in hatch.State: - rc = True - - FreeCAD.closeDocument("TDHatch") - return rc - - -if __name__ == "__main__": - DHatchTest() diff --git a/src/Mod/TechDraw/TDTest/DrawHatchTest.py b/src/Mod/TechDraw/TDTest/DrawHatchTest.py new file mode 100644 index 0000000000..c28f0653ba --- /dev/null +++ b/src/Mod/TechDraw/TDTest/DrawHatchTest.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import print_function + +import FreeCAD +import os +import unittest + + +class DrawHatchTest(unittest.TestCase): + def setUp(self): + """Creates a page and view""" + self.path = os.path.dirname(os.path.abspath(__file__)) + print("TDHatch path: " + self.path) + templateFileSpec = self.path + "/TestTemplate.svg" + + FreeCAD.newDocument("TDHatch") + FreeCAD.setActiveDocument("TDHatch") + FreeCAD.ActiveDocument = FreeCAD.getDocument("TDHatch") + + # make source feature + box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box") + + # make a page + self.page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page") + FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template") + FreeCAD.ActiveDocument.Template.Template = templateFileSpec + FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template + self.page.Scale = 5.0 + # page.ViewObject.show() #unit tests run in console mode + + # make Views + self.view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View") + FreeCAD.ActiveDocument.View.Source = [box] + self.page.addView(self.view) + FreeCAD.ActiveDocument.recompute() + + def tearDown(self): + FreeCAD.closeDocument("TDHatch") + + def testMakeHatchCase(self): + """Tests if hatch area can be added to view""" + # make hatch + print("making hatch") + hatch = FreeCAD.ActiveDocument.addObject("TechDraw::DrawHatch", "Hatch") + hatch.Source = (self.view, ["Face0"]) + hatchFileSpec = self.path + "/TestHatch.svg" + # comment out to use default from preferences + hatch.HatchPattern = ( + hatchFileSpec + ) + print("adding hatch to page") + self.page.addView(hatch) + print("finished hatch") + FreeCAD.ActiveDocument.recompute() + + self.assertTrue("Up-to-date" in hatch.State) + + +if __name__ == "__main__": + unittest.main() diff --git a/src/Mod/TechDraw/TestTechDrawApp.py b/src/Mod/TechDraw/TestTechDrawApp.py index 75ca9bc258..f2585d459d 100644 --- a/src/Mod/TechDraw/TestTechDrawApp.py +++ b/src/Mod/TechDraw/TestTechDrawApp.py @@ -22,7 +22,7 @@ import unittest -from TDTest.DHatchTest import DHatchTest +from TDTest.DrawHatchTest import DrawHatchTest # noqa: F401 from TDTest.DProjGroupTest import DProjGroupTest from TDTest.DVAnnoSymImageTest import DVAnnoSymImageTest from TDTest.DVDimensionTest import DVDimensionTest @@ -44,14 +44,6 @@ class TechDrawTestCases(unittest.TestCase): else: print("TD DrawViewPart test failed") - def testHatchCase(self): - print("starting TD DrawHatch test") - rc = DHatchTest() - if rc: - print("TD DrawHatch test passed") - else: - print("TD DrawHatch test failed") - def testAnnoSymImageCase(self): print("starting TD DrawAnno/Sym/Image test") rc = DVAnnoSymImageTest()