[TechDraw] Make hatch test a unittest
This commit is contained in:
committed by
WandererFan
parent
5a9ffe468c
commit
d1f107f656
@@ -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
|
||||
|
||||
@@ -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()
|
||||
62
src/Mod/TechDraw/TDTest/DrawHatchTest.py
Normal file
62
src/Mod/TechDraw/TDTest/DrawHatchTest.py
Normal file
@@ -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()
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user