def test_square_fades(self): # we may change the actual colors, so just make sure the # color before and after the switch are different old_color = self.w.sequences.square.square.getColor() # print 'color', old_color square_on = True on = False # print 'start loop' check = self.w.sequences.current_task # need to show the square, and then get to the dim square method while square_on: taskMgr.step() if self.w.sequences.current_task != check: check = self.w.sequences.current_task # print 'new task', check # print 'square now at', self.w.sequences.square.square.getPos() if self.w.sequences.current_task == 1 and not on: # make sure we will fade, only want to run this once... # print 'move eye data' self.move_eye_to_get_reward() on = True # print 'moved eye' if self.w.sequences.current_task is None: # print 'restarted loop' # in case we missed the fixation interval self.w.start_main_loop() if self.w.sequences.current_task == 2 and on: # print 'square now at', self.w.sequences.square.square.getPos() # print 'square should be dim' square_on = False # print self.w.sequences.square.square.getColor() self.assertNotEqual(self.w.sequences.square.square.getColor(), old_color)
def load(self, renderer): """Load level from disk""" fileManagerOutputLog.debug(directory + normpath("data/" + self.name + ".dat")) self.file = open(directory + normpath("data/" + self.name + ".world"), 'rb') self.mapmap = pickle.load(self.file) self.file.close() self.name = self.mapmap['name'] self.displayname = self.mapmap['displayname'] self.sizex = self.mapmap['sizex'] self.sizey = self.mapmap['sizey'] self.sizez = self.mapmap['sizez'] self.playerx = self.mapmap['playerx'] self.playery = self.mapmap['playery'] self.playerz = self.mapmap['playerz'] for chunkx in range(int(self.playerx / 16 - 5), int(self.playerx / 16 + 6)): # Generate worldmap for chunky in range(int(self.playery / 16 - 5), int(self.playery / 16 + 6)): for chunkz in range(int(self.playerz / 16 - 5), int(self.playerz / 16 + 6)): if chunkx >= 0 and chunky >= 0 and chunkz >= 0: self.worldmap[str(chunkx)][str(chunky)][int( chunkz)] = chunk(self, abs(chunkx), abs(chunky), abs(chunkz), renderer) renderer.mouseWatchTask(renderer.worldin) taskMgr.step() pass pass pass pass
def test_timing_on_to_fade_if_fixated(self): # once subject fixates, on for fix_interval # First get to on square_off = True a = 0 while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' a = datetime.datetime.now() square_off = False # make sure looking at right place self.move_eye_to_get_reward() # now wait for fade: square_on = True while square_on: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 2: # print 'square should be on' square_on = False b = datetime.datetime.now() c = b - a # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure really on, sanity check self.assertTrue(self.w.sequences.square.square.getParent()) # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval # use fix interval, since fake data will start it right away in fixation window self.assertAlmostEqual(c.total_seconds(), self.config['FIX_INTERVAL'][0], 1)
def test_on_after_manual_move(self): print('test_on_after_manual_move') # make sure square goes on after manual move # wait for square to turn off, then send signal to move square_off = False while not square_off: taskMgr.step() # print self.w.sequences.current_task if self.w.sequences.current_task > 2: square_off = True if self.w.sequences.current_task is None: self.w.start_main_loop() print 'done with first loop' # make sure square is off before = self.w.sequences.square.square.getParent() # and move self.w.key_dict["switch"] = 3 # we wait until it comes back on print 'sent key switch signal' square_off = True while square_off: taskMgr.step() # print self.w.sequences.current_task # does not loop automatically in unittest mode if self.w.sequences.current_task is None: self.w.start_main_loop() if self.w.sequences.current_task == 1: square_off = False # print 'move' # print self.w.sequences.square.square.getParent() self.assertTrue(self.w.sequences.square.square.getParent()) # print 'next test?' # double check square was off to begin with self.assertNotEqual(self.w.sequences.square.square.getParent(), before)
def test_timing_fade_on_to_off(self): print('test_timing_fade_on_to_off') # First get to fade on square_dim = True square_fade = True a = 0 b = 0 while square_dim: taskMgr.step() a = datetime.datetime.now() # if taskTask.now changes to 2, then we have just faded if self.w.sequences.current_task == 2: # print 'square should be faded' square_dim = False # now wait for fade off: while square_fade: taskMgr.step() b = datetime.datetime.now() # if taskTask.now changes to 3, then we have just turned off # if reward interval is zero (usual for our configs), will skip # 3 and go to 4, but that is fine, since we are then measuring # the same interval if self.w.sequences.current_task > 2: square_fade = False c = b - a # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure really off, sanity check self.assertFalse(self.w.sequences.square.square.getParent()) # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval self.assertAlmostEqual(c.total_seconds(), self.config['FADE_INTERVAL'][0], 1)
def test_timing_on_to_fade(self): print('test_timing_on_to_fade') # First get to on square_off = True # print 'time on to fade' a = 0 b = 0 while square_off: taskMgr.step() a = datetime.datetime.now() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False # now wait for fade: square_on = True while square_on: taskMgr.step() b = datetime.datetime.now() # if taskTask.now changes to 2, then we have just faded if self.w.sequences.current_task == 2: # print 'square should be faded' square_on = False c = b - a # print 'c', c.total_seconds() # check that time is close # make sure really on, sanity check self.assertTrue(self.w.sequences.square.square.getParent()) interval = self.config['ON_INTERVAL'][0] # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval self.assertAlmostEqual(c.total_seconds(), interval, 1)
def test_no_reward_if_not_looking(self): # First get ready for square on. # make sure looking at right (wrong) place # move eye away from square self.move_eye_to_get_reward('not') square_off = True while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False # now wait for self.w.sequences.current_task to change again, will run through # turning off, bad fixation and switch to None all at once no_change = True while no_change: taskMgr.step() if self.w.sequences.current_task != 1: no_change = False # print 'end second loop', self.w.sequences.current_task # next step should not be reward or square dims, should be # 6, bad fixation self.assertNotEqual(self.w.sequences.current_task, 2) self.assertNotEqual(self.w.sequences.current_task, 3) self.assertEqual(self.w.sequences.current_task, 6)
def test_reward_for_looking(self): # First get to square on square_off = True while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False # print 'move eye, I hope' self.move_eye_to_get_reward() if self.w.sequences.current_task is None: self.w.start_main_loop() # make sure looking at right place # print 'move eye, I hope' # self.move_eye_to_get_reward() # print 'current task', self.w.sequences.current_task no_reward = True now = self.w.sequences.current_task # wait for reward while no_reward: taskMgr.step() if now != self.w.sequences.current_task: now = self.w.sequences.current_task # print 'now', now # if taskTask.now changes to 4, then getting reward if self.w.sequences.current_task == 4: no_reward = False self.assertTrue(self.w.num_reward > 1)
def test_repeats_same_square_if_no_fixation(self): # First get to square on square_off = True # print 'not looking at ', square_pos # make sure looking at right place (not fixation) self.move_eye_to_get_reward('not') while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False if self.w.sequences.current_task is None: self.w.start_main_loop() # find out where the square is... square_pos = self.w.sequences.square.square.getPos() # Now wait for None. This means we are about to turn on the square again after # missed fixation no_change = True while no_change: taskMgr.step() if self.w.sequences.current_task is None: no_change = False new_square_pos = self.w.sequences.square.square.getPos() # print 'should be in same place', new_square_pos self.assertEqual(square_pos, new_square_pos)
def test_square_turns_on_after_move(self): count = 0 square_off = True last = self.w.sequences.current_task not_moved = True # do a full loop where we get reward, double check it moves, and then check to make sure # square turns on again while square_off: taskMgr.step() # print count # need to check for frameTask.now to change to 1 the second time # (first time is just the beginning of the task, before moving) # if taskTask.now changes to 1, then we have just turned on # sometimes, especially with off-screen, the timing isn't accurate, # and we have to calls to the same function right in a row. Make sure # when frameTask.now is one, it is changing from something else. if self.w.sequences.current_task != last: last = self.w.sequences.current_task # print last if last is None: # print 'None, restart' # last will only be None at end self.w.start_main_loop() count = 1 if last == 1 and count == 1: # print 'square should be on for second time' square_off = False if last == 1 and count == 0 and not_moved: self.move_eye_to_get_reward() not_moved = False self.assertTrue(self.w.sequences.square.square.getParent())
def test_repeats_same_square_if_breaks_fixation(self): # First get to square on square_off = True while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False if self.w.sequences.current_task is None: self.w.start_main_loop() # find out where the square is... square_pos = self.w.sequences.square.square.getPos() # print 'about to break, square is ', square_pos # make sure looking at right place (breaks fixation) self.move_eye_to_get_reward('break') # now force self.w.sequences.current_task to change so fixation breaks no_change = True test = 1 while no_change: taskMgr.step() if self.w.sequences.current_task != test: if test == 1: test = self.w.sequences.current_task else: no_change = False # print 'current task', self.w.sequences.current_task # 6 is broken fixation self.assertEqual(self.w.sequences.current_task, 6) new_square_pos = self.w.sequences.square.square.getPos() # print 'should be in same place', new_square_pos self.assertEqual(square_pos, new_square_pos)
def test_no_reward_if_look_but_break_fixation(self): # First get to square on square_off = True while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False # make sure looking at right place self.move_eye_to_get_reward('break') # we will fixate, and then break fixation, so wait for # self.w.sequences.current_task to change twice, then should be # 6, since we broke fixation no_change = True now = 1 while no_change: taskMgr.step() if self.w.sequences.current_task != now: if self.w.sequences.current_task == 5: now = 5 else: no_change = False # next step should not be reward or square dims, should be # square turns on (without moving) self.assertNotEqual(self.w.sequences.current_task, 2) self.assertNotEqual(self.w.sequences.current_task, 3) self.assertEqual(self.w.sequences.current_task, 6)
def testUpdate(self): scene = SunCgSceneLoader.loadHouseFromJson( "0004d52d1aeeb8ae6de39d6bd993e992", TEST_SUNCG_DATA_DIR) agentNp = scene.agents[0] agentNp.setPos(LVecBase3f(45, -42.5, 1.6)) agentNp.setHpr(45, 0, 0) samplingRate = 16000.0 hrtf = CipicHRTF(os.path.join(TEST_DATA_DIR, 'hrtf', 'cipic_hrir.mat'), samplingRate) acoustics = EvertAcoustics(scene, hrtf, samplingRate, maximumOrder=2, maxBufferLength=30.0) # Add ambient sound filename = os.path.join(TEST_DATA_DIR, 'audio', 'radio.ogg') ambientSound = EvertAudioSound(filename) ambientSound.setLoop(True) ambientSound.setLoopCount(0) acoustics.addAmbientSound(ambientSound) ambientSound.play() acoustics.step(0.0) player = AudioPlayer(acoustics) for _ in range(10): taskMgr.step()
def test_timing_fade_on_to_off(self): # First get to fade on square_bright = True square_fade = True a = 0 b = 0 now = 1 while square_bright: taskMgr.step() if self.w.sequences.current_task == now: self.move_eye_to_get_reward() now = 0 a = datetime.datetime.now() # if taskTask.now changes to 2, then we have just changed color if self.w.sequences.current_task == 2: square_bright = False # now wait for fade off: # print 'square should be faded' while square_fade: taskMgr.step() b = datetime.datetime.now() # if taskTask.now changes to 3, then we have just turned off if self.w.sequences.current_task > 2: # print 'square should be off' square_fade = False c = b - a # print 'square should be off' # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure really off, sanity check self.assertFalse(self.w.sequences.square.square.getParent()) # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval self.assertAlmostEqual(c.total_seconds(), self.config['FADE_INTERVAL'][0], 1)
def much_looping(self): print 'start test' self.finish_loop() print 'now step' for i in range(100): print('step', i) print('next', self.w.sequences.current_task) taskMgr.step()
def test_frowney_disappears_when_collided_into(self): """ collide smiley into frowney, and make sure frowney goes away""" self.w.smiley.setPos(5, 25, 0) # Since we never ran run(), the game has not actually started yet, but # run() is just an infinite loop that runs Task.step() repeatedly, so # we can use taskMgr.step() to do this manually. # step through a couple of times to make sure collided taskMgr.step() taskMgr.step() self.assertTrue(self.w.frowney.isStashed())
def __init__(self, name, renderer, size=(8, 4, 8), lb=None): fileManagerOutputLog.debug("Executed command %s" % 'cd "' + directory + '"') system('cd "' + directory + '"') fileManagerOutputLog.debug("Executed command %s" % 'md "' + normpath("data/" + name + '"')) system('md "' + normpath("data/" + name + '"')) self.name = name self.displayname = name self.size = size self.sizex = size[0] self.sizey = size[1] * 2 self.sizez = size[2] self.playerx = self.sizex / 2 self.playery = self.sizey self.playerz = self.sizez / 2 self.worldmap = {} self.newfile = open( directory + normpath("data/" + self.name + ".world"), 'xb') # Create world file - saves everything but chunks. self.newfile.close() self.save() bar = 0 for chunkx in range(0, size[0]): self.worldmap[chunkx] = {} for chunky in range(0, size[1]): self.worldmap[chunkx][chunky] = {} for chunkz in range(0, size[2]): self.worldmap[chunkx][chunky][chunkz] = newchunk( self, chunkx, chunky, chunkz, True, renderer) self.worldmap[chunkx][chunky][chunkz].hidechunk( self, renderer) bar += 1 lb['value'] = 100 / (self.sizex * self.sizey * self.sizez) * bar renderer.mouseWatchTask(renderer.worldin) taskMgr.step() pass pass for chunky in range(size[1], size[1] * 2): self.worldmap[chunkx][chunky] = {} for chunkz in range(0, size[2]): self.worldmap[chunkx][chunky][chunkz] = newchunk( self, chunkx, chunky, chunkz, False, renderer) bar += 1 lb['value'] = 100 / (self.sizex * self.sizey * self.sizez) * bar renderer.mouseWatchTask(renderer.worldin) taskMgr.step() pass pass pass self.save() pass
def test_timing_reward_to_on(self): # First get to reward # print self.w.interval_list no_reward = True square_off = True a = 0 b = 0 self.move_eye_to_get_reward() fade = False while no_reward: taskMgr.step() a = datetime.datetime.now() if self.w.sequences.current_task == 1 and not fade: # if we go on during loop, might not be in correct place self.move_eye_to_get_reward() fade = True # if taskTask.now changes to 4, then we just started reward, # however we have to wait for all of the reward to be given, # but for testing this should be zero, since not using pydaq if self.w.sequences.current_task == 4: # print 'test: reward' no_reward = False # now wait for move/on: # print 'reward' previous = self.w.sequences.current_task while square_off: taskMgr.step() b = datetime.datetime.now() if self.w.sequences.current_task != previous: # print('test:', self.w.sequences.current_task) previous = self.w.sequences.current_task if self.w.sequences.current_task is None: # print 'loop' self.w.start_main_loop() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False c = b - a # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure really on, sanity check self.assertTrue(self.w.sequences.square.square.getParent()) # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval # move interval is from start of reward until move, so includes time it takes # for reward delay = self.config['MOVE_INTERVAL'][0] self.assertAlmostEqual(c.total_seconds(), delay, 1)
def quit(self, renderer): self.save() for chunkx in range(self.playerx / 16 - 5, self.playerx / 16 + 6): for chunky in range(self.playery / 16 - 5, self.playery / 16 + 6): for chunkz in range(self.playerz / 16 - 5, self.playerz / 16 + 6): self.worldmap[str(chunkx)][str(chunky)][str( chunkz)].hidechunk(self, renderer) taskMgr.step() pass pass pass del self pass
def test_square_turns_on(self): """ The square should turn on when next is 1 """ # time_out = time.time() + 2.1 # start_time = # self.w.start_main_loop() square_off = True while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False self.assertTrue(self.w.sequences.square.square.getParent())
def test_timing_for_time_out_if_missed_fixation(self): # if not fixated, will wait for break interval after square turns off # move eye way outside self.move_eye_to_get_reward('not') # need timing from square off to back on, after a missed fixation # wait for square to turn off # if square is currently on, need to wait for it to go off, # come back on, and then go back off again, so we are sure we missed fixation, # since we can't guarantee there wasn't a fixation before we moved the eye # assuming we have done everything correctly in teardown and setup, we should never have # anything except next = 0 to start with # print 'where we are', self.w.sequences.current_task self.assertTrue(self.w.sequences.current_task is None) # print('next', last) square_on = True square_off = True a = 0 b = 0 while square_on: taskMgr.step() a = datetime.datetime.now() if self.w.sequences.current_task > 0: if not self.w.sequences.square.square.getParent(): # square turned off square_on = False # print 'square off, I think' # print self.w.sequences.current_task # now wait for square to turn back on # print 'next loop' while square_off: taskMgr.step() b = datetime.datetime.now() if self.w.sequences.current_task is None: self.w.start_main_loop() if self.w.sequences.square.square.getParent(): # print('square should be back on') square_off = False c = b - a # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval # the break is the move interval + break interval break_time = self.config['BREAK_INTERVAL'][0] + self.config[ 'MOVE_INTERVAL'][0] self.assertAlmostEqual(c.total_seconds(), break_time, 1)
def test_reward_after_square_off(self): print('test_reward_after_square_off') # should get reward automatically if on manual # check to make sure self.w.num_reward increments self.w.key_dict["switch"] = 7 no_reward = True current_reward = self.w.num_reward new_reward = self.w.num_reward print current_reward while no_reward: taskMgr.step() # print self.w.sequences.current_task new_reward = self.w.num_reward if self.w.sequences.current_task == 4: no_reward = False print new_reward self.assertNotEqual(current_reward, new_reward)
def test_timing_for_time_out_if_missed_fixation(self): # if not fixated, will wait for break interval after square turns off # move eye way outside self.move_eye_to_get_reward('not') # need timing from square off to back on, after a missed fixation # wait for square to turn off # if square is currently on, need to wait for it to go off, # come back on, and then go back off again, so we are sure we missed fixation, # since we can't guarantee there wasn't a fixation before we moved the eye # assuming we have done everything correctly in teardown and setup, we should never have # anything except next = 0 to start with # print 'where we are', self.w.sequences.current_task self.assertTrue(self.w.sequences.current_task is None) # print('next', last) square_on = True square_off = True a = 0 b = 0 while square_on: taskMgr.step() a = datetime.datetime.now() if self.w.sequences.current_task > 0: if not self.w.sequences.square.square.getParent(): # square turned off square_on = False # print 'square off, I think' # print self.w.sequences.current_task # now wait for square to turn back on # print 'next loop' while square_off: taskMgr.step() b = datetime.datetime.now() if self.w.sequences.current_task is None: self.w.start_main_loop() if self.w.sequences.square.square.getParent(): # print('square should be back on') square_off = False c = b - a # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval # the break is the move interval + break interval break_time = self.config['BREAK_INTERVAL'][0] + self.config['MOVE_INTERVAL'][0] self.assertAlmostEqual(c.total_seconds(), break_time, 1)
def test_timing_off_to_reward(self): print('test_timing_off_to_reward') # this is problematic, because it is zero in our usual configuration (which is # why we skip right over next = 3. So, I think what makes the most sense is making # sure that square off to move is the same as reward interval + move interval # First get to off square_fade = True square_not_moved = True a = 0 b = 0 while square_fade: # while time.time() < time_out: taskMgr.step() a = datetime.datetime.now() # if taskTask.now changes to 3, then we have just turned off if self.w.sequences.current_task > 2: # print 'square should be off' square_fade = False if self.w.sequences.current_task is None: self.w.start_main_loop() # now wait for move/on: # print 'out of first loop' # make sure switching doesn't screw up timing self.w.key_dict["switch"] = 3 # now wait for reward, when move changes, we are done with reward # and ready for moving while square_not_moved: # while time.time() < time_out: taskMgr.step() b = datetime.datetime.now() # 1 is square just turned on # if self.w.sequences.current_task == 1: # self.w.start_new_loop() if self.w.sequences.current_task == 1: # print 'square should have moved' square_not_moved = False if self.w.sequences.current_task is None: self.w.start_main_loop() c = b - a # print 'c', c.total_seconds() # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval config_time = self.config['REWARD_INTERVAL'][0] + self.config[ 'MOVE_INTERVAL'][0] self.assertAlmostEqual(c.total_seconds(), config_time, 1)
def test_square_moves_after_fixation(self): # get to square on and fixate square_off = True move = False square_pos = 0 # need to show the square, and then get to the move square method while square_off: taskMgr.step() if self.w.sequences.current_task == 1 and not move: # print 'first square on, move eye' # find out where the square is... square_pos = self.w.sequences.square.square.getPos() self.move_eye_to_get_reward() move = True if self.w.sequences.current_task == 1 and move: # print 'and exit' square_off = False self.assertNotEqual(self.w.sequences.square.square.getPos, square_pos)
def test_timing_off_to_reward(self): print('test_timing_off_to_reward') # this is problematic, because it is zero in our usual configuration (which is # why we skip right over next = 3. So, I think what makes the most sense is making # sure that square off to move is the same as reward interval + move interval # First get to off square_fade = True square_not_moved = True a = 0 b = 0 while square_fade: # while time.time() < time_out: taskMgr.step() a = datetime.datetime.now() # if taskTask.now changes to 3, then we have just turned off if self.w.sequences.current_task > 2: # print 'square should be off' square_fade = False if self.w.sequences.current_task is None: self.w.start_main_loop() # now wait for move/on: # print 'out of first loop' # make sure switching doesn't screw up timing self.w.key_dict["switch"] = 3 # now wait for reward, when move changes, we are done with reward # and ready for moving while square_not_moved: # while time.time() < time_out: taskMgr.step() b = datetime.datetime.now() # 1 is square just turned on # if self.w.sequences.current_task == 1: # self.w.start_new_loop() if self.w.sequences.current_task == 1: # print 'square should have moved' square_not_moved = False if self.w.sequences.current_task is None: self.w.start_main_loop() c = b - a # print 'c', c.total_seconds() # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval config_time = self.config['REWARD_INTERVAL'][0] + self.config['MOVE_INTERVAL'][0] self.assertAlmostEqual(c.total_seconds(), config_time, 1)
def test_square_turns_off_after_breaking_fixation(self): # First get to square on square_off = True while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False # make sure looking at right place (breaks fixation) self.move_eye_to_get_reward('break') # Now wait for break fixation, make sure square is turned off no_change = True while no_change: taskMgr.step() if self.w.sequences.current_task == 6: no_change = False self.assertFalse(self.w.sequences.square.square.getParent())
def test_square_fades(self): print 'test_square_fades' # we may change the actual colors, so just make sure the # color before and after the switch are different old_color = self.w.sequences.square.square.getColor() # print 'color', old_color square_on = True old_step = self.w.sequences.current_task print('current step', old_step) while square_on: taskMgr.step() if self.w.sequences.current_task != old_step: old_step = self.w.sequences.current_task print old_step if self.w.sequences.current_task == 2: # print 'square should be dim' square_on = False # print self.w.sequences.square.square.getColor() self.assertNotEqual(self.w.sequences.square.square.getColor(), old_color)
def finish_loop(self): # does a full loop if just ended, finishes the current # loop if you have already started # always ends at cleanup # print 'finish loop' taskMgr.step() if self.w.sequences.current_task is None: # print 'restarted loop' self.w.start_main_loop() now = self.w.sequences.current_task first_loop = True # print 'now before loop', now # check each time we change tasks while first_loop: taskMgr.step() if self.w.sequences.current_task != now: # print('took a step', self.w.sequences.current_task) now = self.w.sequences.current_task if now is None: first_loop = False
def test_square_turns_off_after_missed_fixation(self): # print 'square turns off after missed fixation' # First get to square on square_off = True # make sure looking at right place (not fixation) self.move_eye_to_get_reward('not') while square_off: taskMgr.step() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task == 1: # print 'square should be on' square_off = False # print 'first loop over' # Now wait for 5, bad fixation. We should now have turned off the square, # and next will turn on the square after a missed fixation no_change = True while no_change: taskMgr.step() if self.w.sequences.current_task == 6: no_change = False self.assertFalse(self.w.sequences.square.square.getParent())
def test_timing_stimulus_up_if_not_fixated(self): # if not fixated, will be on for on duration, then reset # First get ready for square on. # make sure looking at right (wrong) place square_off = True square_on = True a = 0 b = 0 # print(self.w.sequences.square.square.getParent()) # print 'start' self.move_eye_to_get_reward('not') while square_off: taskMgr.step() # if square is parented to render, it is on, otherwise has no parent if self.w.sequences.square.square.getParent(): # print 'square should be on' a = datetime.datetime.now() square_off = False # now wait for square to turn back off: # print 'next loop' while square_on: taskMgr.step() b = datetime.datetime.now() if not self.w.sequences.square.square.getParent(): # print 'square should be off' square_on = False c = b - a # this is consistently off by about 0.07s in tests, but not off when actually # running the task and not running 'offscreen'. Must have something to do with # the frame rate Panda3d assumes when running offscreen. This is the only task # where this shows up, and it is the only task where I am actually checking the # rendering (all others I have 'better?' ways of testing. Hmmm. # c = c + datetime.timedelta(seconds=0.05) # print 'c', c.total_seconds() # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval self.assertAlmostEqual(c.total_seconds(), self.config['ON_INTERVAL'][0], 1)
def checkLeak(): import sys import gc gc.enable() from direct.showbase.DirectObject import DirectObject from direct.task.TaskManagerGlobal import taskMgr class TestClass(DirectObject): def doTask(self, task): return task.done obj = TestClass() startRefCount = sys.getrefcount(obj) print('sys.getrefcount(obj): %s' % sys.getrefcount(obj)) print('** addTask') t = obj.addTask(obj.doTask, 'test') print('sys.getrefcount(obj): %s' % sys.getrefcount(obj)) print('task.getRefCount(): %s' % t.getRefCount()) print('** removeTask') obj.removeTask('test') print('sys.getrefcount(obj): %s' % sys.getrefcount(obj)) print('task.getRefCount(): %s' % t.getRefCount()) print('** step') taskMgr.step() taskMgr.step() taskMgr.step() print('sys.getrefcount(obj): %s' % sys.getrefcount(obj)) print('task.getRefCount(): %s' % t.getRefCount()) print('** task release') t = None print('sys.getrefcount(obj): %s' % sys.getrefcount(obj)) assert sys.getrefcount(obj) == startRefCount
def test_timing_off_to_reward(self): # make sure time to reward accurate # this is problematic, because it is zero in our usual configuration (which is # why we skip right over next = 3. So, I think what makes the most sense is making # sure that square off to move is the same as reward interval + move interval self.move_eye_to_get_reward() # First get to on, move eye to get reward, then go to off square_on = True fade = False no_reward = True a = 0 b = 0 while square_on: taskMgr.step() a = datetime.datetime.now() if self.w.sequences.current_task == 1 and not fade: # if we go on during loop, might not be in correct place self.move_eye_to_get_reward() fade = True if not self.w.sequences.square.square.getParent() and fade: # square is off # print 'square should be off' square_on = False # now wait for move/on: # now wait for reward # print 'wait for reward' while no_reward: taskMgr.step() b = datetime.datetime.now() # if taskTask.now changes to 4, then we have reward if self.w.sequences.current_task == 4: # print 'reward' no_reward = False c = b - a # print 'c', c.total_seconds() # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval config_time = self.config['REWARD_INTERVAL'][0] self.assertAlmostEqual(c.total_seconds(), config_time, 1)
def test_timing_reward_to_on(self): # moved when next is 4, moving happens (almost) simultaneous with on, interval is just # from reward to on, so the moving interval print 'test_timing_reward_to_on' # and move self.w.key_dict["switch"] = 8 not_rewarded = True square_off = True a = 0 b = 0 while not_rewarded: taskMgr.step() a = datetime.datetime.now() if self.w.sequences.current_task == 4: print('reward, next is', self.w.sequences.current_task) not_rewarded = False # print 'next loop' while square_off: taskMgr.step() b = datetime.datetime.now() # if taskTask.now changes to 1, then we have just turned on if self.w.sequences.current_task is None: self.w.start_main_loop() if self.w.sequences.current_task == 1: print('square should be on, next is', self.w.sequences.current_task) square_off = False c = b - a # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure really on, sanity check self.assertTrue(self.w.sequences.square.square.getParent()) # make sure timing within 1 place, won't be very accurate. # but close enough to have correct interval # move interval is time from start of reward to move delay = self.config['MOVE_INTERVAL'][0] self.assertAlmostEqual(c.total_seconds(), delay, 1)
def test_square_turns_off(self): """ Square should go off at current_task is 3. At that point, make sure square has no parent, so not rendered, if task higher than 2. For random, if there is no fixation, never makes it to 2, so make sure off when None (wait period before start of trial) """ # self.w.start_main_loop() now = self.w.sequences.current_task if self.w.sequences.current_task != 0: square_on = True while square_on: taskMgr.step() if self.w.sequences.current_task != now: print 'currently', self.w.sequences.current_task now = self.w.sequences.current_task if self.w.sequences.current_task is None or self.w.sequences.current_task > 2: square_on = False # if self.w.sequences.current_task == 3 or self.w.sequences.current_task == 0: print 'check if on' self.assertFalse(self.w.sequences.square.square.getParent()) # finish the loop self.finish_loop()
def test_timing_on_to_fade_after_manual_move(self): print('test_timing_on_to_fade_after_manual_move') # We turn on at the same time we move, so check the # interval between turning on and fading, which will # be when self.w.sequences.current_task switches to 2. self.finish_loop() self.w.start_main_loop() # and move self.w.key_dict["switch"] = 3 # print 'check time' b = 0 a = 0 # we have set move, # we wait until it comes back on square_off = True while square_off: taskMgr.step() a = datetime.datetime.now() if self.w.sequences.current_task == 1: # okay, should be on now square_off = False # need to stop when square fades square_on = True while square_on: taskMgr.step() b = datetime.datetime.now() if self.w.sequences.current_task == 2: square_on = False c = b - a # print 'c', c.total_seconds() # check that time is close # print 'c should be', self.config['MOVE_INTERVAL'][0] # make sure really on, sanity check self.assertTrue(self.w.sequences.square.square.getParent()) # make sure timing within 2 places self.assertAlmostEqual(c.total_seconds(), self.config['ON_INTERVAL'][0], 1)
for o in __builtin__.dispose_list:o.dispose() __builtin__.dispose_list=[] def update(self, task): ''' main update method. runs the whole time. other updates can register to update_list to get called every frame. ''' [f() for f in update_list] return task.again gc = GameClient() gc.request('Init') while gc.is_running: taskMgr.step() ''' #better loop logic #fps=ConfigVariableDouble('fps') #skip_frames=ConfigVariableDouble('skip_frames') #max_frames_skip=ConfigVariableDouble('max_frames_skip') #next_display=time.clock() #while running: #loops=0 #while time.clock()>next_display and loops<max_frames_skip: #update game #taskMgr.step() #next_display+=skip_frames #loops+=1