def test_get_name(self): """Ensure correct name for CD drive.""" cd_name = self._cd.get_name() response = question('Is the correct name for the CD drive [{}]?' ''.format(cd_name)) self.assertTrue(response)
def test_set_gamma_ramp(self): os.environ["SDL_VIDEO_WINDOW_POS"] = "100,250" pygame.display.quit() pygame.display.init() screen = pygame.display.set_mode((400, 100)) screen.fill((100, 100, 100)) blue_ramp = [x * 256 for x in range(0, 256)] blue_ramp[100] = 150 * 256 # Can't tint too far or gamma ramps fail normal_ramp = [x * 256 for x in range(0, 256)] # test to see if this platform supports gamma ramps gamma_success = False if pygame.display.set_gamma_ramp(normal_ramp, normal_ramp, blue_ramp): pygame.display.update() gamma_success = True if gamma_success: response = question("Is the window background tinted blue?") self.assertTrue(response) # restore normal ramp pygame.display.set_gamma_ramp(normal_ramp, normal_ramp, normal_ramp) pygame.display.quit()
def test_get_count(self): """Ensure the correct number of CD drives can be detected.""" count = pygame.cdrom.get_count() response = question('Is the correct number of CD drives on this ' 'system [{}]?'.format(count)) self.assertTrue(response)
def test_get_name(self): """Ensure correct name for CD drive.""" if self.cd: cd_name = self.cd.get_name() self.assertTrue( question('Is %s the correct name for the CD drive?' % cd_name))
def test_get_empty(self): """Ensure correct name for CD drive.""" prompt("Please ensure the CD drive is closed") is_empty = self._cd.get_empty() response = question('Is the CD drive empty?') self.assertEqual(is_empty, response)
def test_get_count_interactive(self): # Test get_count correctly identifies number of connected joysticks prompt(( "Please connect any joysticks/controllers now before starting the " "joystick.get_count() test.")) pygame.joystick.init() # pygame.joystick.get_count(): return count # number of joysticks on the system, 0 means no joysticks connected count = pygame.joystick.get_count() response = question(( "NOTE: Having Steam open may add an extra virtual controller for " "each joystick/controller physically plugged in.\n" "joystick.get_count() thinks there is [{}] joystick(s)/controller(s)" "connected to this system. Is this correct?".format(count))) self.assertTrue(response) # When you create Joystick objects using Joystick(id), you pass an # integer that must be lower than this count. # Test Joystick(id) for each connected joystick if count != 0: for x in range(count): pygame.joystick.Joystick(x) with self.assertRaises(pygame.error): pygame.joystick.Joystick(count) pygame.joystick.quit()
def test_eject(self): """Ensure CD drive opens/ejects.""" self._cd.eject() response = question('Did the CD eject?') self.assertTrue(response) prompt("Please close the CD drive")
def test_eject(self): """Ensure CD drive opens/ejects.""" # should raise if cd object not initialized if self.cd: self.cd.init() self.cd.eject() self.assertTrue(question('Did the CD eject?')) prompt("Please close the CD drive.")
def test_2_get_name(self): # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_name: # CD.get_name(): return name # the system name of the cdrom drive if self.cd: cd_name = self.cd.get_name() self.assert_( question('Is %s the correct name for the cd drive?' % cd_name))
def test_2_get_name(self): # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_name: # CD.get_name(): return name # the system name of the cdrom drive if self.cd: cd_name = self.cd.get_name() self.assert_ ( question('Is %s the correct name for the cd drive?' % cd_name) )
def test__get_count_interactive(self): prompt("Please connect at least one controller " "before the test for controller.get_count() starts") # Reset the number of joysticks counted controller.quit() controller.init() joystick_num = controller.get_count() ans = question("get_count() thinks there are {} joysticks " "connected. Is that correct?".format(joystick_num)) self.assertTrue(ans)
def test_get_finger(self): """ask for touch input and check the dict""" pygame.display.init() pygame.font.init() os.environ['SDL_VIDEO_WINDOW_POS'] = '50,50' screen = pygame.display.set_mode((800, 600)) screen.fill((255, 255, 255)) font = pygame.font.Font(None, 32) instructions_str_1 = 'Please place some fingers on your touch device' instructions_str_2 = ('Close the window when finished, ' 'and answer the question') inst_1_render = font.render(instructions_str_1, True, pygame.Color('#000000')) inst_2_render = font.render(instructions_str_2, True, pygame.Color('#000000')) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False finger_data_renders = [] num_devices = pygame._sdl2.touch.get_num_devices() if num_devices > 0: first_device = pygame._sdl2.touch.get_device(0) num_fingers = pygame._sdl2.touch.get_num_fingers(first_device) if num_fingers > 0: for finger_index in range(0, num_fingers): data = pygame._sdl2.touch.get_finger( first_device, finger_index) render = font.render('finger - ' + str(data), True, pygame.Color('#000000')) finger_data_renders.append(render) screen.fill((255, 255, 255)) screen.blit(inst_1_render, (5, 5)) screen.blit(inst_2_render, (5, 40)) for index, finger in enumerate(finger_data_renders): screen.blit(finger, (5, 80 + (index * 40))) pygame.display.update() response = question("Does the finger data seem correct?") self.assertTrue(response) pygame.display.quit()
def test_1_eject(self): # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.eject: # CD.eject(): return None # eject or open the cdrom drive # should raise if cd object not initialized if self.cd: self.cd.init() self.cd.eject() self.assert_(question('Did the cd eject?')) prompt("Please close the cd drive")
def test_set_icon_interactive(self): os.environ["SDL_VIDEO_WINDOW_POS"] = "100,250" pygame.display.quit() pygame.display.init() test_icon = pygame.Surface((32, 32)) test_icon.fill((255, 0, 0)) pygame.display.set_icon(test_icon) screen = pygame.display.set_mode((400, 100)) pygame.display.set_caption("Is the window icon a red square?") response = question("Is the display icon red square?") self.assertTrue(response) pygame.display.quit()
def test_set_icon_interactive(self): # on my computer, the window was being created off-screen # thus i set the window position manually os.environ['SDL_VIDEO_WINDOW_POS'] = '100,250' test_icon = pygame.Surface((32, 32)) test_icon.fill((255, 0, 0)) pygame.display.set_icon(test_icon) screen = pygame.display.set_mode((400, 100)) pygame.display.set_caption("Is the icon to the left a red square?") response = question("Is the display icon red square?") self.assertTrue(response) pygame.display.quit()
def question(self, qstr): """since this is the interactive sublcass we ask a question.""" question(qstr)