|
1 | 1 | from __future__ import print_function, division, absolute_import |
2 | 2 |
|
3 | | -import sys |
| 3 | +import math |
4 | 4 | import os |
| 5 | +import sys |
5 | 6 | import unittest |
6 | 7 |
|
7 | 8 | import pytest |
|
14 | 15 | VERBOSE = False |
15 | 16 |
|
16 | 17 |
|
| 18 | +def _approx_equal(a, b): |
| 19 | + """Check if two values are approximately equal, handling nested structures. |
| 20 | +
|
| 21 | + Uses math.isclose for float comparison to handle minor differences between |
| 22 | + fonttools versions in splitCubicAtT precision. |
| 23 | + """ |
| 24 | + if type(a) != type(b): |
| 25 | + return False |
| 26 | + if isinstance(a, (tuple, list)): |
| 27 | + if len(a) != len(b): |
| 28 | + return False |
| 29 | + return all(_approx_equal(x, y) for x, y in zip(a, b)) |
| 30 | + if isinstance(a, float): |
| 31 | + return math.isclose(a, b) |
| 32 | + return a == b |
| 33 | + |
| 34 | + |
17 | 35 | class BooleanTests(unittest.TestCase): |
18 | 36 |
|
19 | 37 | pass |
@@ -47,7 +65,10 @@ def test(self): |
47 | 65 | func(*args, outPen=testPen) |
48 | 66 | expectedPen = DigestPointPen() |
49 | 67 | expectedGlyph.drawPoints(expectedPen) |
50 | | - self.assertEqual(testPen.getDigest(), expectedPen.getDigest(), "Glyph name '%s' failed for '%s'." % (glyph.name, booleanMethodName)) |
| 68 | + self.assertTrue( |
| 69 | + _approx_equal(testPen.getDigest(), expectedPen.getDigest()), |
| 70 | + "Glyph name '%s' failed for '%s'." % (glyph.name, booleanMethodName) |
| 71 | + ) |
51 | 72 |
|
52 | 73 | return True, test |
53 | 74 |
|
|
0 commit comments