From d2d979cde07eb05c708e560dfa6f0ab8bd17cac5 Mon Sep 17 00:00:00 2001 From: Jonathan Wagenet Date: Fri, 11 Apr 2025 12:11:47 -0400 Subject: [PATCH] make_text: add enum and ValueError tests --- src/build123d/topology/composite.py | 8 ++++++-- tests/test_build_enums.py | 1 + tests/test_build_sketch.py | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/build123d/topology/composite.py b/src/build123d/topology/composite.py index cc33a10..63bdb14 100644 --- a/src/build123d/topology/composite.py +++ b/src/build123d/topology/composite.py @@ -325,7 +325,10 @@ class Compound(Mixin3D, Shape[TopoDS_Compound]): }[font_style] if text_align[0] not in [TextAlign.LEFT, TextAlign.CENTER, TextAlign.RIGHT]: - raise ValueError("Horizontal TextAlign must be LEFT, CENTER, or RIGHT") + raise ValueError( + "Horizontal TextAlign must be LEFT, CENTER, or RIGHT. " + f"Got {text_align[0]}" + ) if text_align[1] not in [ TextAlign.BOTTOM, @@ -334,7 +337,8 @@ class Compound(Mixin3D, Shape[TopoDS_Compound]): TextAlign.TOPFIRSTLINE, ]: raise ValueError( - "Vertical TextAlign must be BOTTOM, CENTER, TOP, or TOPFIRSTLINE" + "Vertical TextAlign must be BOTTOM, CENTER, TOP, or TOPFIRSTLINE. " + f"Got {text_align[1]}" ) horiz_align = { diff --git a/tests/test_build_enums.py b/tests/test_build_enums.py index 7d06964..df7ba9b 100644 --- a/tests/test_build_enums.py +++ b/tests/test_build_enums.py @@ -55,6 +55,7 @@ class TestEnumRepr(unittest.TestCase): Side, SortBy, Transition, + TextAlign, Unit, Until, ] diff --git a/tests/test_build_sketch.py b/tests/test_build_sketch.py index a29e723..0e2e062 100644 --- a/tests/test_build_sketch.py +++ b/tests/test_build_sketch.py @@ -370,6 +370,12 @@ class TestBuildSketchObjects(unittest.TestCase): self.assertEqual(len(test.sketch.faces()), 4) self.assertEqual(t.faces()[0].normal_at(), Vector(0, 0, 1)) + with self.assertRaises(ValueError): + Text("test", 2, text_align=(TextAlign.BOTTOM, TextAlign.BOTTOM)) + + with self.assertRaises(ValueError): + Text("test", 2, text_align=(TextAlign.LEFT, TextAlign.LEFT)) + def test_trapezoid(self): with BuildSketch() as test: t = Trapezoid(6, 2, 63.434948823)