-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtest_env.py
66 lines (49 loc) · 1.3 KB
/
test_env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import io
import sys
import unittest
from adept.environments._env import EnvBase
class StubEnv(EnvBase):
def __init__(self, defaults):
self._defaults = defaults
@property
def defaults(self):
return self._defaults
def step(self, action):
pass
def reset(self, **kwargs):
pass
def close(self):
pass
@property
def observation_space(self):
return None
@property
def action_space(self):
return None
@property
def cpu_preprocessor(self):
return None
@property
def gpu_preprocessor(self):
return None
class EnvBase(unittest.TestCase):
defaults = {
'k1': 0,
'k2': False,
'k3': 1.5,
'k4': 'hello'
}
stub = StubEnv(defaults)
def test_prompt_no_changes(self):
sys.stdin = io.StringIO('\n')
new_conf = self.stub.prompt()
assert(new_conf == self.defaults)
def test_prompt_modify(self):
sys.stdin = io.StringIO('{"k1": 5}')
new_conf = self.stub.prompt()
assert(new_conf['k1'] == 5)
assert(new_conf['k2'] == self.defaults['k2'])
assert(new_conf['k3'] == self.defaults['k3'])
assert(new_conf['k4'] == self.defaults['k4'])
if __name__ == '__main__':
unittest.main(verbosity=1)