Transplant the test code from the old location

For some reason the app hangs after the test GUI is run
This commit is contained in:
Kevin Martin
2025-10-31 10:27:14 -04:00
parent 2d5bb51734
commit 5afe1e64f8

View File

@@ -39,6 +39,7 @@ 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):
@@ -46,17 +47,49 @@ class DraftDXF(test_base.DraftTestCaseDoc):
def test_read_dxf_Issue24314(self):
"""Verify that reading a DXF file does not leave pending Python error states"""
operation = "importDXF.import"
_msg(" Test '{}'".format(operation))
_msg(" This test requires a DXF file to read.")
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.assertFalse(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."""