def test_configuration_changes(self): """ The configuration should not change after running the simulation. """ config = utils.load_file(join(EXAMPLES, 'complete.yml'))[0] s = simulation.from_config(config) s.dry_run = True for i in range(5): s.run_simulation(dry_run=True) nconfig = s.to_dict() del nconfig['topology'] assert config == nconfig
def test_configuration_changes(self): """ The configuration should not change after running the simulation. """ config = utils.load_file('examples/complete.yml')[0] s = simulation.from_config(config) for i in range(5): s.run_simulation(dry_run=True) nconfig = s.to_dict() del nconfig['topology'] del nconfig['dry_run'] del nconfig['load_module'] assert config == nconfig
def test_yaml(self): """ The YAML version of a newly created simulation should be equivalent to the configuration file used """ with utils.timer('loading'): config = utils.load_file(join(EXAMPLES, 'complete.yml'))[0] s = simulation.from_config(config) s.dry_run = True with utils.timer('serializing'): serial = s.to_yaml() with utils.timer('recovering'): recovered = yaml.load(serial) with utils.timer('deleting'): del recovered['topology'] assert config == recovered
def test_torvalds_example(self): """A complete example from a documentation should work.""" config = utils.load_file(join(EXAMPLES, 'torvalds.yml'))[0] config['network_params']['path'] = join(EXAMPLES, config['network_params']['path']) s = simulation.from_config(config) env = s.run_simulation(dry_run=True)[0] for a in env.network_agents: skill_level = a.state['skill_level'] if a.id == 'Torvalds': assert skill_level == 'God' assert a.state['total'] == 3 assert a.state['neighbors'] == 2 elif a.id == 'balkian': assert skill_level == 'developer' assert a.state['total'] == 3 assert a.state['neighbors'] == 1 else: assert skill_level == 'beginner' assert a.state['total'] == 3 assert a.state['neighbors'] == 1