Skip to content

Commit 8c487fa

Browse files
committed
Add tests
1 parent 5f13dec commit 8c487fa

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/tree/test_tree.py

+58
Original file line numberDiff line numberDiff line change
@@ -590,5 +590,63 @@ def test_cell_locator(dim):
590590
assert found
591591

592592

593+
class TestRepr:
594+
"""
595+
Test repr methods on TreeMesh.
596+
597+
Check if no error is raised when calling repr methods on a finalized and
598+
non finalized meshes.
599+
"""
600+
601+
@pytest.fixture(params=["2D", "3D"])
602+
def mesh(self, request):
603+
"""Return a sample TreeMesh"""
604+
nc = 16
605+
if request.param == "2D":
606+
h = [nc, nc]
607+
origin = (-32.4, 245.4)
608+
else:
609+
h = [nc, nc, nc]
610+
origin = (-32.4, 245.4, 192.3)
611+
mesh = discretize.TreeMesh(h, origin, diagonal_balance=True)
612+
return mesh
613+
614+
def finalize(self, mesh):
615+
"""
616+
Finalize the sample tree mesh.
617+
"""
618+
origin = mesh.origin
619+
if mesh.dim == 2:
620+
p1 = (origin[0] + 0.4, origin[1] + 0.4)
621+
p2 = (origin[0] + 0.6, origin[1] + 0.6)
622+
mesh.refine_box(p1, p2, levels=5, finalize=True)
623+
else:
624+
p1 = (origin[0] + 0.4, origin[1] + 0.4, origin[2] + 0.7)
625+
p2 = (origin[0] + 0.6, origin[1] + 0.6, origin[2] + 0.9)
626+
mesh.refine_box(p1, p2, levels=5, finalize=True)
627+
628+
@pytest.mark.parametrize("finalize", [True, False])
629+
def test_repr(self, mesh, finalize):
630+
"""
631+
Test if __repr__ doesn't raise errors on any TreeMesh.
632+
"""
633+
if finalize:
634+
self.finalize(mesh)
635+
output = mesh.__repr__()
636+
assert type(output) is str
637+
assert len(output) != 0
638+
639+
@pytest.mark.parametrize("finalize", [True, False])
640+
def test_repr_html(self, mesh, finalize):
641+
"""
642+
Test if _repr_html_ doesn't raise errors on any TreeMesh.
643+
"""
644+
if finalize:
645+
self.finalize(mesh)
646+
output = mesh._repr_html_()
647+
assert type(output) is str
648+
assert len(output) != 0
649+
650+
593651
if __name__ == "__main__":
594652
unittest.main()

0 commit comments

Comments
 (0)