def runLocal(self, evt): """Run experiment from new process using inherited ScriptProcess class methods.""" if self.currentSelection is None: return currentFile = str(self.currentFile) if self.currentFile.suffix == '.psyexp': generateScript(experimentPath=currentFile.replace('.psyexp', '_lastrun.py'), exp=self.loadExperiment()) self.runFile(fileName=currentFile) # Enable/Disable btns self.runBtn.Disable() self.stopBtn.Enable()
def test_writing(self): # Create simple experiment with a Polygon exp = experiment.Experiment() rt = experiment.routines.Routine(name="testRoutine", exp=exp) exp.addRoutine("testRoutine", rt) exp.flow.addRoutine(rt, 0) comp = polygon.PolygonComponent(exp=exp, parentName="testRoutine") rt.addComponent(comp) # Set use version exp.settings.params['Use version'].val = "2021.1.4" # Save experiment exp.saveToXML(str(self.temp / "versionText.psyexp")) # --- Python --- # Write script scriptFile = str(self.temp / "versionText.py") generateScript( experimentPath=scriptFile, exp=exp, target="PsychoPy" ) # Read script with open(scriptFile, "r") as f: script = f.read() # Get args passed to comp args = script.split(f"{comp.name} = visual.ShapeStim(")[1] args = args.split(")")[0] # If using 2021.1.4, there shouldn't be any "anchor" arg in ShapeStim, as it wasn't implemented yet assert "anchor" not in args, ( "When compiling Py with useversion 2021.1.4, found 'anchor' argument in ShapeStim; this was not " "implemented in requested version." ) # --- JS --- # Write script scriptFile = str(self.temp / "versionText.js") generateScript( experimentPath=scriptFile, exp=exp, target="PsychoJS" ) # Read script with open(scriptFile, "r") as f: script = f.read() # Check for correct version import statement assert "import { PsychoJS } from './lib/core-2021.1.4.js'" in script, ( "When compiling JS with useversion 2021.1.4, could not find version-specific import statement." )