Skip to content

Commit daaaee9

Browse files
committed
Add test for dynamic 0 mass bodies
1 parent c1d222a commit daaaee9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pymunk/space.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def add_post_step_callback(
660660
self,
661661
callback_function: Callable[
662662
..., None
663-
], # TODO: Fix me once PEP-612 is implemented
663+
], # TODO: Fix me once PEP-612 is implemented (py 3.10)
664664
key: Hashable,
665665
*args: Any,
666666
**kwargs: Any,

pymunk/tests/test_body.py

+29
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,35 @@ def test_static(self) -> None:
171171
b = p.Body(body_type=p.Body.STATIC)
172172
self.assertEqual(b.body_type, p.Body.STATIC)
173173

174+
def test_mass(self) -> None:
175+
s = p.Space()
176+
b = p.Body()
177+
178+
b.mass = 2
179+
s.add(b)
180+
181+
# Cant set 0 mass on Body in Space
182+
with self.assertRaises(AssertionError):
183+
b.mass = 0
184+
185+
s.remove(b)
186+
b.mass = 0
187+
s.add(b)
188+
# Cant add 0 mass Body to Space and run step
189+
with self.assertRaises(AssertionError):
190+
s.step(1)
191+
192+
c = p.Circle(b, 1)
193+
s.add(c)
194+
195+
# Same with a Shape
196+
with self.assertRaises(AssertionError):
197+
s.step(1)
198+
199+
# Setting the Shape mass or density should fix it
200+
c.density = 10
201+
s.step(1)
202+
174203
def test_mass_moment_from_shape(self) -> None:
175204
s = p.Space()
176205

0 commit comments

Comments
 (0)