def test_button_presses_and_window_size(): """Test EC window_size=None and button press capture """ warnings.simplefilter('ignore') # esc as quit key with ExperimentController(*std_args, audio_controller='pyglet', response_device='keyboard', window_size=None, output_dir=None, full_screen=False, participant='foo', session='01', force_quit='escape', version='dev') as ec: warnings.simplefilter('always') fake_button_press(ec, '1', 0.3) assert_equal( ec.screen_prompt('press 1', live_keys=['1'], max_wait=1.5), '1') ec.screen_text('press 1 again') ec.flip() fake_button_press(ec, '1', 0.3) assert_equal(ec.wait_one_press(1.5, live_keys=[1])[0], '1') ec.screen_text('press 1 one last time') ec.flip() fake_button_press(ec, '1', 0.3) out = ec.wait_for_presses(1.5, live_keys=['1'], timestamp=False) assert_equal(out[0], '1')
def test_button_presses_and_window_size(): """Test EC window_size=None and button press capture """ with ExperimentController(*std_args, audio_controller='pyglet', response_device='keyboard', window_size=None, output_dir=temp_dir, full_screen=False, participant='foo', session='01') as ec: fake_button_press(ec, '1', 0.3) assert_equal(ec.screen_prompt('press 1', live_keys=['1'], max_wait=1.5), '1') ec.screen_text('press 1 again') ec.flip() fake_button_press(ec, '1', 0.3) assert_equal(ec.wait_one_press(1.5, live_keys=[1])[0], '1') ec.screen_text('press 1 one last time') ec.flip() fake_button_press(ec, '1', 0.3) out = ec.wait_for_presses(1.5, live_keys=['1'], timestamp=False) assert_equal(out[0], '1')
def test_button_presses_and_window_size(): """Test EC window_size=None and button press capture """ warnings.simplefilter('ignore') # esc as quit key with ExperimentController(*std_args, audio_controller='pyglet', response_device='keyboard', window_size=None, output_dir=None, full_screen=False, participant='foo', session='01', force_quit='escape', version='dev') as ec: warnings.simplefilter('always') fake_button_press(ec, '1', 0.3) assert_equal(ec.screen_prompt('press 1', live_keys=['1'], max_wait=1.5), ('1', 'press')) ec.screen_text('press 1 again') ec.flip() fake_button_press(ec, '1', 0.3) assert_equal(ec.wait_one_press(1.5, live_keys=[1])[0], '1') ec.screen_text('press 1 one last time') ec.flip() fake_button_press(ec, '1', 0.3) out = ec.wait_for_presses(1.5, live_keys=['1'], timestamp=False) assert_equal(out[0], ('1', 'press'))
def test_button_presses_and_window_size(hide_window): """Test EC window_size=None and button press capture.""" with ExperimentController(*std_args, audio_controller='sound_card', response_device='keyboard', window_size=None, output_dir=None, full_screen=False, session='01', participant='foo', trigger_controller='dummy', force_quit='escape', version='dev') as ec: ec.listen_presses() ec.get_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1', 0.5) assert_equal( ec.screen_prompt('press 1', live_keys=['1'], max_wait=1.5), '1') ec.listen_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1') assert_equal(ec.get_presses(timestamp=False), [('1', )]) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.2) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 2) assert_equal(presses[0][0], '1') assert (isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.1, return_kinds=True) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 3) assert_equal(presses[0][::2], ('1', 'press')) assert (isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=False, return_kinds=True) assert_equal(presses, [('1', 'press')]) ec.listen_presses() ec.screen_text('press 1 again') ec.flip() fake_button_press(ec, '1', 0.3) assert_equal(ec.wait_one_press(1.5, live_keys=[1])[0], '1') ec.screen_text('press 1 one last time') ec.flip() fake_button_press(ec, '1', 0.3) out = ec.wait_for_presses(1.5, live_keys=['1'], timestamp=False) assert_equal(out[0], '1') fake_button_press(ec, 'a', 0.3) fake_button_press(ec, 'return', 0.5) assert ec.text_input() == 'A' fake_button_press(ec, 'a', 0.3) fake_button_press(ec, 'space', 0.35) fake_button_press(ec, 'backspace', 0.4) fake_button_press(ec, 'comma', 0.45) fake_button_press(ec, 'return', 0.5) # XXX this fails on OSX travis for some reason new_pyglet = _new_pyglet() bad = sys.platform == 'darwin' bad |= sys.platform == 'win32' and new_pyglet if not bad: assert ec.text_input(all_caps=False).strip() == 'a'
def test_button_presses_and_window_size(): """Test EC window_size=None and button press capture.""" with ExperimentController(*std_args, audio_controller='pyglet', response_device='keyboard', window_size=None, output_dir=None, full_screen=False, session='01', participant='foo', trigger_controller='dummy', force_quit='escape', version='dev') as ec: ec.listen_presses() ec.get_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1', 0.5) assert_equal( ec.screen_prompt('press 1', live_keys=['1'], max_wait=1.5), '1') ec.listen_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1') assert_equal(ec.get_presses(timestamp=False), [('1', )]) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.2) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 2) assert_equal(presses[0][0], '1') assert_true(isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.1, return_kinds=True) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 3) assert_equal(presses[0][::2], ('1', 'press')) assert_true(isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=False, return_kinds=True) assert_equal(presses, [('1', 'press')]) ec.listen_presses() ec.screen_text('press 1 again') ec.flip() fake_button_press(ec, '1', 0.3) assert_equal(ec.wait_one_press(1.5, live_keys=[1])[0], '1') ec.screen_text('press 1 one last time') ec.flip() fake_button_press(ec, '1', 0.3) out = ec.wait_for_presses(1.5, live_keys=['1'], timestamp=False) assert_equal(out[0], '1')
def test_button_presses_and_window_size(hide_window): """Test EC window_size=None and button press capture.""" with ExperimentController(*std_args, audio_controller='sound_card', response_device='keyboard', window_size=None, output_dir=None, full_screen=False, session='01', participant='foo', trigger_controller='dummy', force_quit='escape', version='dev') as ec: ec.listen_presses() ec.get_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1', 0.5) assert_equal(ec.screen_prompt('press 1', live_keys=['1'], max_wait=1.5), '1') ec.listen_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1') assert_equal(ec.get_presses(timestamp=False), [('1',)]) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.2) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 2) assert_equal(presses[0][0], '1') assert (isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.1, return_kinds=True) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 3) assert_equal(presses[0][::2], ('1', 'press')) assert (isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=False, return_kinds=True) assert_equal(presses, [('1', 'press')]) ec.listen_presses() ec.screen_text('press 1 again') ec.flip() fake_button_press(ec, '1', 0.3) assert_equal(ec.wait_one_press(1.5, live_keys=[1])[0], '1') ec.screen_text('press 1 one last time') ec.flip() fake_button_press(ec, '1', 0.3) out = ec.wait_for_presses(1.5, live_keys=['1'], timestamp=False) assert_equal(out[0], '1') fake_button_press(ec, 'a', 0.3) fake_button_press(ec, 'return', 0.5) assert ec.text_input() == 'A' fake_button_press(ec, 'a', 0.3) fake_button_press(ec, 'space', 0.35) fake_button_press(ec, 'backspace', 0.4) fake_button_press(ec, 'comma', 0.45) fake_button_press(ec, 'return', 0.5) # XXX this fails on OSX travis for some reason if (os.getenv('TRAVIS', '').lower() != 'true' or sys.platform != 'darwin'): assert ec.text_input(all_caps=False) == 'a'
def test_button_presses_and_window_size(): """Test EC window_size=None and button press capture.""" warnings.simplefilter('ignore') # esc as quit key with ExperimentController(*std_args, audio_controller='pyglet', response_device='keyboard', window_size=None, output_dir=None, full_screen=False, session='01', participant='foo', trigger_controller='dummy', force_quit='escape', version='dev') as ec: warnings.simplefilter('always') ec.listen_presses() ec.get_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1', 0.5) assert_equal(ec.screen_prompt('press 1', live_keys=['1'], max_wait=1.5), '1') ec.listen_presses() assert_equal(ec.get_presses(), []) fake_button_press(ec, '1') assert_equal(ec.get_presses(timestamp=False), [('1',)]) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.2) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 2) assert_equal(presses[0][0], '1') assert_true(isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=True, relative_to=0.1, return_kinds=True) assert_equal(len(presses), 1) assert_equal(len(presses[0]), 3) assert_equal(presses[0][::2], ('1', 'press')) assert_true(isinstance(presses[0][1], float)) ec.listen_presses() fake_button_press(ec, '1') presses = ec.get_presses(timestamp=False, return_kinds=True) assert_equal(presses, [('1', 'press')]) ec.listen_presses() ec.screen_text('press 1 again') ec.flip() fake_button_press(ec, '1', 0.3) assert_equal(ec.wait_one_press(1.5, live_keys=[1])[0], '1') ec.screen_text('press 1 one last time') ec.flip() fake_button_press(ec, '1', 0.3) out = ec.wait_for_presses(1.5, live_keys=['1'], timestamp=False) assert_equal(out[0], '1')