[TechDraw] Make section view test a unittest
This commit is contained in:
committed by
WandererFan
parent
937d19c4ad
commit
886c1415d8
@@ -148,7 +148,7 @@ SET(TDTest_SRCS
|
||||
TDTest/DrawViewSymbolTest.py
|
||||
TDTest/DrawViewDimensionTest.py
|
||||
TDTest/DrawViewPartTest.py
|
||||
TDTest/DVSectionTest.py
|
||||
TDTest/DrawViewSectionTest.py
|
||||
TDTest/DVBalloonTest.py
|
||||
TDTest/TechDrawTestUtilities.py
|
||||
)
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# test script for TechDraw module
|
||||
# creates a page, 1 view and 1 section view
|
||||
from __future__ import print_function
|
||||
|
||||
import FreeCAD
|
||||
import os
|
||||
|
||||
|
||||
def DVSectionTest():
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
print("TDSection path: " + path)
|
||||
templateFileSpec = path + "/TestTemplate.svg"
|
||||
|
||||
FreeCAD.newDocument("TDSection")
|
||||
FreeCAD.setActiveDocument("TDSection")
|
||||
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDSection")
|
||||
|
||||
box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
|
||||
|
||||
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
|
||||
print("page created")
|
||||
|
||||
view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
|
||||
rc = page.addView(view)
|
||||
view.Source = [box]
|
||||
view.Direction = (0.0, 0.0, 1.0)
|
||||
view.Rotation = 0.0
|
||||
view.X = 30.0
|
||||
view.Y = 150.0
|
||||
print("view created")
|
||||
|
||||
section = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewSection", "Section")
|
||||
rc = page.addView(section)
|
||||
section.Source = [box]
|
||||
section.BaseView = view
|
||||
section.Direction = (0.0, 1.0, 0.0)
|
||||
section.SectionNormal = (0.0, 1.0, 0.0)
|
||||
section.SectionOrigin = (5.0, 5.0, 5.0)
|
||||
view.touch()
|
||||
print("section created")
|
||||
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
rc = False
|
||||
if ("Up-to-date" in view.State) and ("Up-to-date" in section.State):
|
||||
rc = True
|
||||
|
||||
FreeCAD.closeDocument("TDSection")
|
||||
return rc
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
DVSectionTest()
|
||||
51
src/Mod/TechDraw/TDTest/DrawViewSectionTest.py
Normal file
51
src/Mod/TechDraw/TDTest/DrawViewSectionTest.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import FreeCAD
|
||||
import unittest
|
||||
from .TechDrawTestUtilities import createPageWithSVGTemplate
|
||||
|
||||
|
||||
class DrawViewSectionTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Creates a page and a view"""
|
||||
FreeCAD.newDocument("TDSection")
|
||||
FreeCAD.setActiveDocument("TDSection")
|
||||
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDSection")
|
||||
|
||||
self.box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
|
||||
|
||||
self.page = createPageWithSVGTemplate()
|
||||
self.page.Scale = 5.0
|
||||
# page.ViewObject.show() # unit tests run in console mode
|
||||
print("page created")
|
||||
|
||||
self.view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
|
||||
self.page.addView(self.view)
|
||||
self.view.Source = [self.box]
|
||||
self.view.Direction = (0.0, 0.0, 1.0)
|
||||
self.view.Rotation = 0.0
|
||||
self.view.X = 30.0
|
||||
self.view.Y = 150.0
|
||||
print("view created")
|
||||
|
||||
def tearDown(self):
|
||||
FreeCAD.closeDocument("TDSection")
|
||||
|
||||
def testMakeDrawViewSection(self):
|
||||
"""Tests if a DrawViewSection can be added to page"""
|
||||
section = FreeCAD.ActiveDocument.addObject(
|
||||
"TechDraw::DrawViewSection", "Section"
|
||||
)
|
||||
self.page.addView(section)
|
||||
section.Source = [self.box]
|
||||
section.BaseView = self.view
|
||||
section.Direction = (0.0, 1.0, 0.0)
|
||||
section.SectionNormal = (0.0, 1.0, 0.0)
|
||||
section.SectionOrigin = (5.0, 5.0, 5.0)
|
||||
self.view.touch()
|
||||
print("section created")
|
||||
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
self.assertTrue("Up-to-date" in section.State)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -26,10 +26,10 @@ from TDTest.DrawHatchTest import DrawHatchTest # noqa: F401
|
||||
from TDTest.DrawViewAnnotationTest import DrawViewAnnotationTest # 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.DVSectionTest import DVSectionTest
|
||||
from TDTest.DVBalloonTest import DVBalloonTest
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -46,14 +46,6 @@ class TechDrawTestCases(unittest.TestCase):
|
||||
else:
|
||||
print("TD DrawProjGroup test failed")
|
||||
|
||||
def testSectionCase(self):
|
||||
print("starting TD DrawViewSection test")
|
||||
rc = DVSectionTest()
|
||||
if rc:
|
||||
print("TD DrawViewSection test passed")
|
||||
else:
|
||||
print("TD DrawViewSection test failed")
|
||||
|
||||
def testBalloonCase(self):
|
||||
print("starting TD DrawViewBalloon test")
|
||||
rc = DVBalloonTest()
|
||||
|
||||
Reference in New Issue
Block a user