CAM: Add AssetManager.copy() and .deepcopy()
CAM: Add copy/paste support for the ToolBitBrowser CAM: Move library dropdown and sort order combo to dedicated row to give them more space CAM: Fix: PathAssetManagerTest failed CAM: Add YamlSerializer [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci CAM: Fix CodeQL complaints CAM: add LibraryProperties dialog CAM: Replace the LibraryEditor CAM: allow for editing tool number in the tool editor dialog CAM: Remember last selected library and sort order in preferences CAM: support natural sort order in tool and library lists CAM: Fix CodeQL complaints CAM: Fix: not all attributes included in YAML serialization CAM: Fix: UTF8 chars not included in LinuxCNC export Fix: tool library not displayed when loading it for the first time CAM: Fix: custom shape class not found CAM: Check dependencies on import for friendlier error messages CAM: Open file dialogs in home by default CAM: Show "All Tools" entry in library list in the library editor CAM: fix: error on sorting tools with no tool number CAM: Fix: traceback if library contained tool number as string CAM: Fix: Linter errors in manager.py CAM: Fix: separator between library and tool buttons CAM: Add drag & drop support to the library editor CAM: Fix numerous linter errors on the AssetManager CAM: Show current library in library editor window title CAM: Add dedicated icons for library add + remove CAM: Support F2 key in library editor CAM: library editor handles delete key when library list is in focus; focus search field by default CAM: fix: tool list in dock initially not loading CAM: Fix: library editor did not open from "all tools" list CAM: Increase precision of parameters in tool summary to 3 digits fix TestToolBitListWidget
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import yaml
|
||||
import json
|
||||
from typing import Type, cast
|
||||
import FreeCAD
|
||||
@@ -6,6 +7,7 @@ from Path.Tool.toolbit import ToolBit, ToolBitEndmill
|
||||
from Path.Tool.toolbit.serializers import (
|
||||
FCTBSerializer,
|
||||
CamoticsToolBitSerializer,
|
||||
YamlToolBitSerializer,
|
||||
)
|
||||
from Path.Tool.assets.asset import Asset
|
||||
from Path.Tool.assets.serializer import AssetSerializer
|
||||
@@ -132,3 +134,72 @@ class TestFCTBSerializer(_BaseToolBitSerializerTestCase):
|
||||
self.assertEqual(deserialized_bit.get_shape_name(), "Endmill")
|
||||
self.assertEqual(str(deserialized_bit.get_diameter()), "4.12 mm")
|
||||
self.assertEqual(str(deserialized_bit.get_length()), "15.0 mm")
|
||||
|
||||
|
||||
class TestYamlToolBitSerializer(_BaseToolBitSerializerTestCase):
|
||||
serializer_class = YamlToolBitSerializer
|
||||
|
||||
def test_serialize(self):
|
||||
super().test_serialize()
|
||||
serialized_data = self.serializer_class.serialize(self.test_tool_bit)
|
||||
# YAML specific assertions
|
||||
data = yaml.safe_load(serialized_data.decode("utf-8"))
|
||||
self.assertEqual(data.get("id"), "5mm_Endmill")
|
||||
self.assertEqual(data.get("name"), "Test Tool")
|
||||
self.assertEqual(data.get("shape"), "endmill.fcstd")
|
||||
self.assertEqual(data.get("shape-type"), "Endmill")
|
||||
self.assertEqual(data.get("parameter", {}).get("Diameter"), "4.12 mm")
|
||||
self.assertEqual(data.get("parameter", {}).get("Length"), "15.0 mm")
|
||||
|
||||
def test_extract_dependencies(self):
|
||||
"""Test dependency extraction for YAML."""
|
||||
yaml_data = (
|
||||
b"name: Test Tool\n"
|
||||
b"shape: endmill\n"
|
||||
b"shape-type: Endmill\n"
|
||||
b"parameter:\n"
|
||||
b" Diameter: 4.12 mm\n"
|
||||
b" Length: 15.0 mm\n"
|
||||
b"attribute: {}\n"
|
||||
)
|
||||
dependencies = self.serializer_class.extract_dependencies(yaml_data)
|
||||
self.assertIsInstance(dependencies, list)
|
||||
self.assertEqual(len(dependencies), 1)
|
||||
self.assertEqual(dependencies[0], AssetUri.build("toolbitshape", "endmill"))
|
||||
|
||||
def test_deserialize(self):
|
||||
# Create a known serialized data string based on the YAML format
|
||||
yaml_data = (
|
||||
b"id: TestID\n"
|
||||
b"name: Test Tool\n"
|
||||
b"shape: endmill\n"
|
||||
b"shape-type: Endmill\n"
|
||||
b"parameter:\n"
|
||||
b" Diameter: 4.12 mm\n"
|
||||
b" Length: 15.0 mm\n"
|
||||
b"attribute: {}\n"
|
||||
)
|
||||
# Create a ToolBitShapeEndmill instance for 'endmill'
|
||||
shape = ToolBitShapeEndmill("endmill")
|
||||
|
||||
# Create the dependencies dictionary with the shape instance
|
||||
dependencies: Mapping[AssetUri, Asset] = {AssetUri.build("toolbitshape", "endmill"): shape}
|
||||
|
||||
# Provide dummy id and dependencies for deserialization test
|
||||
deserialized_bit = cast(
|
||||
ToolBitEndmill,
|
||||
self.serializer_class.deserialize(yaml_data, "TestID", dependencies=dependencies),
|
||||
)
|
||||
self.assertIsInstance(deserialized_bit, ToolBit)
|
||||
self.assertEqual(deserialized_bit.id, "TestID")
|
||||
self.assertEqual(deserialized_bit.label, "Test Tool")
|
||||
self.assertEqual(deserialized_bit.get_shape_name(), "Endmill")
|
||||
self.assertEqual(str(deserialized_bit.get_diameter()), "4.12 mm")
|
||||
self.assertEqual(str(deserialized_bit.get_length()), "15.0 mm")
|
||||
|
||||
# Test with ID argument.
|
||||
deserialized_bit = cast(
|
||||
ToolBitEndmill,
|
||||
self.serializer_class.deserialize(yaml_data, id="test_id", dependencies=dependencies),
|
||||
)
|
||||
self.assertEqual(deserialized_bit.id, "test_id")
|
||||
|
||||
Reference in New Issue
Block a user