def test_setup(self): env = self.make_env() self.assertTrue(len(env.instance_set) >= 1) self.assertTrue(env.n_steps > 0) self.assertTrue(type(env.reward_range) is tuple) self.assertTrue(issubclass(type(env.observation_space), spaces.Space)) self.assertTrue(issubclass(type(env.action_space), spaces.Space)) config = { "action_space": spaces.Discrete(2), "observation_space": spaces.Discrete(2), "reward_range": (-1, 0), "cutoff": 30, "benchmark_info": None, "instance_set": { 0: 1, 1: 1 }, } env = AbstractEnv(config) self.assertTrue(len(env.instance_set) >= 1) self.assertTrue(env.n_steps > 0) self.assertTrue(type(env.reward_range) is tuple) self.assertTrue(issubclass(type(env.observation_space), spaces.Space)) self.assertTrue(issubclass(type(env.action_space), spaces.Space))
def make_env(self): config = { "action_space_class": "Discrete", "action_space_args": np.array([4]).astype(np.float32), "observation_space_class": "Box", "observation_space_type": np.float32, "observation_space_args": [ np.array([-1, -1, -1], dtype=np.float32), np.array([1, 1, 1], dtype=np.float32), ], "reward_range": (-1, 0), "cutoff": 30, "benchmark_info": None, "instance_set": { 0: 1, 1: 1 }, } env = AbstractEnv(config) return env
def test_exceptions(self): config = { "action_space_class": "Discrete", "action_space_args": np.array([4]).astype(np.float32), "observation_space_class": "Dict", "observation_space_type": np.float32, "observation_space_args": [ np.array([-1, -1, -1], dtype=np.float32), np.array([1, 1, 1], dtype=np.float32), ], "reward_range": (-1, 0), "cutoff": 30, "instance_set": [[1], [1]], } with pytest.raises(TypeError): AbstractEnv(config) config = { "action_space_class": "Discrete", "action_space_args": np.array([4]).astype(np.float32), "observation_space_class": "Box", "observation_space_type": np.float32, "reward_range": (-1, 0), "cutoff": 30, "instance_set": [[1], [1]], } with pytest.raises(KeyError): AbstractEnv(config) config = { "action_space_class": "Discrete", "action_space_args": np.array([4]).astype(np.float32), "observation_space_type": np.float32, "observation_space_args": [ np.array([-1, -1, -1], dtype=np.float32), np.array([1, 1, 1], dtype=np.float32), ], "reward_range": (-1, 0), "cutoff": 30, "instance_set": [[1], [1]], } with pytest.raises(KeyError): AbstractEnv(config) config = { "action_space_class": "Tuple", "action_space_args": np.array([4]).astype(np.float32), "observation_space_class": "Box", "observation_space_type": np.float32, "observation_space_args": [ np.array([-1, -1, -1], dtype=np.float32), np.array([1, 1, 1], dtype=np.float32), ], "reward_range": (-1, 0), "cutoff": 30, "instance_set": [[1], [1]], } with pytest.raises(TypeError): AbstractEnv(config) config = { "action_space_args": np.array([4]).astype(np.float32), "observation_space_class": "Box", "observation_space_type": np.float32, "observation_space_args": [ np.array([-1, -1, -1], dtype=np.float32), np.array([1, 1, 1], dtype=np.float32), ], "reward_range": (-1, 0), "cutoff": 30, "instance_set": [[1], [1]], } with pytest.raises(KeyError): AbstractEnv(config)