Skip to content

Commit bf47f12

Browse files
authored
Fixed font-related test error on some platforms (#1577)
* Fixed font-related test error on some platforms * Use OpenSans font in testdata directory * Fix lack of font path robustness * Switched to a global text font variable * Implement pathlib suggestion
1 parent 1bdc28f commit bf47f12

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tests/test_cadquery.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
# system modules
66
import math, os.path, time, tempfile
7+
from pathlib import Path
78
from random import random
89
from random import randrange
910
from itertools import product
@@ -24,7 +25,8 @@
2425
)
2526

2627
# test data directory
27-
testdataDir = os.path.join(os.path.dirname(__file__), "testdata")
28+
testdataDir = Path(__file__).parent.joinpath("testdata")
29+
testFont = str(testdataDir / "OpenSans-Regular.ttf")
2830

2931
# where unit test output will be saved
3032
OUTDIR = tempfile.gettempdir()
@@ -3843,7 +3845,7 @@ def testText(self):
38433845
"CQ 2.0",
38443846
0.5,
38453847
0.05,
3846-
fontPath=os.path.join(testdataDir, "OpenSans-Regular.ttf"),
3848+
fontPath=testFont,
38473849
cut=False,
38483850
combine=False,
38493851
halign="right",
@@ -3863,7 +3865,7 @@ def testText(self):
38633865
"CQ 2.0",
38643866
0.5,
38653867
0.05,
3866-
fontPath=os.path.join(testdataDir, "OpenSans-Irregular.ttf"),
3868+
fontPath=testFont,
38673869
cut=False,
38683870
combine=False,
38693871
halign="right",
@@ -3885,17 +3887,23 @@ def testText(self):
38853887
)
38863888

38873889
def testTextAlignment(self):
3888-
left_bottom = Workplane().text("I", 10, 0, halign="left", valign="bottom")
3890+
left_bottom = Workplane().text(
3891+
"I", 10, 0, halign="left", valign="bottom", fontPath=testFont,
3892+
)
38893893
lb_bb = left_bottom.val().BoundingBox()
38903894
self.assertGreaterEqual(lb_bb.xmin, 0)
38913895
self.assertGreaterEqual(lb_bb.ymin, 0)
38923896

3893-
centers = Workplane().text("I", 10, 0, halign="center", valign="center")
3897+
centers = Workplane().text(
3898+
"I", 10, 0, halign="center", valign="center", fontPath=testFont,
3899+
)
38943900
c_bb = centers.val().BoundingBox()
38953901
self.assertAlmostEqual(c_bb.center.x, 0, places=0)
38963902
self.assertAlmostEqual(c_bb.center.y, 0, places=0)
38973903

3898-
right_top = Workplane().text("I", 10, 0, halign="right", valign="top")
3904+
right_top = Workplane().text(
3905+
"I", 10, 0, halign="right", valign="top", fontPath=testFont,
3906+
)
38993907
rt_bb = right_top.val().BoundingBox()
39003908
self.assertLessEqual(rt_bb.xmax, 0)
39013909
self.assertLessEqual(rt_bb.ymax, 0)

0 commit comments

Comments
 (0)