|
|
|
|
|
|
|
|
|
|
def test_take_step_adds_experiences_to_trainer_and_trains(): |
|
|
|
tc, trainer_mock = trainer_controller_with_take_step_mocks() |
|
|
|
|
|
|
|
old_step_info = EnvironmentStep(Mock(), Mock(), action_info_dict) |
|
|
|
new_step_info = EnvironmentStep(Mock(), Mock(), action_info_dict) |
|
|
|
brain_info_dict = {"testbrain": Mock()} |
|
|
|
old_step_info = EnvironmentStep(brain_info_dict, brain_info_dict, action_info_dict) |
|
|
|
new_step_info = EnvironmentStep(brain_info_dict, brain_info_dict, action_info_dict) |
|
|
|
trainer_mock.is_ready_update = MagicMock(return_value=True) |
|
|
|
|
|
|
|
env_mock = MagicMock() |
|
|
|
|
|
|
env_mock.reset.assert_not_called() |
|
|
|
env_mock.step.assert_called_once() |
|
|
|
trainer_mock.add_experiences.assert_called_once_with( |
|
|
|
new_step_info.previous_all_brain_info, |
|
|
|
new_step_info.current_all_brain_info, |
|
|
|
new_step_info.previous_all_brain_info["testbrain"], |
|
|
|
new_step_info.current_all_brain_info["testbrain"], |
|
|
|
new_step_info.previous_all_brain_info, new_step_info.current_all_brain_info |
|
|
|
new_step_info.previous_all_brain_info["testbrain"], |
|
|
|
new_step_info.current_all_brain_info["testbrain"], |
|
|
|
) |
|
|
|
trainer_mock.update_policy.assert_called_once() |
|
|
|
trainer_mock.increment_step.assert_called_once() |
|
|
|
|
|
|
|
|
|
|
action_info_dict = {"testbrain": MagicMock()} |
|
|
|
|
|
|
|
old_step_info = EnvironmentStep(Mock(), Mock(), action_info_dict) |
|
|
|
new_step_info = EnvironmentStep(Mock(), Mock(), action_info_dict) |
|
|
|
brain_info_dict = {"testbrain": Mock()} |
|
|
|
old_step_info = EnvironmentStep(brain_info_dict, brain_info_dict, action_info_dict) |
|
|
|
new_step_info = EnvironmentStep(brain_info_dict, brain_info_dict, action_info_dict) |
|
|
|
|
|
|
|
trainer_mock.is_ready_update = MagicMock(return_value=False) |
|
|
|
|
|
|
|
env_mock = MagicMock() |
|
|
|
|
|
|
env_mock.reset.assert_not_called() |
|
|
|
env_mock.step.assert_called_once() |
|
|
|
trainer_mock.add_experiences.assert_called_once_with( |
|
|
|
new_step_info.previous_all_brain_info, |
|
|
|
new_step_info.current_all_brain_info, |
|
|
|
new_step_info.previous_all_brain_info["testbrain"], |
|
|
|
new_step_info.current_all_brain_info["testbrain"], |
|
|
|
new_step_info.previous_all_brain_info, new_step_info.current_all_brain_info |
|
|
|
new_step_info.previous_all_brain_info["testbrain"], |
|
|
|
new_step_info.current_all_brain_info["testbrain"], |
|
|
|
) |
|
|
|
trainer_mock.clear_update_buffer.assert_called_once() |