- arc improvements, fillets, operations, bodys
This commit is contained in:
@@ -13,16 +13,58 @@ import unittest
|
||||
# Allow running this file directly: ``python tests/test_project_io.py``.
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, "src"))
|
||||
|
||||
from fluency.io.project_io import save_project, load_project
|
||||
from fluency.io.project_io import save_project, load_project, _feature_to_dict, _feature_from_dict
|
||||
from fluency.models.data_model import (
|
||||
Project,
|
||||
Component,
|
||||
Body,
|
||||
Sketch,
|
||||
Workplane,
|
||||
Assembly,
|
||||
Feature,
|
||||
)
|
||||
|
||||
|
||||
class TestRevolveAxisSerialization(unittest.TestCase):
|
||||
"""Revolve features persist their revolve axis across save/load."""
|
||||
|
||||
def test_axis_round_trip(self):
|
||||
sk = Sketch()
|
||||
feat = Feature(
|
||||
operation="revolve",
|
||||
angle=180.0,
|
||||
axis=(1, 0, 0),
|
||||
origin=(10.0, 5.0, 0.0),
|
||||
axis_line_id=7,
|
||||
)
|
||||
feat.sketch = sk
|
||||
data = _feature_to_dict(feat)
|
||||
self.assertEqual(data["axis"], [1.0, 0.0, 0.0])
|
||||
self.assertEqual(data["origin"], [10.0, 5.0, 0.0])
|
||||
self.assertEqual(data["axis_line_id"], 7)
|
||||
restored = _feature_from_dict(data, {sk.id: sk})
|
||||
self.assertEqual(tuple(restored.axis), (1.0, 0.0, 0.0))
|
||||
self.assertEqual(tuple(restored.origin), (10.0, 5.0, 0.0))
|
||||
self.assertEqual(restored.axis_line_id, 7)
|
||||
self.assertEqual(restored.angle, 180.0)
|
||||
|
||||
def test_default_axis(self):
|
||||
"""Old files without axis fields fall back to Z axis at the origin."""
|
||||
sk = Sketch()
|
||||
data = _feature_to_dict(Feature(operation="revolve", angle=90.0))
|
||||
restored = _feature_from_dict(data, {sk.id: sk})
|
||||
self.assertEqual(tuple(restored.axis), (0, 0, 1))
|
||||
self.assertEqual(tuple(restored.origin), (0.0, 0.0, 0.0))
|
||||
self.assertIsNone(restored.axis_line_id)
|
||||
# legacy file without the keys
|
||||
del data["axis"]
|
||||
del data["origin"]
|
||||
del data["axis_line_id"]
|
||||
restored = _feature_from_dict(data, {sk.id: sk})
|
||||
self.assertEqual(tuple(restored.axis), (0, 0, 1))
|
||||
self.assertEqual(tuple(restored.origin), (0.0, 0.0, 0.0))
|
||||
|
||||
|
||||
class TestProjectIO(unittest.TestCase):
|
||||
"""Round-trip the same project through save/load and check equivalence."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user