def test_layers_game(self): game = Game() game.working_directory = "/home/luke/Projects/pyvida/test_data" s = Scene("testscene") game.immediate_add(s) s._load_layer("scenes/title/background.png") assert len(s.layers) == 1 assert list(game.items.keys()) == ["testscene_background"]
def test_get_best_file(self, use_game, working_dir, fname, expected): # '../../../../../Projects/pyvida/test_data/data/actors/Adam/idle.montage' game = Game() if use_game else None if game: game.working_directory = working_dir f = get_best_file(game, fname) assert expected in f
def test_play_soft(self): game = Game(resolution=(100, 100)) game.autoscale = False p = PlayerPygletSFX(game) p.load("test_data/data/sfx/achievement.ogg", 0.3) assert p._sound p.play() sleep(1.2)
def test_smart(self): game = Game(resolution=(100, 100)) game.autoscale = False game.working_directory = "/home/luke/Projects/pyvida/test_data" a = Actor("Adam") a.smart(game) assert list(a.actions.keys()) == ["idle"] assert a.resource_name == "Adam"
def test_play_loop(self): game = Game(resolution=(100, 100)) game.autoscale = False game.init() p = PlayerPygletMusic(game) p.load("test_data/data/music/dos4gw_newwake.ogg") assert p._music p.play(loops=1) while p.busy(): pyglet.clock.tick() pyglet.app.platform_event_loop.dispatch_posted_events()
def test_immediate_splash(self): game = Game() game.result = False def hello(*args, **kwargs): game.result = True game.immediate_splash(Path( TEST_PATH, "test_data/data/interface/test.png").as_posix(), callback=hello) assert game.result is True
def set_up(self): self.game = Game("Unit Tests", fps=60, afps=16, resolution=RESOLUTION) self.game.settings = Settings() self.actor = Actor("_test_actor").smart(self.game) self.msgbox = Item("msgbox").smart(self.game, using="data/items/_test_item") self.ok = Item("ok").smart(self.game, using="data/items/_test_item") self.scene = Scene("_test_scene") self.item = Item("test_item") self.game.add( [self.scene, self.actor, self.msgbox, self.ok, self.item]) self.scene.immediate_add(self.actor) self.game.scene = self.scene
def setup(self): g = Game() m = MotionManager() m.game = g mt = Motion("jump") m.motions["jump"] = mt return g, m
def test_load_assets(self): game = Game(resolution=(100, 100)) game.autoscale = False game.working_directory = "/home/luke/Projects/pyvida/test_data" a = Actor("Adam") a.smart(game) a.load_assets(game) resource = get_resource(a.resource_name) action = a.get_action() assert resource[0] == 249 assert resource[1] == 341 assert action.w == 249 assert action.h == 341 assert type(resource[2]) == PyvidaSprite assert list(a.actions.keys()) == ["idle"]
def test_use_on_events(self): g = Game() m = MotionManagerOld() m.game = g m.motion("jump", 'test2', destructive=True) event = g.events[0] assert event[0].__name__ == "on_motion" assert event[1:] == (m, ('jump', 'test2'), {'destructive': True})
def test_decorator(self): g = Game() m = MotionManagerOld() m.game = g m.decorator_test("photograph", ringo=True) event = g.events[0] assert event[0].__name__ == "decorator_test" assert event[1:] == (m, ('photograph', ), {'ringo': True})
def test_both(self): g = Game() m = MotionManagerOld() m.game = g m.decorator_test("photograph", ringo=True) m.motion("jump", 'test2', destructive=True) event0 = g.events[0] event1 = g.events[1] assert event0[1:] == (m, ('photograph', ), {'ringo': True}) assert event1[1:] == (m, ('jump', 'test2'), {'destructive': True})
def test_reset_window(self): res = [100, 100] game = Game() game.autoscale = False game.resolution = res game._window = MagicMock() game._window.get_size.return_value = res game.reset_window(fullscreen=False, create=False) assert game.fullscreen == False
class TestEvents: def set_up(self): self.game = Game("Unit Tests", fps=60, afps=16, resolution=RESOLUTION) self.game.settings = Settings() self.actor = Actor("_test_actor").smart(self.game) self.msgbox = Item("msgbox").smart(self.game, using="data/items/_test_item") self.ok = Item("ok").smart(self.game, using="data/items/_test_item") self.scene = Scene("_test_scene") self.item = Item("test_item") self.game.add( [self.scene, self.actor, self.msgbox, self.ok, self.item]) self.scene.immediate_add(self.actor) self.game.scene = self.scene def test_relocate(self): # setup self.set_up() self.actor.relocate(self.scene) event = self.game.events[0] assert len(self.game.events) == 1 assert event[0].__name__ == "relocate" assert event[1] == self.actor assert event[2][0] == self.scene
def test_smart_basic(self): game = Game("Test", "1.0", "1.0", "testpyvida", fps=16, afps=16, resolution=(100, 100)) game.autoscale = False game.working_directory = TEST_PATH game.immediate_smart() assert len(game.items) == 2 assert len(game.actors) == 4 assert len(game.scenes) == 1
def test_create_bars_and_scale(self, screen_size, game_resolution, window_size, scaling_factor, expected_displacement): # Fit game to requested window size game = Game() game.resolution = game_resolution # the native size of the game graphics game._window = MagicMock() game._window.get_size.return_value = screen_size game.create_bars_and_scale(screen_size[0], screen_size[0], scaling_factor) assert game._window_dx == expected_displacement[ 0] # displacement by fullscreen mode assert game._window_dy == expected_displacement[ 1] # displacement by fullscreen mode
def test_handle_events(self): game = Game("Unit Tests", fps=60, afps=16, resolution=RESOLUTION)
def test_screen(self): g = Game() assert g.screen assert type(g.screen) == pyglet.canvas.xlib.XlibScreen
def test_screens(self): g = Game() assert len(g.screens) == 2
def test_scene_with_item(self): game = Game("Test", "1.0", "1.0", "testpyvida", fps=16, afps=16, resolution=(1680, 1050)) game.autoscale = False game.working_directory = "/home/luke/Projects/pyvida/test_data" game.init() game.smart() game.queue_load_state("title", "initial") game.camera.scene("title") game.update() # run events logo = game.scene.get_object("logo") assert game.w == 1680 assert not game.autoscale assert game.scene == game.scenes["title"] assert game.scene.layers[0] == "title_background" assert logo
def test_immediate_toggle_fullscreen(self): game = Game() game.immediate_toggle_fullscreen(True, False) assert game.settings.fullscreen is True
def test_game_init(self): g = Game(resolution=(100, 100)) g.autoscale = False g.init() assert g.resolution == (100, 100)
def create_basic_scene(resolution=(1680, 1050), with_update=False): game = Game("Test", "1.0", "1.0", "testpyvida", fps=16, afps=16, resolution=resolution) game.autoscale = False game.working_directory = "/home/luke/Projects/pyvida/test_data" game.init() game.smart() game.queue_load_state("title", "initial") game.camera.scene("title") if with_update: game.update() # perform all the queued events return game
def test_init(self): game = Game() p = PlayerPygletMusic(game) assert not p._music
def test_scene_with_menu(self): game = Game("Test", "1.0", "1.0", "testpyvida", fps=16, afps=16, resolution=(1680, 1050)) game.autoscale = False game.working_directory = "/home/luke/Projects/pyvida/test_data" mx, my = game.resolution[0] / 2 - 100, 140 # game.resolution[1]-50 game.add(MenuFactory("menu", (mx, my))) game.immediate_menu_from_factory("menu", [ ("menu_new", MagicMock()), ("menu_old", MagicMock()), ]) game.init() game.smart() game.queue_load_state("title", "initial") game.camera.scene("title") game.set_menu(*["menu_new", "menu_old"], clear=True) game.menu.show() game.update() # run events assert game.w == 1680 assert not game.autoscale assert game.scene == game.scenes["title"] assert game.scene.layers[0] == "title_background" assert game.scene.get_object("logo")
def test_init(self): game = Game(resolution=(100, 100)) game.autoscale = False p = PlayerPygletSFX(game) assert not p._sound