def test_extra_imports(): # only Jon needs to run this, so test first if you are him! import os if sys.platform=='win32': import win32api user=win32api.GetUserName() else: import pwd user = pwd.getpwuid(os.getuid()).pw_name if user not in ['jwp','lpzjwp']: utils.skip('Testing extra imports is only needed for building Standalone distributions') #OK, it's Jon , so run it import serial import pp import egi try: import labjack except: import u3, u6, ue9, LabJackPython import ioLabs import hid import pyo #avbin import pyglet assert pyglet.media.have_avbin #platform specific if sys.platform=='win32': import parallel import pylink
def test_refresh_rate(self): if self.win.winType=='pygame': utils.skip("getMsPerFrame seems to crash the testing of pygame") #make sure that we're successfully syncing to the frame rate msPFavg, msPFstd, msPFmed = visual.getMsPerFrame(self.win,nFrames=60, showVisual=True) assert (1000/150.0 < msPFavg < 1000/40.0), \ "Your frame period is %.1fms which suggests you aren't syncing to the frame" %msPFavg
def test_Exp_LoadCompilePsyexp(self): #""" for each builder demo .psyexp: load-save-load, compile (syntax check), namespace""" exp = self.exp self.new_diff_file = self.tmp_diffs_file # make temp copies of all builder demos: for root, dirs, files in os.walk(path.join(exp.prefsPaths['demos'], 'builder')): for f in files: if (f.endswith('.psyexp') or f.endswith('.xlsx') or f.endswith('.csv') )\ and not f.startswith('bart'): shutil.copyfile(path.join(root, f), path.join(self.tmp_dir, f)) # also copy any psyexp in 'here' (testExperiment dir) #for f in glob.glob(path.join(self.here, '*.psyexp')): # shutil.copyfile(f, path.join(self.tmp_dir, path.basename(f))) test_psyexp = list(glob.glob(path.join(self.tmp_dir, '*.psyexp'))) if len(test_psyexp) == 0: utils.skip("No test .psyexp files found (no Builder demos??)") diff_in_file_py = '' # will later assert that this is empty #diff_in_file_psyexp = '' #diff_in_file_pyc = '' #savedLocale = '.'.join(locale.getlocale()) locale.setlocale(locale.LC_ALL, '') # default for file in test_psyexp: # test for any diffs using various locale's: for loc in ['en_US', 'en_US.UTF-8', 'ru_RU', 'ja_JP']: try: locale.setlocale(locale.LC_ALL, loc) except locale.Error: continue #skip this locale; it isnt installed file_py, file_psyexp = self._checkLoadSave(file) file_pyc = self._checkCompile(file_py) #sha1_first = sha1hex(file_pyc, file=True) file2_py, file2_psyexp = self._checkLoadSave(file_psyexp) file2_pyc = self._checkCompile(file2_py) #sha1_second = sha1hex(file2_pyc, file=True) # check first against second, filtering out uninteresting diffs; catch diff in any of multiple psyexp files diff_in_file_py += self._checkPyDiff(file_py, file2_py) #diff_psyexp = _diff_file(file_psyexp,file2_psyexp)[2:] #diff_in_file_psyexp += diff_psyexp #diff_pyc = (sha1_first != sha1_second) #assert not diff_pyc if self.exp.prefsApp['locale']: locale.setlocale(locale.LC_ALL, self.exp.prefsApp['locale']) assert not diff_in_file_py ### see known_py_diffs.txt; potentially a locale issue? ###
def test_aperture(self): win = self.win if not win.allowStencil: utils.skip("Don't run aperture test when no stencil is available") contextName=self.contextName grating = visual.PatchStim(win, mask='gauss',sf=8.0, size=2,color='FireBrick', units='norm') aperture = visual.Aperture(win, size=1*self.scaleFactor,pos=[0.8*self.scaleFactor,0]) aperture.disable() grating.draw() aperture.enable() grating.setOri(90) grating.setColor('black') grating.draw() utils.compareScreenshot('aperture1_%s.png' %(contextName), win)
def test_quicktime(): if sys.platform!='darwin': utils.skip("Only OS X can make Quicktime movies") import numpy, time, os mov_name = "qtTest.mov" t0=time.time() m = makeMovies.QuicktimeMovie(mov_name) for frameN in range(10): arr=(numpy.random.random([640,480,3])*255).astype(numpy.uint8) m.addFrame(arr, 1) print '.',;os.sys.stdout.flush() m.save() print 'took %.2fs' %(time.time()-t0) os.unlink(mov_name)
def test_mov(self): win = self.win if self.win.winType=='pygame': utils.skip("movies only available for pyglet backend") win.flip() contextName=self.contextName #construct full path to the movie file fileName = os.path.join(utils.TESTS_DATA_PATH, 'testMovie.mp4') #check if present if not os.path.isfile(fileName): raise IOError('Could not find movie file: %s' % os.path.abspath(fileName)) #then do actual drawing mov = visual.MovieStim(win, fileName) for frameN in range(10): mov.draw() win.flip()
def test_element_array(self): win = self.win contextName=self.contextName if not win._haveShaders: utils.skip("ElementArray requires shaders, which aren't available") #using init thetas = numpy.arange(0,360,10) N=len(thetas) radii = numpy.linspace(0,1.0,N)*self.scaleFactor x, y = misc.pol2cart(theta=thetas, radius=radii) xys = numpy.array([x,y]).transpose() spiral = visual.ElementArrayStim(win, nElements=N,sizes=0.5*self.scaleFactor, sfs=3.0, xys=xys, oris=thetas) spiral.draw() win.flip() spiral.draw() utils.compareScreenshot('elarray1_%s.png' %(contextName), win) win.flip()
def test_Run_FastStroopPsyExp(self): # start from a psyexp file, loadXML, execute, get keypresses from a emulator thread utils.skip() # test is stalling, hangs up before any text is displayed if sys.platform.startswith('linux'): utils.skip("response emulation thread not working on linux yet") os.chdir(self.tmp_dir) file = path.join(exp.prefsPaths['tests'], 'data', 'ghost_stroop.psyexp') f = codecs.open(file, 'r', 'utf-8') text = f.read() f.close() # copy conditions file to tmp_dir shutil.copyfile(os.path.join(self.exp.prefsPaths['tests'], 'data', 'ghost_trialTypes.xlsx'), os.path.join(self.tmp_dir,'ghost_trialTypes.xlsx')) # edit the file, to have a consistent font: text = text.replace("'Arial'","'"+utils.TESTS_FONT+"'") #text = text.replace("Arial",utils.TESTS_FONT) # fails file = path.join(self.tmp_dir, 'ghost_stroop.psyexp') f = codecs.open(file, 'w', 'utf-8') f.write(text) f.close() exp.loadFromXML(file) # reload the edited file lastrun = path.join(self.tmp_dir, 'ghost_stroop_lastrun.py') script = exp.writeScript(expPath=file) # reposition its window out from under splashscreen (can't do easily from .psyexp): text = script.getvalue().replace('fullscr=False,','pos=(40,40), fullscr=False,') f = codecs.open(lastrun, 'w', 'utf-8') f.write(text) f.close() # run: stdout, stderr = shellCall('python '+lastrun, stderr=True) assert not len(stderr), stderr # print stderr if it's greater than zero
def _inner(): utils.skip("Can't test without Mock")