source: nagslang/tests/test_game_object.py@ 124:ae61528436f1

Last change on this file since 124:ae61528436f1 was 124:ae61528436f1, checked in by Jeremy Thurgood <firxen@…>, 7 years ago

Fix test.

File size: 2.0 KB
Line 
1from unittest import TestCase
2
3from nagslang.constants import COLLISION_TYPE_OTHER, SWITCH_PUSHERS
4from nagslang import game_object
5
6
7class FakeShape(object):
8 def __init__(self, collision_type=COLLISION_TYPE_OTHER):
9 self.collision_type = collision_type
10
11
12class FakeSpace(object):
13 def __init__(self, *shapes):
14 self._shapes = shapes
15
16 def shape_query(self, shape):
17 return self._shapes
18
19
20class FakeGameObject(object):
21 def __init__(self, shape, space):
22 self._shape = shape
23 self._space = space
24
25 def get_shape(self):
26 return self._shape
27
28 def get_space(self):
29 return self._space
30
31
32class FakePuzzler(game_object.Puzzler):
33 def __init__(self, fake_state):
34 self.fake_state = fake_state
35
36 def get_state(self):
37 return self.fake_state
38
39
40class TestPuzzles(TestCase):
41 def mkpuzzler(self, gobj, cls, *args, **kw):
42 puzzler = cls(*args, **kw)
43 puzzler.set_game_object(gobj)
44 return puzzler
45
46 def test_floor_switch_puzzler(self):
47 gobj = FakeGameObject(None, FakeSpace())
48 puzzler = self.mkpuzzler(gobj, game_object.FloorSwitchPuzzler)
49 self.assertFalse(puzzler.get_state())
50
51 gobj = FakeGameObject(None, FakeSpace(FakeShape()))
52 puzzler = self.mkpuzzler(gobj, game_object.FloorSwitchPuzzler)
53 self.assertFalse(puzzler.get_state())
54
55 for collision_type in SWITCH_PUSHERS:
56 gobj = FakeGameObject(
57 None, FakeSpace(FakeShape(collision_type)))
58 puzzler = self.mkpuzzler(gobj, game_object.FloorSwitchPuzzler)
59 self.assertTrue(puzzler.get_state())
60
61 def test_state_proxy_puzzler(self):
62 glue = game_object.PuzzleGlue()
63 puzzler = game_object.StateProxyPuzzler('faker')
64 glue.add_component('puzzler', puzzler)
65 faker = FakePuzzler('foo')
66 glue.add_component('faker', faker)
67
68 self.assertEqual('foo', puzzler.get_state())
69 faker.fake_state = 'bar'
70 self.assertEqual('bar', puzzler.get_state())
Note: See TracBrowser for help on using the repository browser.