|
|
|
|
|
|
import yaml |
|
|
|
import mock |
|
|
|
import unittest.mock as mock |
|
|
|
import pytest |
|
|
|
|
|
|
|
from unitytrainers.trainer_controller import TrainerController |
|
|
|
|
|
|
mock_socket.return_value.accept.return_value = (mock_socket, 0) |
|
|
|
mock_socket.recv.return_value.decode.return_value = dummy_start |
|
|
|
tc = TrainerController(' ', ' ', 1, None, True, True, False, 1, |
|
|
|
1, 1, 1) |
|
|
|
1, 1, 1, '', "tests/test_unitytrainers.py") |
|
|
|
open_name = '%s.open' % __name__ |
|
|
|
open_name = 'unitytrainers.trainer_controller' + '.open' |
|
|
|
with mock.patch(open_name, create=True) as mock_open: |
|
|
|
mock_open.return_value = 0 |
|
|
|
mock_load.return_value = dummy_config |
|
|
|
config = TrainerController._load_config("tests/test_unitytrainers.py") |
|
|
|
assert(len(config) == 1) |
|
|
|
assert(config['default']['trainer'] == "ppo") |
|
|
|
with mock.patch(open_name, create=True) as _: |
|
|
|
with mock.patch('subprocess.Popen'): |
|
|
|
with mock.patch('socket.socket') as mock_socket: |
|
|
|
with mock.patch('glob.glob') as mock_glob: |
|
|
|
mock_load.return_value = dummy_config |
|
|
|
mock_glob.return_value = ['FakeLaunchPath'] |
|
|
|
mock_socket.return_value.accept.return_value = (mock_socket, 0) |
|
|
|
mock_socket.recv.return_value.decode.return_value = dummy_start |
|
|
|
mock_load.return_value = dummy_config |
|
|
|
tc = TrainerController(' ', ' ', 1, None, True, True, False, 1, |
|
|
|
1, 1, 1, '','') |
|
|
|
config = tc._load_config() |
|
|
|
assert(len(config) == 1) |
|
|
|
assert(config['default']['trainer'] == "ppo") |
|
|
|
open_name = '%s.open' % __name__ |
|
|
|
open_name = 'unitytrainers.trainer_controller' + '.open' |
|
|
|
with mock.patch(open_name, create=True) as mock_open: |
|
|
|
mock_open.return_value = 0 |
|
|
|
with mock.patch(open_name, create=True) as _: |
|
|
|
with mock.patch('subprocess.Popen'): |
|
|
|
with mock.patch('socket.socket') as mock_socket: |
|
|
|
with mock.patch('glob.glob') as mock_glob: |
|
|
|
|
|
|
tc = TrainerController(' ', ' ', 1, None, True, True, False, 1, |
|
|
|
1, 1, 1) |
|
|
|
1, 1, 1, '', "tests/test_unitytrainers.py") |
|
|
|
config = tc._load_config("tests/test_unitytrainers.py") |
|
|
|
config = tc._load_config() |
|
|
|
tf.reset_default_graph() |
|
|
|
with tf.Session() as sess: |
|
|
|
tc._initialize_trainers(config, sess) |
|
|
|
|
|
|
# Test for Behavior Cloning Trainer |
|
|
|
mock_load.return_value = dummy_bc_config |
|
|
|
config = tc._load_config("tests/test_unitytrainers.py") |
|
|
|
config = tc._load_config() |
|
|
|
tf.reset_default_graph() |
|
|
|
with tf.Session() as sess: |
|
|
|
tc._initialize_trainers(config, sess) |
|
|
|
|
|
|
mock_load.return_value = dummy_bad_config |
|
|
|
config = tc._load_config("tests/test_unitytrainers.py") |
|
|
|
config = tc._load_config() |
|
|
|
tf.reset_default_graph() |
|
|
|
with tf.Session() as sess: |
|
|
|
with pytest.raises(UnityEnvironmentException): |
|
|
|