[TD]Add tests for geometry creation
- check that edge geometry count is correct - handle delay waiting for threads to complete - add test for DrawViewDetail
This commit is contained in:
@@ -150,6 +150,7 @@ SET(TDTest_SRCS
|
||||
TDTest/DrawViewPartTest.py
|
||||
TDTest/DrawViewSectionTest.py
|
||||
TDTest/DrawViewBalloonTest.py
|
||||
TDTest/DrawViewDetailTest.py
|
||||
TDTest/TechDrawTestUtilities.py
|
||||
)
|
||||
|
||||
|
||||
77
src/Mod/TechDraw/TDTest/DrawViewDetailTest.py
Normal file
77
src/Mod/TechDraw/TDTest/DrawViewDetailTest.py
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# test script for DrawViewDetail
|
||||
# creates a page, a view and a detail view
|
||||
from __future__ import print_function
|
||||
|
||||
import FreeCAD
|
||||
import unittest
|
||||
from .TechDrawTestUtilities import createPageWithSVGTemplate
|
||||
from PySide import QtCore
|
||||
|
||||
class DrawViewDetailTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Creates a page"""
|
||||
FreeCAD.newDocument("TDPart")
|
||||
FreeCAD.setActiveDocument("TDPart")
|
||||
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDPart")
|
||||
|
||||
FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
|
||||
|
||||
self.page = createPageWithSVGTemplate()
|
||||
self.page.Scale = 5.0
|
||||
# page.ViewObject.show() # unit tests run in console mode
|
||||
print("DrawViewDetail test: page created")
|
||||
|
||||
self.view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
|
||||
self.page.addView(self.view)
|
||||
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
#wait for threads to complete before checking result
|
||||
loop = QtCore.QEventLoop()
|
||||
|
||||
timer = QtCore.QTimer()
|
||||
timer.setSingleShot(True)
|
||||
timer.timeout.connect(loop.quit)
|
||||
|
||||
timer.start(2000) #2 second delay
|
||||
loop.exec_()
|
||||
print("DrawViewDetail test: view created")
|
||||
|
||||
def tearDown(self):
|
||||
print("DrawViewDetail test finished")
|
||||
FreeCAD.closeDocument("TDPart")
|
||||
|
||||
def testMakeDrawViewPart(self):
|
||||
"""Tests if a view can be added to page"""
|
||||
print("testing DrawViewDetail")
|
||||
|
||||
detail = FreeCAD.ActiveDocument.addObject(
|
||||
"TechDraw::DrawViewDetail", "Detail"
|
||||
)
|
||||
detail.BaseView = self.view
|
||||
detail.Direction = self.view.Direction
|
||||
detail.XDirection = self.view.XDirection
|
||||
self.page.addView(detail)
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
print("DrawViewDetail test: Detail created")
|
||||
|
||||
#wait for threads to complete before checking result
|
||||
loop = QtCore.QEventLoop()
|
||||
|
||||
timer = QtCore.QTimer()
|
||||
timer.setSingleShot(True)
|
||||
timer.timeout.connect(loop.quit)
|
||||
|
||||
timer.start(2000) #2 second delay
|
||||
loop.exec_()
|
||||
|
||||
edges = detail.getVisibleEdges()
|
||||
|
||||
self.assertEqual(len(edges), 4, "DrawViewDetail has wrong number of edges")
|
||||
self.assertTrue("Up-to-date" in detail.State, "DrawViewDetail is not Up-to-date")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
# basic test script for TechDraw module
|
||||
# creates a page and 1 view
|
||||
from __future__ import print_function
|
||||
|
||||
import FreeCAD
|
||||
import unittest
|
||||
from .TechDrawTestUtilities import createPageWithSVGTemplate
|
||||
|
||||
from PySide import QtCore
|
||||
|
||||
class DrawViewPartTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -21,19 +22,33 @@ class DrawViewPartTest(unittest.TestCase):
|
||||
self.page = createPageWithSVGTemplate()
|
||||
self.page.Scale = 5.0
|
||||
# page.ViewObject.show() # unit tests run in console mode
|
||||
print("page created")
|
||||
print("DrawViewPart test: page created")
|
||||
|
||||
def tearDown(self):
|
||||
print("DrawViewPart test finished")
|
||||
FreeCAD.closeDocument("TDPart")
|
||||
|
||||
def testMakeDrawViewPart(self):
|
||||
"""Tests if a view can be added to page"""
|
||||
print("testing DrawViewPart")
|
||||
view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
|
||||
self.page.addView(view)
|
||||
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
self.assertTrue("Up-to-date" in view.State)
|
||||
|
||||
#wait for threads to complete before checking result
|
||||
loop = QtCore.QEventLoop()
|
||||
|
||||
timer = QtCore.QTimer()
|
||||
timer.setSingleShot(True)
|
||||
timer.timeout.connect(loop.quit)
|
||||
|
||||
timer.start(2000) #2 second delay
|
||||
loop.exec_()
|
||||
|
||||
edges = view.getVisibleEdges()
|
||||
self.assertEqual(len(edges), 4, "DrawViewPart has wrong number of edges")
|
||||
self.assertTrue("Up-to-date" in view.State, "DrawViewPart is not Up-to-date")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import FreeCAD
|
||||
import unittest
|
||||
from .TechDrawTestUtilities import createPageWithSVGTemplate
|
||||
|
||||
from PySide import QtCore
|
||||
|
||||
class DrawViewSectionTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -15,7 +15,7 @@ class DrawViewSectionTest(unittest.TestCase):
|
||||
self.page = createPageWithSVGTemplate()
|
||||
self.page.Scale = 5.0
|
||||
# page.ViewObject.show() # unit tests run in console mode
|
||||
print("page created")
|
||||
print("DrawViewSection test: page created")
|
||||
|
||||
self.view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
|
||||
self.page.addView(self.view)
|
||||
@@ -24,9 +24,22 @@ class DrawViewSectionTest(unittest.TestCase):
|
||||
self.view.Rotation = 0.0
|
||||
self.view.X = 30.0
|
||||
self.view.Y = 150.0
|
||||
print("view created")
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
#wait for threads to complete before checking result
|
||||
loop = QtCore.QEventLoop()
|
||||
|
||||
timer = QtCore.QTimer()
|
||||
timer.setSingleShot(True)
|
||||
timer.timeout.connect(loop.quit)
|
||||
|
||||
timer.start(2000) #2 second delay
|
||||
loop.exec_()
|
||||
|
||||
print("DrawViewSection test: view created")
|
||||
|
||||
def tearDown(self):
|
||||
print("DrawViewSection test: finished")
|
||||
FreeCAD.closeDocument("TDSection")
|
||||
|
||||
def testMakeDrawViewSection(self):
|
||||
@@ -40,10 +53,21 @@ class DrawViewSectionTest(unittest.TestCase):
|
||||
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")
|
||||
|
||||
print("DrawViewSection test: section created")
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
#wait for threads to complete before checking result
|
||||
loop = QtCore.QEventLoop()
|
||||
|
||||
timer = QtCore.QTimer()
|
||||
timer.setSingleShot(True)
|
||||
timer.timeout.connect(loop.quit)
|
||||
|
||||
timer.start(2000) #2 second delay
|
||||
loop.exec_()
|
||||
|
||||
edges = section.getVisibleEdges()
|
||||
self.assertEqual(len(edges), 4, "DrawViewSection has wrong number of edges")
|
||||
self.assertTrue("Up-to-date" in section.State)
|
||||
|
||||
|
||||
|
||||
@@ -29,3 +29,4 @@ from TDTest.DrawViewSectionTest import DrawViewSectionTest # noqa: F401
|
||||
from TDTest.DrawViewSymbolTest import DrawViewSymbolTest # noqa: F401
|
||||
from TDTest.DrawViewPartTest import DrawViewPartTest # noqa: F401
|
||||
from TDTest.DrawProjectionGroupTest import DrawProjectionGroupTest # noqa: F401
|
||||
from TDTest.DrawViewDetailTest import DrawViewDetailTest # noqa: F401
|
||||
|
||||
Reference in New Issue
Block a user