[TechDraw] Make annotation test a unittest

This commit is contained in:
Benjamin Bræstrup Sayoc
2022-07-25 01:52:56 +02:00
committed by WandererFan
parent 64f6249ee9
commit a9a31ad3b8
5 changed files with 61 additions and 13 deletions

View File

@@ -144,10 +144,12 @@ SET(TDTest_SRCS
TDTest/DrawHatchTest.py
TDTest/DProjGroupTest.py
TDTest/DVAnnoSymImageTest.py
TDTest/DrawViewAnnotationTest.py
TDTest/DVDimensionTest.py
TDTest/DVPartTest.py
TDTest/DVSectionTest.py
TDTest/DVBalloonTest.py
TDTest/TechDrawTestUtilities.py
)
SET(TDTestFile_SRCS

View File

@@ -26,17 +26,6 @@ def DVAnnoSymImageTest():
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
# page.ViewObject.show() # unit tests run in console mode
# annotation
anno = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewAnnotation", "TestAnno")
s = "Different Text"
sl = list()
sl.append(s)
anno.Text = sl
anno.TextStyle = "Bold"
page.addView(anno)
anno.X = 30.0
anno.Y = 150.0
# symbol
sym = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewSymbol", "TestSymbol")
f = open(symbolFileSpec, "r")
@@ -55,8 +44,7 @@ def DVAnnoSymImageTest():
FreeCAD.ActiveDocument.recompute()
rc = False
if (
("Up-to-date" in anno.State)
and ("Up-to-date" in sym.State)
("Up-to-date" in sym.State)
and ("Up-to-date" in img.State)
):
rc = True

View File

@@ -0,0 +1,38 @@
from __future__ import print_function
import FreeCAD
import unittest
from .TechDrawTestUtilities import createPageWithSVGTemplate
class DrawViewAnnotationTest(unittest.TestCase):
def setUp(self):
"""Creates a page"""
FreeCAD.newDocument("TDAnno")
FreeCAD.setActiveDocument("TDAnno")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDAnno")
self.page = createPageWithSVGTemplate()
def tearDown(self):
FreeCAD.closeDocument("TDAnno")
def testMakeAnnotation(self):
"""Tests if an annotation can be added to page"""
anno = FreeCAD.ActiveDocument.addObject(
"TechDraw::DrawViewAnnotation", "TestAnno"
)
s = "Different Text"
sl = list()
sl.append(s)
anno.Text = sl
anno.TextStyle = "Bold"
self.page.addView(anno)
anno.X = 30.0
anno.Y = 150.0
FreeCAD.ActiveDocument.recompute()
self.assertTrue("Up-to-date" in anno.State)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,19 @@
from __future__ import print_function
import FreeCAD
import os
def createPageWithSVGTemplate(
templateName: str = "TestTemplate.svg",
):
"""Returns a page with an SVGTemplate added on the ActiveDocument"""
print("2")
path = os.path.dirname(os.path.abspath(__file__))
print("TDTestAnno path: " + path)
templateFileSpec = path + templateName
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
return page

View File

@@ -23,6 +23,7 @@
import unittest
from TDTest.DrawHatchTest import DrawHatchTest # noqa: F401
from TDTest.DrawViewAnnotationTest import DrawViewAnnotationTest # noqa: F401
from TDTest.DProjGroupTest import DProjGroupTest
from TDTest.DVAnnoSymImageTest import DVAnnoSymImageTest
from TDTest.DVDimensionTest import DVDimensionTest