Skip to content

Commit

Permalink
Added tests for training
Browse files Browse the repository at this point in the history
  • Loading branch information
henneysq committed Mar 13, 2024
1 parent 2dcef6a commit e19f2c2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_experiment_va.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,32 @@ def test_8_check_unique_triggers(self):
# return

# self.assertTrue(experiment_manager.end_of_experiment_flag)

def test_10_ten_trials(self):
experiment_manager = VisualAttentionExperimentManager(
sub=SUB, ses=SES, run=RUN, root=ROOT
)
experiment_manager.show_start_screen = MagicMock()
experiment_manager.show_pause_screen = MagicMock()

experiment_manager = check_is_trigger_connected(experiment_manager)
experiment_manager = check_is_lc_connected(experiment_manager)

experiment_manager.load_experiment_data()
experiment_manager.prepare_psychopy()

for _ in range(10):
current_trial = experiment_manager.get_current_trial_data()
attention_side = current_trial.task
stimulus = current_trial.stimulus_condition
task_congruence = current_trial.task_congruence

try:
_, _ = experiment_manager.execute_current_trial(
grating_side=attention_side,
grating_congruence=task_congruence,
stimulus=stimulus,
)
experiment_manager.increment_trial_progress()
except SystemExit:
break
40 changes: 40 additions & 0 deletions tests/test_experiment_wm.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,43 @@ def test_8_check_unique_triggers(self):

# self.assertTrue(experiment_manager.end_of_experiment_flag)


def test_10_ten_trials(self):
experiment_manager = WorkingMemoryExperimentManager(
sub=SUB, ses=SES, run=RUN, root=ROOT
)

experiment_manager.show_start_screen = MagicMock()
experiment_manager.show_pause_screen = MagicMock()

experiment_manager = check_is_trigger_connected(experiment_manager)
experiment_manager = check_is_lc_connected(experiment_manager)

experiment_manager.load_experiment_data()
experiment_manager.prepare_psychopy()

try:
experiment_manager.trigger.prepare_trigger()
import time; time.sleep(3)
experiment_manager.trigger.ser.reset_input_buffer()
except Exception as e:
logging.info("Caught exception while connecting serial port:\n" + str(e))
experiment_manager.trigger.ser = MagicMock()
experiment_manager.trigger.ser.write = MagicMock()
experiment_manager.trigger.ser.read = MagicMock(return_value=bytearray([0]))
experiment_manager.trigger.trigger_ready = True

for _ in range(3):
current_trial = experiment_manager.get_current_trial_data()
stimulus = current_trial.stimulus_condition
task_difficulty = current_trial.task_difficulty
presented_sum_correctness = current_trial.presented_sum_correctness
try:
_ = experiment_manager.execute_current_trial(
presented_sum_correctness=presented_sum_correctness,
stimulus=stimulus,
task_difficulty=task_difficulty
)
experiment_manager.increment_trial_progress()
except SystemExit:
break

0 comments on commit e19f2c2

Please sign in to comment.