Skip to content

Commit 1beacc9

Browse files
committed
A few more basic models tests
1 parent 4b2c15e commit 1beacc9

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/test_models.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,68 @@ def test_cone(self):
8484
self.assertAlmostEqual(mesh.volume, math.pi/3, places=int(math.log10(segments)))
8585

8686

87+
class TestBasicFunctionality(utils.TestCase):
88+
def tearDown(self):
89+
Model.flush_caches(0, 0)
90+
91+
def test_equality(self):
92+
self.assertTrue(Model.box() == Model.box())
93+
self.assertFalse(Model.box() == Model.sphere())
94+
95+
def test_str(self):
96+
self.assertEqual(str(Model.sphere(128)), '!sphere-128')
97+
98+
def test_repr(self):
99+
self.assertEqual(repr(Model.sphere(128)), '<Model: !sphere-128>')
100+
101+
def test_by_name(self):
102+
self.assertIsNone(Model.by_name('!sphere-104'))
103+
model = Model.sphere(104)
104+
self.assertIs(Model.by_name('!sphere-104'), model)
105+
106+
107+
class MyModel(Model):
108+
@staticmethod
109+
def get():
110+
model = Model.by_name('!mymodel')
111+
if model is None:
112+
model = MyModel('!mymodel')
113+
return model
114+
115+
def is_smooth(self):
116+
return False
117+
118+
def check_for_changes(self):
119+
pass
120+
121+
def build_trimesh(self):
122+
return trimesh.Trimesh(vertices=[[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]],
123+
faces=[[0, 1, 2], [2, 3, 0]])
124+
125+
126+
class TestSubclassing(utils.TestCase):
127+
def tearDown(self):
128+
Model.flush_caches(0, 0)
129+
130+
def test_subclass_insantiation(self):
131+
model = MyModel.get()
132+
self.assertIsInstance(model, MyModel)
133+
self.assertEqual(model.name, '!mymodel')
134+
self.assertIs(MyModel.get(), model)
135+
mesh = model.get_trimesh()
136+
self.assertIs(model.get_trimesh(), mesh)
137+
self.assertAllAlmostEqual(mesh.vertices, [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
138+
self.assertAllAlmostEqual(mesh.faces, [[0, 1, 2], [2, 3, 0]])
139+
self.assertEqual(model.snap_edges().name, 'snap_edges(!mymodel)')
140+
141+
def test_bad_manifold(self):
142+
model = MyModel.get()
143+
with unittest.mock.patch('flitter.render.window.models.logger') as mock_logger:
144+
manifold = model.get_manifold()
145+
mock_logger.error.assert_called_with("Mesh is not a volume: {}", model.name)
146+
self.assertIsNone(manifold)
147+
148+
87149
class TestManifoldPrimitives(utils.TestCase):
88150
def tearDown(self):
89151
Model.flush_caches(0, 0)
@@ -389,6 +451,10 @@ class TestTrim(utils.TestCase):
389451
def tearDown(self):
390452
Model.flush_caches(0, 0)
391453

454+
def test_bad_arguments(self):
455+
self.assertIsNone(Model.box().trim(None, [1, 0, 0]))
456+
self.assertIsNone(Model.box().trim(0, None))
457+
392458
def test_trim_sphere_to_box(self):
393459
model = Model.sphere()
394460
for x in (-1, 1):
@@ -429,6 +495,11 @@ def setUp(self):
429495
def tearDown(self):
430496
Model.flush_caches(0, 0)
431497

498+
def test_ignored_none(self):
499+
self.assertEqual(Model.union(Model.box(), None, Model.sphere()).name, 'union(!box, !sphere)')
500+
self.assertEqual(Model.intersect(Model.box(), None, Model.sphere()).name, 'intersect(!box, !sphere)')
501+
self.assertEqual(Model.difference(Model.box(), None, Model.sphere()).name, 'difference(!box, !sphere)')
502+
432503
def test_nested_box_union(self):
433504
model = Model.union(*self.nested_box_models)
434505
mesh = model.get_trimesh()

0 commit comments

Comments
 (0)