浏览代码

added a test

/MLA-1734-demo-provider
vincentpierre 4 年前
当前提交
ff826bd2
共有 1 个文件被更改,包括 24 次插入0 次删除
  1. 24
      ml-agents/mlagents/trainers/tests/test_subprocess_env_manager.py

24
ml-agents/mlagents/trainers/tests/test_subprocess_env_manager.py


@mock.patch(
"mlagents.trainers.subprocess_env_manager.SubprocessEnvManager.create_worker"
)
def test_training_behaviors_collects_results_from_all_envs(self, mock_create_worker):
def create_worker_mock(worker_id, step_queue, env_factor, engine_c):
return MockEnvWorker(
worker_id, EnvironmentResponse(EnvironmentCommand.RESET, worker_id, {f"key{worker_id}" : worker_id})
)
mock_create_worker.side_effect = create_worker_mock
manager = SubprocessEnvManager(
mock_env_factory, EngineConfig.default_config(), 4
)
params = {"test": "params"}
res = manager.training_behaviors
for i, env in enumerate(manager.env_workers):
env.send.assert_called_with(EnvironmentCommand.BEHAVIOR_SPECS)
env.recv.assert_called()
for worker_id in range(4):
assert f"key{worker_id}" in res
assert res[f"key{worker_id}"] == worker_id
@mock.patch(
"mlagents.trainers.subprocess_env_manager.SubprocessEnvManager.create_worker"
)
def test_step_takes_steps_for_all_non_waiting_envs(self, mock_create_worker):
mock_create_worker.side_effect = create_worker_mock
manager = SubprocessEnvManager(

正在加载...
取消
保存