diff --git a/src/Mod/TechDraw/CMakeLists.txt b/src/Mod/TechDraw/CMakeLists.txt index cc46644550..5551569069 100644 --- a/src/Mod/TechDraw/CMakeLists.txt +++ b/src/Mod/TechDraw/CMakeLists.txt @@ -149,7 +149,7 @@ SET(TDTest_SRCS TDTest/DrawViewDimensionTest.py TDTest/DrawViewPartTest.py TDTest/DrawViewSectionTest.py - TDTest/DVBalloonTest.py + TDTest/DrawViewBalloonTest.py TDTest/TechDrawTestUtilities.py ) diff --git a/src/Mod/TechDraw/TDTest/DVBalloonTest.py b/src/Mod/TechDraw/TDTest/DVBalloonTest.py deleted file mode 100644 index b02bce17ea..0000000000 --- a/src/Mod/TechDraw/TDTest/DVBalloonTest.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# test script for TechDraw module -# creates a page and 2 views -# adds 1 length dimension to view1 -# adds 1 radius dimension to view2 -from __future__ import print_function - -import FreeCAD -from FreeCAD import Units -import os - - -def DVBalloonTest(): - path = os.path.dirname(os.path.abspath(__file__)) - print("TDBalloon path: " + path) - templateFileSpec = path + "/TestTemplate.svg" - - FreeCAD.newDocument("TDBalloon") - FreeCAD.setActiveDocument("TDBalloon") - FreeCAD.ActiveDocument = FreeCAD.getDocument("TDBalloon") - - # make source feature - FreeCAD.ActiveDocument.addObject("Part::Box", "Box") - FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere") - - # 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 = [FreeCAD.ActiveDocument.Box] - page.addView(view1) - view1.X = Units.Quantity(30.0, Units.Length) - view1.Y = Units.Quantity(150.0, Units.Length) - view2 = FreeCAD.activeDocument().addObject("TechDraw::DrawViewPart", "View001") - FreeCAD.activeDocument().View001.Source = [FreeCAD.activeDocument().Sphere] - page.addView(view2) - view2.X = Units.Quantity(220.0, Units.Length) - view2.Y = Units.Quantity(150.0, Units.Length) - FreeCAD.ActiveDocument.recompute() - - print("Place balloon") - balloon1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewBalloon", "Balloon1") - balloon1.SourceView = view1 - # balloon1.OriginIsSet = 1 # OriginIsSet property removed March 2020 - balloon1.OriginX = view1.X + Units.Quantity(20.0, Units.Length) - balloon1.OriginY = view1.Y + Units.Quantity(20.0, Units.Length) - balloon1.Text = "1" - balloon1.Y = balloon1.OriginX + Units.Quantity(20.0, Units.Length) - balloon1.X = balloon1.OriginY + Units.Quantity(20.0, Units.Length) - - print("adding balloon1 to page") - page.addView(balloon1) - - balloon2 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewBalloon", "Balloon2") - balloon2.SourceView = view2 - # balloon2.OriginIsSet = 1 - balloon2.OriginX = view2.X + Units.Quantity(20.0, Units.Length) - balloon2.OriginY = view2.Y + Units.Quantity(20.0, Units.Length) - balloon2.Text = "2" - balloon2.Y = balloon2.OriginX + Units.Quantity(20.0, Units.Length) - balloon2.X = balloon2.OriginY + Units.Quantity(20.0, Units.Length) - - print("adding balloon2 to page") - page.addView(balloon2) - - FreeCAD.ActiveDocument.recompute() - - rc = False - if ("Up-to-date" in balloon1.State) and ("Up-to-date" in balloon2.State): - rc = True - - FreeCAD.closeDocument("TDBalloon") - return rc - - -if __name__ == "__main__": - DVBalloonTest() diff --git a/src/Mod/TechDraw/TDTest/DrawViewBalloonTest.py b/src/Mod/TechDraw/TDTest/DrawViewBalloonTest.py new file mode 100644 index 0000000000..e5dcfbaa0d --- /dev/null +++ b/src/Mod/TechDraw/TDTest/DrawViewBalloonTest.py @@ -0,0 +1,80 @@ +import FreeCAD +from FreeCAD import Units +import unittest +from .TechDrawTestUtilities import createPageWithSVGTemplate + + +class DrawViewBalloonTest(unittest.TestCase): + def setUp(self): + """Creates a page and 2 views""" + FreeCAD.newDocument("TDBalloon") + FreeCAD.setActiveDocument("TDBalloon") + FreeCAD.ActiveDocument = FreeCAD.getDocument("TDBalloon") + + # make source feature + FreeCAD.ActiveDocument.addObject("Part::Box", "Box") + FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere") + + # make a page + self.page = createPageWithSVGTemplate() + self.page.Scale = 5.0 + # page.ViewObject.show() # unit tests run in console mode + + # make Views + self.view1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View") + FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box] + self.page.addView(self.view1) + self.view1.X = Units.Quantity(30.0, Units.Length) + self.view1.Y = Units.Quantity(150.0, Units.Length) + self.view2 = FreeCAD.activeDocument().addObject( + "TechDraw::DrawViewPart", "View001" + ) + FreeCAD.activeDocument().View001.Source = [FreeCAD.activeDocument().Sphere] + self.page.addView(self.view2) + self.view2.X = Units.Quantity(220.0, Units.Length) + self.view2.Y = Units.Quantity(150.0, Units.Length) + FreeCAD.ActiveDocument.recompute() + + def tearDown(self): + FreeCAD.closeDocument("TDBalloon") + + def testMakeDrawViewBalloon(self): + """Tests if a DrawViewBalloon can be added to view""" + print("Place balloon") + balloon1 = FreeCAD.ActiveDocument.addObject( + "TechDraw::DrawViewBalloon", "Balloon1" + ) + balloon1.SourceView = self.view1 + # balloon1.OriginIsSet = 1 # OriginIsSet property removed March 2020 + balloon1.OriginX = self.view1.X + Units.Quantity(20.0, Units.Length) + balloon1.OriginY = self.view1.Y + Units.Quantity(20.0, Units.Length) + balloon1.Text = "1" + balloon1.Y = balloon1.OriginX + Units.Quantity(20.0, Units.Length) + balloon1.X = balloon1.OriginY + Units.Quantity(20.0, Units.Length) + + print("adding balloon1 to page") + self.page.addView(balloon1) + + FreeCAD.ActiveDocument.recompute() + self.assertTrue("Up-to-date" in balloon1.State) + + balloon2 = FreeCAD.ActiveDocument.addObject( + "TechDraw::DrawViewBalloon", "Balloon2" + ) + balloon2.SourceView = self.view2 + # balloon2.OriginIsSet = 1 + balloon2.OriginX = self.view2.X + Units.Quantity(20.0, Units.Length) + balloon2.OriginY = self.view2.Y + Units.Quantity(20.0, Units.Length) + balloon2.Text = "2" + balloon2.Y = balloon2.OriginX + Units.Quantity(20.0, Units.Length) + balloon2.X = balloon2.OriginY + Units.Quantity(20.0, Units.Length) + + print("adding balloon2 to page") + self.page.addView(balloon2) + + FreeCAD.ActiveDocument.recompute() + self.assertTrue("Up-to-date" in balloon2.State) + + +if __name__ == "__main__": + unittest.main() diff --git a/src/Mod/TechDraw/TestTechDrawApp.py b/src/Mod/TechDraw/TestTechDrawApp.py index a3409d3dd9..f8b3b526ab 100644 --- a/src/Mod/TechDraw/TestTechDrawApp.py +++ b/src/Mod/TechDraw/TestTechDrawApp.py @@ -24,13 +24,13 @@ import unittest from TDTest.DrawHatchTest import DrawHatchTest # noqa: F401 from TDTest.DrawViewAnnotationTest import DrawViewAnnotationTest # noqa: F401 +from TDTest.DrawViewBalloonTest import DrawViewBalloonTest # noqa: F401 from TDTest.DrawViewDimensionTest import DrawViewDimensionTest # noqa: F401 from TDTest.DrawViewImageTest import DrawViewImageTest # noqa: F401 from TDTest.DrawViewSectionTest import DrawViewSectionTest # noqa: F401 from TDTest.DrawViewSymbolTest import DrawViewSymbolTest # noqa: F401 from TDTest.DrawViewPartTest import DrawViewPartTest # noqa: F401 from TDTest.DProjGroupTest import DProjGroupTest -from TDTest.DVBalloonTest import DVBalloonTest # --------------------------------------------------------------------------- # define the test cases to test the FreeCAD TechDraw module @@ -45,11 +45,3 @@ class TechDrawTestCases(unittest.TestCase): print("TD DrawProjGroup test passed") else: print("TD DrawProjGroup test failed") - - def testBalloonCase(self): - print("starting TD DrawViewBalloon test") - rc = DVBalloonTest() - if rc: - print("TD DrawViewBalloon test passed") - else: - print("TD DrawViewBalloon test failed")