-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_plato.py
95 lines (77 loc) · 2.79 KB
/
test_plato.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright (c) 2015-2025 The Regents of the University of Michigan.
# This file is from the coxeter project, released under the BSD 3-Clause License.
import tempfile
import pytest
import coxeter
try:
import matplotlib
matplotlib.use("Agg")
import plato.draw.matplotlib # noqa: F401
MATPLOTLIB_PLATO_AVAILABLE = True
except ImportError:
MATPLOTLIB_PLATO_AVAILABLE = False
@pytest.mark.skipif(
not MATPLOTLIB_PLATO_AVAILABLE,
reason="plato and matplotlib are required for this test.",
)
def test_draw_circle():
circle = coxeter.shapes.Circle(1)
scene = circle.to_plato_scene("matplotlib", scene_kwargs=dict(zoom=10))
with tempfile.NamedTemporaryFile(suffix=".png") as tmp:
scene.save(tmp.name)
@pytest.mark.skipif(
not MATPLOTLIB_PLATO_AVAILABLE,
reason="plato and matplotlib are required for this test.",
)
def test_draw_polygon():
polygon = coxeter.shapes.Polygon([[0, 0], [1, 0], [0, 1]])
scene = polygon.to_plato_scene("matplotlib", scene_kwargs=dict(zoom=10))
with tempfile.NamedTemporaryFile(suffix=".png") as tmp:
scene.save(tmp.name)
@pytest.mark.skipif(
not MATPLOTLIB_PLATO_AVAILABLE,
reason="plato and matplotlib are required for this test.",
)
def test_draw_convex_polygon():
polygon = coxeter.shapes.ConvexPolygon([[0, 0], [1, 0], [0, 1]])
scene = polygon.to_plato_scene("matplotlib", scene_kwargs=dict(zoom=10))
with tempfile.NamedTemporaryFile(suffix=".png") as tmp:
scene.save(tmp.name)
@pytest.mark.skipif(
not MATPLOTLIB_PLATO_AVAILABLE,
reason="plato and matplotlib are required for this test.",
)
def test_draw_spheropolygon():
spheropolygon = coxeter.shapes.ConvexSpheropolygon([[0, 0], [1, 0], [0, 1]], 0.3)
scene = spheropolygon.to_plato_scene("matplotlib", scene_kwargs=dict(zoom=10))
with tempfile.NamedTemporaryFile(suffix=".png") as tmp:
scene.save(tmp.name)
@pytest.mark.skipif(
not MATPLOTLIB_PLATO_AVAILABLE,
reason="plato and matplotlib are required for this test.",
)
def test_draw_sphere():
sphere = coxeter.shapes.Sphere(1)
scene = sphere.to_plato_scene("matplotlib", scene_kwargs=dict(zoom=10))
with tempfile.NamedTemporaryFile(suffix=".png") as tmp:
scene.save(tmp.name)
@pytest.mark.skipif(
not MATPLOTLIB_PLATO_AVAILABLE,
reason="plato and matplotlib are required for this test.",
)
def test_draw_convex_polyhedron():
cube = coxeter.shapes.ConvexPolyhedron(
[
[0, 0, 0],
[0, 1, 0],
[1, 1, 0],
[1, 0, 0],
[0, 0, 1],
[0, 1, 1],
[1, 1, 1],
[1, 0, 1],
]
)
scene = cube.to_plato_scene("matplotlib", scene_kwargs=dict(zoom=10))
with tempfile.NamedTemporaryFile(suffix=".png") as tmp:
scene.save(tmp.name)