def test_excluded_domain(capsys, logging_config): log = Logger() log._enable_all = False log.spam('eggs') out, err = capsys.readouterr() assert out == '' assert err == ''
def test_enable_all(capsys, logging_config): log = Logger() log.set_enable_all(True) log.spam('eggs') out, err = capsys.readouterr() assert out == '' assert err.find("[spam] eggs\n") >= 0
def test_logging_config(): config = Config([__name__, '--log', 'v1', 'v2', 'v3']) log = Logger() assert (config.verbose is False) assert ('v1' in log._enabled_keys) assert ('v2' in log._enabled_keys) assert ('v3' in log._enabled_keys) assert ('v4' not in log._enabled_keys)
def test_included_domain(capsys, logging_config): log = Logger() log.foo('bar') log.baz('qux') out, err = capsys.readouterr() assert out == '' assert err.find('[foo] bar\n') >= 0 assert err.find('[baz] qux\n') >= 0
def test_verbose_logging(capsys, temp_dot_bonsai): config = Config([ __name__, '--verbose' ]) log = Logger() assert(config.verbose is True) assert(log._enable_all is True)
def test_disable_domain(capsys, logging_config): log = Logger() log.set_enabled('spam', False) assert log._enabled_keys['spam'] == False log.spam('eggs') out, err = capsys.readouterr() assert out == '' assert err == ''
""" Provides the state transform, action transform, terminal function and reward function. The functions in this file are called from cartpole_simulator.py. """ import math from bonsai_ai.logger import Logger log = Logger() def state(model_state): """ Convert the state as represented in CartPole to a format expected. by the AI Engine. """ return { 'position': model_state[0], 'velocity': model_state[1], 'angle': model_state[2], 'rotation': model_state[3], } def terminal(model_state): """ Return true if the state should end the episode. This includes both failure terminals (such as when the model isout-of-bounds) and success terminals (when the model is in a successful state) """ x, x_dot, theta, theta_dot = model_state theta_threshold_radians = 12 * 2 * math.pi / 360
def test_verbose_logging(): config = Config([__name__, '--verbose']) log = Logger() assert (config.verbose is True) assert (log._enable_all is True) assert (len(log._enabled_keys.keys()) == 0)