[TechDraw] Make image test a unittest

This commit is contained in:
Benjamin Bræstrup Sayoc
2022-07-25 02:22:04 +02:00
committed by WandererFan
parent 4fc8596d7b
commit a1dfe2465f
4 changed files with 37 additions and 54 deletions

View File

@@ -143,8 +143,8 @@ SET(TDTest_SRCS
TDTest/__init__.py
TDTest/DrawHatchTest.py
TDTest/DProjGroupTest.py
TDTest/DVAnnoSymImageTest.py
TDTest/DrawViewAnnotationTest.py
TDTest/DrawViewImageTest.py
TDTest/DrawViewSymbolTest.py
TDTest/DVDimensionTest.py
TDTest/DVPartTest.py

View File

@@ -1,43 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# annotation & symbol test script for TechDraw module
# creates a page, 1 annotation and import 1 symbol
from __future__ import print_function
import FreeCAD
import os
def DVAnnoSymImageTest():
path = os.path.dirname(os.path.abspath(__file__))
print("TDTestAnno path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
imageFileSpec = path + "/TestImage.png"
FreeCAD.newDocument("TDAnno")
FreeCAD.setActiveDocument("TDAnno")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDAnno")
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.ViewObject.show() # unit tests run in console mode
# image
img = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewImage", "TestImage")
img.ImageFile = imageFileSpec
page.addView(img)
FreeCAD.ActiveDocument.recompute()
rc = False
if "Up-to-date" in img.State:
rc = True
FreeCAD.closeDocument("TDAnno")
return rc
if __name__ == "__main__":
DVAnnoSymImageTest()

View File

@@ -0,0 +1,34 @@
from __future__ import print_function
import FreeCAD
import os
import unittest
from .TechDrawTestUtilities import createPageWithSVGTemplate
class DrawViewImageTest(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 testMakeImage(self):
"""Tests if an image can be added to page"""
path = os.path.dirname(os.path.abspath(__file__))
imageFileSpec = path + "/TestImage.png"
img = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewImage", "TestImage")
img.ImageFile = imageFileSpec
self.page.addView(img)
FreeCAD.ActiveDocument.recompute()
self.assertTrue("Up-to-date" in img.State)
if __name__ == "__main__":
unittest.main()

View File

@@ -24,9 +24,9 @@ import unittest
from TDTest.DrawHatchTest import DrawHatchTest # noqa: F401
from TDTest.DrawViewAnnotationTest import DrawViewAnnotationTest # noqa: F401
from TDTest.DrawViewSymbolTest import DrawViewSymbolTest
from TDTest.DrawViewImageTest import DrawViewImageTest # noqa: F401
from TDTest.DrawViewSymbolTest import DrawViewSymbolTest # noqa: F401
from TDTest.DProjGroupTest import DProjGroupTest
from TDTest.DVAnnoSymImageTest import DVAnnoSymImageTest
from TDTest.DVDimensionTest import DVDimensionTest
from TDTest.DVPartTest import DVPartTest
from TDTest.DVSectionTest import DVSectionTest
@@ -46,14 +46,6 @@ class TechDrawTestCases(unittest.TestCase):
else:
print("TD DrawViewPart test failed")
def testAnnoSymImageCase(self):
print("starting TD DrawAnno/Sym/Image test")
rc = DVAnnoSymImageTest()
if rc:
print("TD DrawAnno/Sym/Image test passed")
else:
print("TD DrawAnno/Sym/Image test failed")
def testProjGroupCase(self):
print("starting TD DrawProjGroup test")
rc = DProjGroupTest()