Skip to content

Commit

Permalink
test_direct_api.py -> add tests/test-methods for str/repr of GroupBy
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegenstein authored Feb 21, 2024
1 parent 38255f4 commit e568d29
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions tests/test_direct_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,21 @@ def test_manifold(self):
class TestShapeList(DirectApiTestCase):
"""Test ShapeList functionality"""

def assertDunderStrEqual(self, actual: str, expected_lines: list[str]):
actual_lines = actual.splitlines()
self.assertEqual(len(actual_lines), len(expected_lines))
for actual_line, expected_line in zip(actual_lines, expected_lines):
start, end = re.split(r"at 0x[0-9a-f]+,", expected_line, 2, re.I)
self.assertTrue(actual_line.startswith(start))
self.assertTrue(actual_line.endswith(end))

def assertDunderReprEqual(self, actual: str, expected: str):
splitter = r"at 0x[0-9a-f]+"
actual_split_list = re.split(splitter, actual, 0, re.I)
expected_split_list = re.split(splitter, expected, 0, re.I)
for actual_split, expected_split in zip(actual_split_list, expected_split_list):
self.assertEqual(actual_split, expected_split)

def test_sort_by(self):
faces = Solid.make_box(1, 2, 3).faces() < SortBy.AREA
self.assertAlmostEqual(faces[-1].area, 2, 5)
Expand Down Expand Up @@ -2965,9 +2980,34 @@ def test_group_by_retrieve_groups(self):

def test_group_by_str_repr(self):
nonagon = RegularPolygon(5,9)
# placeholder for future tests
self.assertTrue(True)


expected = [
"[[<build123d.topology.Edge at 0x1277f6e1cd0>],"
" [<build123d.topology.Edge at 0x1277f6e1c10>,"
" <build123d.topology.Edge at 0x1277fd8a090>],"
" [<build123d.topology.Edge at 0x1277f75d690>,"
" <build123d.topology.Edge at 0x127760d9310>],"
" [<build123d.topology.Edge at 0x12777261f90>,"
" <build123d.topology.Edge at 0x1277f6bd2d0>],"
" [<build123d.topology.Edge at 0x1276fbb0590>,"
" <build123d.topology.Edge at 0x1277fec6d90>]]"
]

assertDunderStrEqual(nonagon.edges().group_by(Axis.X), expected)

expected_repr = (
"[[<build123d.topology.Edge object at 0x000001277FEC6D90>],"
" [<build123d.topology.Edge object at 0x000001277F6BCC10>,"
" <build123d.topology.Edge object at 0x000001277EC3D5D0>],"
" [<build123d.topology.Edge object at 0x000001277F6BEA90>,"
" <build123d.topology.Edge object at 0x000001276FCB2310>],"
" [<build123d.topology.Edge object at 0x000001277F6D10D0>,"
" <build123d.topology.Edge object at 0x000001276FBAAD10>],"
" [<build123d.topology.Edge object at 0x000001277FC86F90>,"
" <build123d.topology.Edge object at 0x000001277F6E1CD0>]]"
)
assertDunderReprEqual(repr(nonagon.edges().group_by(Axis.X)),expected_repr)

def test_distance(self):
with BuildPart() as box:
Box(1, 2, 3)
Expand Down

0 comments on commit e568d29

Please sign in to comment.