Module tests.moog_demos.example_configs.test_examples

Run all example configs, using random actions.

To run this test, navigate to this directory and run

$ pytest test_examples.py --capture=tee-sys

Note: The –capture=tee-sys routes print statements to stdout, which is useful for debugging.

Alternatively, to run this test and any others, navigate to any parent directory and simply run

$ pytest --capture=tee-sys

This will run all test_* files in children directories.

Classes

class TestExampleConfigs
Expand source code
class TestExampleConfigs():
    """Run all the example configs and levels in _CONFIG_LEVELS."""

    @pytest.mark.parametrize(
        'config_name',
        list(_CONFIG_LEVELS.keys()),
    )
    def testExampleConfigs(self, config_name):
        config_module = importlib.import_module(
            'moog_demos.example_configs.' + config_name)
        for level in _CONFIG_LEVELS[config_name]:
            config = config_module.get_config(level)
            env = environment.Environment(**config)
            for _ in range(_NUM_EPISODES):
                env.reset()
                for _ in range(_NUM_STEPS):
                    env.step(action=env.action_space.random_action())

    def testMultiAgentExample(self):
        config_name = 'multi_agent_example.configs.cleanup'
        config_module = importlib.import_module(config_name)
        config = config_module.get_config(None)
        agents = config.pop('agents')
        agent_name = config.pop('agent_name')
        multi_env = environment.Environment(**config)
        env = env_wrappers.MultiAgentEnvironment(
            environment=multi_env, agent_name=agent_name, **agents)

        for _ in range(_NUM_EPISODES):
            env.reset()
            for _ in range(_NUM_STEPS):
                action_space = env.action_space.action_spaces[agent_name]
                env.step(action=action_space.random_action())

Run all the example configs and levels in _CONFIG_LEVELS.

Methods

def testExampleConfigs(self, config_name)
Expand source code
@pytest.mark.parametrize(
    'config_name',
    list(_CONFIG_LEVELS.keys()),
)
def testExampleConfigs(self, config_name):
    config_module = importlib.import_module(
        'moog_demos.example_configs.' + config_name)
    for level in _CONFIG_LEVELS[config_name]:
        config = config_module.get_config(level)
        env = environment.Environment(**config)
        for _ in range(_NUM_EPISODES):
            env.reset()
            for _ in range(_NUM_STEPS):
                env.step(action=env.action_space.random_action())
def testMultiAgentExample(self)
Expand source code
def testMultiAgentExample(self):
    config_name = 'multi_agent_example.configs.cleanup'
    config_module = importlib.import_module(config_name)
    config = config_module.get_config(None)
    agents = config.pop('agents')
    agent_name = config.pop('agent_name')
    multi_env = environment.Environment(**config)
    env = env_wrappers.MultiAgentEnvironment(
        environment=multi_env, agent_name=agent_name, **agents)

    for _ in range(_NUM_EPISODES):
        env.reset()
        for _ in range(_NUM_STEPS):
            action_space = env.action_space.action_spaces[agent_name]
            env.step(action=action_space.random_action())