def test_renderer_events(self): s = Scene(None) class TestRenderer(Renderer): test = 0 def on_draw(self): self.test += 1 sys = TestRenderer(s) s.broadcast('draw') self.assertEquals(sys.test, 1)
def test_system_events(self): s = Scene(None) class TestSystem(System): test = 0 def on_update(self, dt): self.test = dt + 5 sys = TestSystem(s) s.broadcast('update',5) self.assertEquals(sys.test, 10)
def test_entity_retrieval(self): s = Scene(None) for i in range(10): s.entity() for i in range(20): s.entity(components = [ComponentTest]) for i in range(30): s.entity(groups=['test']) self.assertEquals(len(list(s.get())), 60) self.assertEquals(len(list(s.get(ComponentTest))), 20) self.assertEquals(len(list(s.get().is_member_of('test'))), 30)
def test_key_controller_events(self): s = Scene(None) class TestKey(KeyControl): def on_key_press(self, sym, mod): self.sym = sym self.mod = mod def on_key_release(self, sym, mod): self.sym = sym self.mod = mod @KeyControl.key_press(5) def test(self): self.sym = 'works' sys = TestKey(s) s.broadcast('keypress', 13, 0) self.assertEquals(sys.sym, 13) self.assertEquals(sys.mod, 0) s.broadcast('keyrelease', 1, 2) self.assertEquals(sys.sym, 1) self.assertEquals(sys.mod, 2) s.broadcast('keypress', 5, 0) self.assertEquals(sys.sym, 'works')
def test_event_binding(self): s = Scene(None) sys = System() s.bind("test", sys.test) s.broadcast("test", 4) self.assertEquals(sys.result, 4) s.broadcast("test", "result") self.assertEquals(sys.result, "result")
def test_entity_creation(self): s = Scene(None) e = s.entity(components = None, groups = None) self.assertEquals(len(s._entities), 1) s.add_entity(TestEntity()) self.assertEquals(len(s._entities), 2) e = s.entity(components = [ComponentTest]) self.assertEquals(len(s._entities), 3) e = s.entity(components = [ComponentTest], groups = ['one', 'two']) self.assertEquals(len(s._entities), 4)
def test_system_retrieval(self): s = Scene(None) sys = System() s.add_system(sys) self.assertTrue(s.get_system("System") is sys)
def test_system_registration(self): s = Scene(None) s.add_system(System()) self.assertEquals(len(s._system_dict), 1)
def test_controller_registration(self): s = Scene(None) c = Controller(s) s.add_system(c) self.assertTrue(c.scene is s) self.assertTrue(c is s.get_system('Controller'))