File size: 5,434 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | # ***************************************************************************
# * Copyright (c) 2025 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
"""Mock objects for postprocessor testing.
This module provides mock objects that simulate FreeCAD CAM job structure
without requiring disk I/O or loading actual FreeCAD documents.
"""
import Path
class MockTool:
def __init__(self):
self.ShapeName = "endmill"
class MockToolController:
"""Mock ToolController for operations."""
def __init__(
self,
tool_number=1,
label="TC: Default Tool",
spindle_speed=1000,
spindle_dir="Forward",
):
self.Tool = MockTool()
self.ToolNumber = tool_number
self.Label = label
self.SpindleSpeed = spindle_speed
self.SpindleDir = spindle_dir
self.Name = f"TC{tool_number}"
# Create a simple path with tool change commands
self.Path = Path.Path()
self.Path.addCommands(
[Path.Command(f"M6 T{tool_number}"), Path.Command(f"M3 S{spindle_speed}")]
)
def InList(self):
return []
class MockOperation:
"""Mock Operation object for testing postprocessors."""
def __init__(self, name="Operation", label=None, tool_controller=None, active=True):
self.Name = name
self.Label = label or name
self.Active = active
self.ToolController = tool_controller
# Create an empty path by default
self.Path = Path.Path()
def InList(self):
"""Mock InList - operations belong to a job."""
return []
class MockStock:
"""Mock Stock object with BoundBox."""
def __init__(self, xmin=0.0, xmax=100.0, ymin=0.0, ymax=100.0, zmin=0.0, zmax=10.0):
self.Shape = type(
"obj",
(object,),
{
"BoundBox": type(
"obj",
(object,),
{
"XMin": xmin,
"XMax": xmax,
"YMin": ymin,
"YMax": ymax,
"ZMin": zmin,
"ZMax": zmax,
},
)()
},
)()
class MockSetupSheet:
"""Mock SetupSheet object."""
def __init__(self, clearance_height=5.0, safe_height=3.0):
self.ClearanceHeightOffset = type("obj", (object,), {"Value": clearance_height})()
self.SafeHeightOffset = type("obj", (object,), {"Value": safe_height})()
class MockJob:
"""Mock Job object for testing postprocessors."""
def __init__(self):
# Create mock Stock with BoundBox
self.Stock = MockStock()
# Create mock SetupSheet
self.SetupSheet = MockSetupSheet()
# Create mock Operations group
self.Operations = type("obj", (object,), {"Group": []})()
# Create mock Tools group
self.Tools = type("obj", (object,), {"Group": []})()
# Create mock Model group
self.Model = type("obj", (object,), {"Group": []})()
# Basic properties
self.Label = "MockJob"
self.PostProcessor = ""
self.PostProcessorArgs = ""
self.PostProcessorOutputFile = ""
self.Fixtures = ["G54"]
self.OrderOutputBy = "Tool"
self.SplitOutput = False
def InList(self):
"""Mock InList for fixture setup."""
return []
def create_default_job_with_operation():
"""Create a mock job with a default tool controller and operation.
This is a convenience function for common test scenarios.
Returns: (job, operation, tool_controller)
"""
job = MockJob()
# Create default tool controller
tc = MockToolController(tool_number=1, label="TC: Default Tool", spindle_speed=1000)
job.Tools.Group = [tc]
# Create default operation
op = MockOperation(name="Profile", label="Profile", tool_controller=tc)
job.Operations.Group = [op]
return job, op, tc
|