Merge pull request #24317 from kpemartin/Issue24314

Update unit test to use new storage for DXF import settings
This commit is contained in:
Chris Hennes
2025-11-05 14:25:58 -06:00
committed by GitHub
5 changed files with 2356 additions and 55 deletions

View File

@@ -69,6 +69,7 @@ SET(Draft_tests
drafttests/test_pivy.py
drafttests/test_svg.py
drafttests/README.md
drafttests/Issue24314.dxf
)
SET(Draft_utilities

View File

@@ -108,7 +108,8 @@ from drafttests.test_draftgeomutils import TestDraftGeomUtils as DraftTest04
# Handling of file formats tests
# from drafttests.test_svg import DraftSVG as DraftTest05
# from drafttests.test_dxf import DraftDXF as DraftTest06
from drafttests.test_dxf import DraftDXF as DraftTest06
# from drafttests.test_dwg import DraftDWG as DraftTest07
# from drafttests.test_oca import DraftOCA as DraftTest08
# from drafttests.test_airfoildat import DraftAirfoilDAT as DraftTest09
@@ -120,7 +121,7 @@ True if DraftTest02 else False
True if DraftTest03 else False
True if DraftTest04 else False
# True if DraftTest05 else False
# True if DraftTest06 else False
True if DraftTest06 else False
# True if DraftTest07 else False
# True if DraftTest08 else False
# True if DraftTest09 else False

File diff suppressed because it is too large Load Diff

View File

@@ -41,24 +41,57 @@ import Draft
from drafttests import auxiliary as aux
from drafttests import test_base
from draftutils.messages import _msg
import importDXF
class DraftDXF(test_base.DraftTestCaseDoc):
"""Test reading and writing of DXF files with Draft."""
def test_read_dxf(self):
"""Read a DXF file and import its elements as Draft objects."""
operation = "importDXF.import"
_msg(" Test '{}'".format(operation))
_msg(" This test requires a DXF file to read.")
def test_read_dxf_Issue24314(self):
"""Verify that reading a DXF file does not leave pending Python error states"""
file = "Mod/Draft/drafttest/test.dxf"
in_file = os.path.join(App.getResourceDir(), file)
file = "Mod/Draft/drafttests/Issue24314.dxf"
in_file = os.path.join(App.getHomePath(), file)
_msg(" file={}".format(in_file))
_msg(" exists={}".format(os.path.exists(in_file)))
obj = aux.fake_function(in_file)
self.assertTrue(obj, "'{}' failed".format(operation))
hGrp = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
# Set options, doing our best to restore them:
wasShowDialog = hGrp.GetBool("dxfShowDialog", True)
wasUseLegacyImporter = hGrp.GetBool("dxfUseLegacyImporter", False)
wasUseLayers = hGrp.GetBool("dxfUseDraftVisGroups", True)
wasImportMode = hGrp.GetInt("DxfImportMode", 2)
wasCreateSketch = hGrp.GetBool("dxfCreateSketch", False)
wasImportAnonymousBlocks = hGrp.GetBool("dxfstarblocks", False)
doc = None
try:
# disable Preferences dialog in gui mode (avoids popup prompt to user)
hGrp.SetBool("dxfShowDialog", False)
# Use the new C++ importer -- that's where the bug was
hGrp.SetBool("dxfUseLegacyImporter", False)
# Preserve the DXF layers (makes the checking of document contents easier)
hGrp.SetBool("dxfUseDraftVisGroups", True)
# create simple part shapes (2 params)
# This is required to display the bug because creation of Draft objects clears out the
# pending exception this test is looking for, whereas creation of the simple shape object
# actually throws on the pending exception so the entity is absent from the document.
hGrp.SetInt("DxfImportMode", 2)
hGrp.SetBool("dxfCreateSketch", False)
hGrp.SetBool("dxfstarblocks", False)
doc = importDXF.open(in_file)
# This doc should have 3 objects: The Layers container, the DXF layer called 0, and one Line
self.assertEqual(len(doc.Objects), 3)
finally:
hGrp.SetBool("dxfShowDialog", wasShowDialog)
hGrp.SetBool("dxfUseLegacyImporter", wasUseLegacyImporter)
hGrp.SetBool("dxfUseDraftVisGroups", wasUseLayers)
hGrp.SetInt("DxfImportMode", wasImportMode)
hGrp.SetBool("dxfCreateSketch", wasCreateSketch)
hGrp.SetBool("dxfstarblocks", wasImportAnonymousBlocks)
if doc:
App.closeDocument(doc.Name)
def test_export_dxf(self):
"""Create some figures and export them to a DXF file."""

View File

@@ -682,50 +682,6 @@ class DocumentBasicCases(unittest.TestCase):
FreeCAD.closeDocument("CreateTest")
class DocumentImportCases(unittest.TestCase):
def testDXFImportCPPIssue20195(self):
if "BUILD_DRAFT" in FreeCAD.__cmake__:
import importDXF
from draftutils import params
# Set options, doing our best to restore them:
wasShowDialog = params.get_param("dxfShowDialog")
wasUseLayers = params.get_param("dxfUseDraftVisGroups")
wasUseLegacyImporter = params.get_param("dxfUseLegacyImporter")
wasCreatePart = params.get_param("dxfCreatePart")
wasCreateDraft = params.get_param("dxfCreateDraft")
wasCreateSketch = params.get_param("dxfCreateSketch")
try:
# disable Preferences dialog in gui mode (avoids popup prompt to user)
params.set_param("dxfShowDialog", False)
# Preserve the DXF layers (makes the checking of document contents easier)
params.set_param("dxfUseDraftVisGroups", True)
# Use the new C++ importer -- that's where the bug was
params.set_param("dxfUseLegacyImporter", False)
# create simple part shapes (3 params)
# This is required to display the bug because creation of Draft objects clears out the
# pending exception this test is looking for, whereas creation of the simple shape object
# actually throws on the pending exception so the entity is absent from the document.
params.set_param("dxfCreatePart", True)
params.set_param("dxfCreateDraft", False)
params.set_param("dxfCreateSketch", False)
importDXF.insert(
FreeCAD.getHomePath() + "Mod/Test/TestData/DXFSample.dxf", "ImportedDocName"
)
finally:
params.set_param("dxfShowDialog", wasShowDialog)
params.set_param("dxfUseDraftVisGroups", wasUseLayers)
params.set_param("dxfUseLegacyImporter", wasUseLegacyImporter)
params.set_param("dxfCreatePart", wasCreatePart)
params.set_param("dxfCreateDraft", wasCreateDraft)
params.set_param("dxfCreateSketch", wasCreateSketch)
doc = FreeCAD.getDocument("ImportedDocName")
# This doc should have 3 objects: The Layers container, the DXF layer called 0, and one Line
self.assertEqual(len(doc.Objects), 3)
FreeCAD.closeDocument("ImportedDocName")
# class must be defined in global scope to allow it to be reloaded on document open
class SaveRestoreSpecialGroup:
def __init__(self, obj):