class App(object): def __init__(self): self.window = Window(width=800, height=600, title='Breakdown') self.window.add_scene(scene=GameScene(self.window)) def run(self): return self.window.run()
class TestWindow(TestCase): def setUp(self) -> None: self.window = Window(800, 600, 'Test') scene_ref = 'app.scene.scene.Scene' @unittest.mock.patch('pygame.event.get', return_value=[EventMother.quit()]) @unittest.mock.patch(scene_ref) def test_exit_if_scene_ends_without_error(self, events, scene): scene.run.return_value = 0 self.window.add_scene(scene) self.assertEqual(0, self.window.run()) @unittest.mock.patch('pygame.event.get', return_value=[EventMother.quit()]) @unittest.mock.patch(scene_ref) def test_exit_with_error_if_scene_returns_error(self, events, scene): scene.run.return_value = -1 self.window.add_scene(scene) self.assertEqual(-1, self.window.run()) @unittest.mock.patch('pygame.event.get', return_value=[EventMother.quit()]) @unittest.mock.patch(scene_ref) @unittest.mock.patch(scene_ref) def test_exit_with_error_if_any_scene_returns_error( self, events, scene_1, scene_2): scene_1.run.return_value = -1 scene_2.run.return_value = 0 self.window.add_scene(scene_1) self.window.add_scene(scene_2) self.assertEqual(-1, self.window.run())
class App(object): def __init__(self): self.window = Window(800, 600, 'Japong!') self.add_scene(StartScene(self.window)) self.add_scene(GameScene(self.window)) self.add_scene(EndScene(self.window)) def run(self): pygame.init() code = self.window.run() pygame.quit() return code def add_scene(self, scene): self.window.add_scene(scene)
def setUp(self) -> None: ball = Ball(pong.config.white, 10) engine = ComputerControlEngine(ball) self.left_player = Player('left', 'left', engine) self.right_player = Player('right', 'right', engine) self.score_manager = ScoreManager(self.left_player, self.right_player, (1, 5)) self.score_board = ScoreBoard(self.score_manager) self.scene = Scene(Window(100, 100, 'Test'))
def test_should_run_scenes(self): window = Window(800, 600, 'Test') scene = Scene(window) with unittest.mock.patch.object(scene, 'run', wraps=scene.run) as spy: window.add_scene(scene) window.run() spy.assert_called()
def setUp(self) -> None: self.window = Window(800, 600, 'Test')
def __init__(self): self.window = Window(width=800, height=600, title='Breakdown') self.window.add_scene(scene=GameScene(self.window))
def __init__(self): self.window = Window(800, 600, 'Japong!') self.add_scene(StartScene(self.window)) self.add_scene(GameScene(self.window)) self.add_scene(EndScene(self.window))
#!/usr/bin/env python3 from tkinter import * from app.window import Window # Requirement for running: sudo apt-get install python3-tk # Run this file at shell as: ./main.py if __name__ == "__main__": root = Tk() # initializing window root.title("Hashcode") # set the title window = Window(root) # instantiate window window.show() # run program
#Application from app.characters import Characters from app.window import Window from app.enemies import Enemies from app.base import Base #Libreries import random #Create window app = Window() app.setSize(800, 600) app.setName('fffffaff') #Create entities mainCharacter = Characters() mainCharacter.set(sizeHeight=30, sizeWidth=30, positionX=140, positionY=390, color=(0, 0, 255)) enemy = Enemies() enemy.speed = 0.25 enemy.set(sizeHeight=40, sizeWidth=40, positionX=580, positionY=random.randint(20, 780), color=(255, 0, 0)) mainCharacterBase = Base(mainCharacter) mainCharacterBase.set(sizeHeight=40,
def test_should_run_fine(self, mock): window = Window(800, 600, 'title') self.assertEqual(0, window.run())
def test_should_allow_play_again(self): window = Window(800, 600, 'Test') play_again_scene = Scene(window) with unittest.mock.patch.object(play_again_scene, 'run', wraps=play_again_scene.run, side_effect=[1, 0]) as spy: window.add_scene(play_again_scene) self.assertEqual(0, window.run())
def test_should_exit_with_error(self): window = Window(800, 600, 'Test') error_scene = Scene(window) with unittest.mock.patch.object(error_scene, 'run', wraps=error_scene.run, return_value=-1) as spy: window.add_scene(error_scene) self.assertEqual(-1, window.run())
def test_should_add_scenes(self): window = Window(800, 600, 'Test') window.add_scene(Scene(window)) self.assertEqual(1, len(window.scenes))