浏览代码

[FixingPytests] Added the new Semantic and modified the pytest

/develop-generalizationTraining-TrainerController
vincentpierre 7 年前
当前提交
6c55017e
共有 5 个文件被更改,包括 32 次插入23 次删除
  1. 1
      python/requirements.txt
  2. 2
      python/tests/test_bc.py
  3. 2
      python/tests/test_ppo.py
  4. 11
      python/tests/test_unityagents.py
  5. 39
      python/tests/test_unitytrainers.py

1
python/requirements.txt


matplotlib
numpy>=1.11.0
jupyter
mock>=2.0.0
pytest>=3.2.2
docopt
pyyaml

2
python/tests/test_bc.py


import mock
import unittest.mock as mock
import pytest
import numpy as np

2
python/tests/test_ppo.py


import mock
import unittest.mock as mock
import pytest
import numpy as np

11
python/tests/test_unityagents.py


import json
import mock
import unittest.mock as mock
import pytest
import struct

"agents": [1,2],
"vectorObservations": [1,2,3,4,5,6,1,2,3,4,5,6],
"rewards": [1,2],
"vectorActions": [1,2,3,4],
"previousVectorActions": [1,2,3,4],
"previousTextActions":["",""],
"memories": [],
"dones": [false, false],
"maxes": [false, false],

"agents": [1,2,3],
"vectorObservations": [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9],
"rewards": [1,2,3],
"vectorActions": [1,2,3,4,5,6],
"previousVectorActions": [1,2,3,4,5,6],
"previousTextActions":["","",""],
"memories": [],
"dones": [false, false, false],
"maxes": [false, false, false],

"agents": [1,2,3],
"vectorObservations": [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9],
"rewards": [1,2,3],
"vectorActions": [1,2,3,4,5,6],
"previousVectorActions": [1,2,3,4,5,6],
"previousTextActions":["","",""],
"memories": [],
"dones": [false, false, true],
"maxes": [false, false, false],

39
python/tests/test_unitytrainers.py


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):

正在加载...
取消
保存