Debian Codegraph @

tests/test_importers.py

raw symbols SCIP
1 """
2 Tests file importers such as STEP
3 """
4 # core modules
5 import tempfilescip-python python python-stdlib 3.11 tempfile/__init__:
6 import osscip-python python python-stdlib 3.11 os/__init__:
7
8 from cadqueryscip-python python cadquery 2.8.0.dev0 cadquery/__init__: import importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:, Workplanescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#, Compoundscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Compound#
9 from testsscip-python python cadquery 2.8.0.dev0 tests/__init__: import BaseTestscip-python python cadquery 2.8.0.dev0 tests/BaseTest#
10 from pytestscip-python python pytest 9.0.3 pytest/__init__: import approx, raises
11
12 # where unit test output will be saved
13 OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR. = tempfilescip-python python python-stdlib 3.11 tempfile/__init__:.gettempdirscip-python python python-stdlib 3.11 tempfile/gettempdir().()
14
15 # test data directory
16 testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..dirnamescip-python python python-stdlib 3.11 posixpath/split().(__file__scip-python python cadquery 2.8.0.dev0 `tests.test_importers`/), "testdata")
17
18
19 class TestImportersscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#(BaseTestscip-python python cadquery 2.8.0.dev0 tests/BaseTest#):
20 def importBoxscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(self), importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(importType), fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(fileName)):
21 """
22 Exports a simple box and then imports it again
23 :param importType: The type of file we're importing (STEP, STL, etc)
24 :param fileName: The path and name of the file to write to
25 """
26 # We first need to build a simple shape to export
27 shape = Workplanescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#("XY").boxscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#box().(1, 2, 3).valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().()
28
29 if importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(importType) == importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.STEPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#STEP.:
30 # Export the shape to a temporary file
31 shape.exportStepscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#exportStep().(fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(fileName))
32 elif importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(importType) == importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BREPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BREP.:
33 shape.exportBrepscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#exportBrep().(fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(fileName))
34 elif importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(importType) == importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BINscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BIN.:
35 shape.exportBinscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#exportBin().(fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(fileName))
36
37 # Reimport the shape from the new file
38 importedShape = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importShapescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importShape().(importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(importType), fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(fileName))
39
40 # Check to make sure we got a single solid back.
41 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(self).assertTrue(importedShape.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
42 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(self).assertEqual(importedShape.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().ShapeTypescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#ShapeType().(), "Solid")
43 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(self).assertEqual(len(importedShape.objectsscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#objects.), 1)
44
45 # Check the number of faces and vertices per face to make sure we have a
46 # box shape.
47 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(self).assertNFacesAndNVerticesscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(importedShape, (1, 1, 1), (4, 4, 4))
48 # Check that the volume is correct.
49 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(self).assertAlmostEqual(importedShape.findSolidscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#findSolid().().Volumescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#Volume().(), 6)
50
51 def importCompoundscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self), importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(importType), fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(fileName)):
52 """
53 Exports a "+" shaped compound box and then imports it again.
54 :param importType: The type of file we're importing (STEP, STL, etc)
55 :param fileName: The path and name of the file to write to
56 """
57 # We first need to build a simple shape to export
58 b1 = Workplanescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#("XY").boxscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#box().(1, 2, 3).valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().()
59 b2 = Workplanescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#("XZ").boxscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#box().(1, 2, 3).valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().()
60 shape = Compoundscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Compound#.makeCompoundscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Compound#makeCompound().([b1, b2])
61
62 if importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(importType) == importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.STEPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#STEP.:
63 # Export the shape to a temporary file
64 shape.exportStepscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#exportStep().(fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(fileName))
65 elif importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(importType) == importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BREPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BREP.:
66 shape.exportBrepscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#exportBrep().(fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(fileName))
67 elif importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(importType) == importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BINscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BIN.:
68 shape.exportBinscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#exportBin().(fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(fileName))
69
70 # Reimport the shape from the new file
71 importedShape = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importShapescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importShape().(importTypescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(importType), fileNamescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(fileName))
72
73 # Check to make sure we got the shapes we expected.
74 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertTrue(importedShape.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
75 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertEqual(importedShape.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().ShapeTypescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#ShapeType().(), "Compound")
76 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertEqual(len(importedShape.objectsscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#objects.), 1)
77
78 # Check the number of faces and vertices per face to make sure we have
79 # two boxes.
80 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertNFacesAndNVerticesscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(importedShape, (2, 2, 2), (8, 8, 8))
81
82 # Check that the volume is the independent sum of the two boxes' 6mm^2
83 # volumes.
84 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertAlmostEqual(importedShape.findSolidscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#findSolid().().Volumescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#Volume().(), 12)
85
86 # Join the boxes together and ensure that they are geometrically where
87 # we expected them to be. This should be a workplane containing a
88 # compound composed of a single Solid.
89 fusedShape = Workplanescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#("XY").newObjectscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#newObject().(importedShape.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().fusescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#fuse().())
90
91 # Check to make sure we got a valid shape
92 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertTrue(fusedShape.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
93
94 # Check the number of faces and vertices per face to make sure we have
95 # two boxes.
96 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertNFacesAndNVerticesscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(fusedShape, (5, 3, 3), (12, 12, 12))
97
98 # Check that the volume accounts for the overlap of the two shapes.
99 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(self).assertAlmostEqual(fusedShape.findSolidscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#findSolid().().Volumescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#Volume().(), 8)
100
101 def assertNFacesAndNVerticesscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(self), workplanescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(workplane), nFacesXYZscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(nFacesXYZ), nVerticesXYZscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(nVerticesXYZ)):
102 """
103 Checks that the workplane has the number of faces and vertices expected
104 in X, Y, and Z.
105 :param workplane: The workplane to assess.
106 :param nFacesXYZ: The number of faces expected in +X, +Y, and +Z planes.
107 :param nVerticesXYZ: The number of vertices expected in +X, +Y, and +Z planes.
108 """
109 nFacesX, nFacesY, nFacesZ = nFacesXYZscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(nFacesXYZ)
110 nVerticesX, nVerticesY, nVerticesZ = nVerticesXYZscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(nVerticesXYZ)
111
112 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(self).assertEqual(workplanescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(workplane).faces("+X").size(), nFacesX)
113 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(self).assertEqual(workplanescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(workplane).faces("+X").vertices().size(), nVerticesX)
114
115 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(self).assertEqual(workplanescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(workplane).faces("+Y").size(), nFacesY)
116 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(self).assertEqual(workplanescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(workplane).faces("+Y").vertices().size(), nVerticesY)
117
118 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(self).assertEqual(workplanescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(workplane).faces("+Z").size(), nFacesZ)
119 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(self).assertEqual(workplanescip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#assertNFacesAndNVertices().(workplane).faces("+Z").vertices().size(), nVerticesZ)
120
121 def testInvalidImportTypeRaisesRuntimeErrorscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testInvalidImportTypeRaisesRuntimeError().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testInvalidImportTypeRaisesRuntimeError().(self)):
122 fileName = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "tempSTEP.step")
123 shape = Workplanescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#("XY").boxscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#box().(1, 2, 3).valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().()
124 shape.exportStepscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#exportStep().(fileName)
125 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testInvalidImportTypeRaisesRuntimeError().(self).assertRaises(RuntimeErrorscip-python python python-stdlib 3.11 builtins/RuntimeError#, importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importShapescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importShape()., "INVALID", fileName)
126
127 def testBREPscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBREP().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBREP().(self)):
128 """
129 Test BREP file import.
130 """
131 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBREP().(self).importBoxscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(
132 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BREPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BREP., osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "tempBREP.brep")
133 )
134 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBREP().(self).importCompoundscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(
135 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BREPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BREP., osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "tempBREP.brep")
136 )
137
138 def testBINscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBIN().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBIN().(self)):
139 """
140 Test binary BREP file import.
141 """
142 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBIN().(self).importBoxscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BINscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BIN., osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "tempBIN.bin"))
143 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testBIN().(self).importCompoundscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(
144 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.BINscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#BIN., osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "tempBIN.bin")
145 )
146
147 def testSTEPscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testSTEP().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testSTEP().(self)):
148 """
149 Tests STEP file import
150 """
151 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testSTEP().(self).importBoxscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importBox().(
152 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.STEPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#STEP., osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "tempSTEP.step")
153 )
154 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testSTEP().(self).importCompoundscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#importCompound().(
155 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.STEPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#STEP., osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "tempSTEP.step")
156 )
157
158 def testInvalidSTEPscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testInvalidSTEP().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testInvalidSTEP().(self)):
159 """
160 Attempting to load an invalid STEP file should throw an exception, but
161 not segfault.
162 """
163 tmpfile = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(OUTDIRscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/OUTDIR., "badSTEP.step")
164 with openscip-python python python-stdlib 3.11 builtins/open().(tmpfile, "w") as f:
165 f.writescip-python python python-stdlib 3.11 io/TextIOBase#write().("invalid STEP file")
166 with selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testInvalidSTEP().(self).assertRaises(ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#):
167 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importShapescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importShape().(importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.STEPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#STEP., tmpfile)
168
169 def testImportMultipartSTEPscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportMultipartSTEP().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportMultipartSTEP().(self)):
170 """
171 Import a STEP file that contains two objects and ensure that both are
172 loaded.
173 """
174
175 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "red_cube_blue_cylinder.step")
176 objs = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importShapescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importShape().(importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.STEPscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#STEP., filename)
177 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportMultipartSTEP().(self).assertEqual(2, len(objs.allscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#all().()))
178
179 def testImportDXFscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self)):
180 """
181 Test DXF import with various tolerances.
182 """
183
184 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "gear.dxf")
185
186 with selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertRaises(ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#):
187 # tol >~ 2e-4 required for closed wires
188 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename)
189
190 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename, tolscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(tol)=1e-3)
191 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
192 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.facesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#faces().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 1)
193 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.wiresscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#wires().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 2)
194
195 obj = obj.wiresscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#wires().().toPendingscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#toPending().().extrudescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#extrude().(1)
196 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
197 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.solidsscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#solids().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 1)
198
199 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importShapescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importShape().(importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.ImportTypesscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#.DXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/ImportTypes#DXF., filename, tol=1e-3)
200 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
201
202 # additional files to test more DXF entities
203
204 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "MC 12x31.dxf")
205 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename)
206 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
207
208 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "1001.dxf")
209 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename)
210 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
211
212 # test spline import
213
214 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "spline.dxf")
215 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename, tolscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(tol)=1)
216 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
217 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.facesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#faces().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 1)
218 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.wiresscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#wires().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 2)
219
220 # test rational spline import
221 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "rational_spline.dxf")
222 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename)
223 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
224 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.facesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#faces().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 1)
225 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.edgesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#edges().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 1)
226
227 # importing of a complex shape exported from Inkscape
228 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "genshi.dxf")
229 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename)
230 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
231 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.facesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#faces().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 1)
232
233 # test layer filtering
234 filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 posixpath/split().(testdataDirscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/testdataDir., "three_layers.dxf")
235 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename, excludescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(exclude)=["Layer2"])
236 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertTrue(obj.valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().isValidscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#isValid().())
237 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.facesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#faces().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 2)
238 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(obj.wiresscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#wires().().sizescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#size().(), 2)
239
240 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename, includescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(include)=["Layer2"])
241 assert obj.verticesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#vertices().("<XY").valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().toTuplescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.geom`/Vector#toTuple().() == approx(
242 (104.2871791623584, 0.0038725018551133, 0.0)
243 )
244
245 obj = importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename, includescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(include)=["Layer2", "Layer3"])
246 assert obj.verticesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#vertices().("<XY").valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().toTuplescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.geom`/Vector#toTuple().() == approx(
247 (104.2871791623584, 0.0038725018551133, 0.0)
248 )
249 assert obj.verticesscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#vertices().(">XY").valscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#val().().toTuplescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.geom`/Vector#toTuple().() == approx(
250 (257.6544359816229, 93.62447646419444, 0.0)
251 )
252
253 with raises(ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#):
254 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename, includescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(include)=["Layer1"], excludescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(exclude)=["Layer3"])
255
256 with raises(ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#):
257 # Layer4 does not exist
258 importersscip-python python cadquery 2.8.0.dev0 `occ_impl.importers`/__init__:.importDXFscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(filename, includescip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.importers`/importDXF().(include)=["Layer4"])
259
260 # test dxf extrusion into the third dimension
261 extrusion_value = 15.0
262 tmp = obj.wiresscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#wires().()
263 tmp.ctxscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#ctx..pendingWiresscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/CQContext#pendingWires. = tmp.valsscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#vals().()
264 threed = tmp.extrudescip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#extrude().(extrusion_value)
265 selfscip-python python cadquery 2.8.0.dev0 `tests.test_importers`/TestImporters#testImportDXF().(self).assertEqual(threed.findSolidscip-python python cadquery 2.8.0.dev0 `cadquery.cq`/Workplane#findSolid().().BoundingBoxscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.shapes`/Shape#BoundingBox().().zlenscip-python python cadquery 2.8.0.dev0 `cadquery.occ_impl.geom`/BoundBox#zlen., extrusion_value)
266
267
268 if __name__scip-python python cadquery 2.8.0.dev0 `tests.test_importers`/ == "__main__":
269 import unittestscip-python python python-stdlib 3.11 unittest/__init__:
270
271 unittestscip-python python python-stdlib 3.11 unittest/__init__:.mainscip-python python cadquery 2.8.0.dev0 main/__init__:()