def test_generate_model_parameter_errors_1(self): # config = observer_configuration(type="hz", resource=['/topic1', '/topic2', '/topic3']) config = observer_configuration(type="hz", resource=['/topic1']) topics_published_from_nodes = {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']} topics_subscribed_from_nodes = {'node3': ['/topic2'], 'node2': ['/topic1']} nodes_publish_topics = {'node1': ['/topic1'], 'node3': ['/topic3'], 'node2': ['/topic2']} nodes_subscribe_topics = {'node3': ['/topic2'], 'node2': ['/topic1']} config_tests = [(KeyError, observer_configuration(type="hz_wrong", resource=['/topic'])), (ValueError, observer_configuration(type="hz")), (KeyError, observer_configuration()), (TypeError, observer_configuration), (TypeError, 1), (ValueError, observer_configuration(type="hz", resource=[''])), (TypeError, observer_configuration(type="hz", resource=[1])), (TypeError, observer_configuration(type="hz", resource='no_list')), (TypeError, observer_configuration(type="hz", resource=1)), (ValueError, observer_configuration(type="hz", resource=['/topic1', '/topic2', '/topic3'])), (ValueError, observer_configuration(type="hz", resource=['/topic_wrong'])) ] for (error, config) in config_tests: with self.assertRaises(error): print "'" + str(error.__name__) + "' should be raised by '" + str(config).replace("\n", " ") + "'", HzObserver.generate_model_parameter(config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
def test_compare_configuration_13(self): config_a = configuration() config_a.nodes.append( node_configuration(name="node1", pub_topic=["/topic1"], sub_topic=[])) config_a.nodes.append( node_configuration(name="node2", pub_topic=["/topic2"], sub_topic=["/topic1"])) config_a.observers.append( observer_configuration(type="resource", resource=["node1"])) config_a.observers.append( observer_configuration(type="hz", resource=["node2"])) config_b = configuration() config_b.nodes.append( node_configuration(name="node1", pub_topic=["/topic1"], sub_topic=[])) config_b.nodes.append( node_configuration(name="node2", pub_topic=["/topic2"], sub_topic=["/topic1"])) config_b.observers.append( observer_configuration(type="resource", resource=["node1", "node2"])) config_b.observers.append( observer_configuration(type="hz", resource=["node2"])) self.assertFalse(compare_configuration(config_a, config_b), "configurations not equal!")
def test_minimize_config_2(self): config_a = configuration() config_a.nodes.append( node_configuration(name="node1", pub_topic=["/topic1"], sub_topic=[])) config_a.nodes.append( node_configuration(name="node2", pub_topic=["/topic2"], sub_topic=["/topic1"])) config_a.nodes.append( node_configuration(name="node3", pub_topic=["/topic3"], sub_topic=["/topic2"])) config_a.observers.append( observer_configuration(type="resource", resource=["node1"])) config_required = configuration() config_required.nodes.append( node_configuration(name="node1", pub_topic=[], sub_topic=[])) config_required.observers.append( observer_configuration(type="resource", resource=["node1"])) DiagnosisConfigValidator.minimize_config(config_a) self.assertTrue(compare_configuration(config_a, config_required), "configurations not equal!")
def test_generate_model_parameter_errors_2(self): # config = {'nodes': ['node1', 'node2', 'node3'], 'type': 'resources'} config = observer_configuration(type="resources", resource=['node1']) topics_published_from_nodes = {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']} topics_subscribed_from_nodes = {'node3': ['/topic2'], 'node2': ['/topic1']} nodes_publish_topics = {'node1': ['/topic1'], 'node3': ['/topic3'], 'node2': ['/topic2']} nodes_subscribe_topics = {'node3': ['/topic2'], 'node2': ['/topic1']} nodes_subscribe_topics_testes = \ [(ValueError, {'node1': ['/'], 'node2': ['/topic1']}), (ValueError, {'node1': [''], 'node2': ['/topic1']}), (TypeError, {'node1': [1], 'node2': ['/topic1']}), (ValueError, {'node1': ['/topic1'], 'node2': ['/']}), (ValueError, {'node1': ['/topic1'], 'node2': ['']}), (TypeError, {'node1': ['/topic1'], 'node2': [1]}), (ValueError, {'node1': ['/wrong_topic_name'], 'node2': ['/topic2']}), ] for (error, nodes_subscribe_topics) in nodes_subscribe_topics_testes: with self.assertRaises(error): print "'" + str(error.__name__) + "' should be raised by '" + str(nodes_subscribe_topics) + "'", ResourcesObserver.generate_model_parameter(config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
def test_generate_model_parameter2(self): # config = {'nodes': ['node1', 'node2', 'node3'], 'type': 'resources'} config = observer_configuration(type="resources", resource=['node1']) topics_published_from_nodes = {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']} topics_subscribed_from_nodes = {'node3': ['/topic2'], 'node2': ['/topic1']} nodes_publish_topics = {'node1': ['/topic1'], 'node3': ['/topic3'], 'node2': ['/topic2']} nodes_subscribe_topics = {'node3': ['/topic2'], 'node2': ['/topic1']} vars, rules, nodes, real_nodes = ResourcesObserver.generate_model_parameter(config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) vars_req = {'resources_obs_node1': Variable('resources_obs_node1', 1, None), # 'resources_obs_node2': Variable('resources_obs_node2', 1, None), # 'resources_obs_node3': Variable('resources_obs_node3', 1, None) } self.assertEqual(len(vars), len(vars_req), "resources added wrong number of variables!") for i, obj in vars.items(): self.assertTrue(vars_req.has_key(i), "Key '" + str(i) + "' not in variables-required list!") self.assertEqual(str(vars_req[i]), str(obj), "Variable '" + str(i) + "' not generated with right parameters!") rules_req = [ResourcesObserver(ab_pred('node1'), 'resources_obs_node1', all_ab_pred([])), # ResourcesObserver(ab_pred('node2'), 'resources_obs_node2', all_ab_pred(['/topic1'])), # ResourcesObserver(ab_pred('node3'), 'resources_obs_node3', all_ab_pred(['/topic2'])) ] rules_req_str = [str(x) for x in rules_req] self.assertTrue(not any([x for x in rules if str(x) not in rules_req_str]), "Rules does not match!") self.assertEqual(len(rules), len(rules_req), "resources added wrong number of rules!") self.assertEqual(len(nodes), 0, "resources should not add nodes!") self.assertEqual(len(real_nodes), 0, "resources should not add real nodes!")
def test_generate_model_parameter1(self): config = observer_configuration(type="hz", resource=['/topic']) topics_published_from_nodes = {'/topic': ['/node1', '/node2']} topics_subscribed_from_nodes = {} nodes_publish_topics = {'/node1': ['/topic'], '/node2': ['/topic']} nodes_subscribe_topics = {} vars, rules, nodes, real_nodes = HzObserver.generate_model_parameter(config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) vars_req = {'hz_obs_/topic_all': Variable('hz_obs_/topic_all', 1, None), 'hz_obs_/topic_/node1': Variable('hz_obs_/topic_/node1', 1, None), 'hz_obs_/topic_/node2': Variable('hz_obs_/topic_/node2', 1, None)} self.assertEqual(len(vars), len(vars_req), "Hz added wrong number of variables!") for i, obj in vars.items(): self.assertTrue(i in vars_req, "Key '" + str(i) + "' not in variables-required list!") self.assertEqual(str(vars_req[i]), str(obj), "Variable '" + str(i) + "' not generated with right parameters!") subscribed_topics = [] rules_req = [HzObserver(ab_pred('/node1'), 'hz_obs_/topic_/node1', subscribed_topics), HzObserver(ab_pred('/node2'), 'hz_obs_/topic_/node2', subscribed_topics), CalleridsObserver('hz_obs_/topic_all', ['hz_obs_/topic_/node1', 'hz_obs_/topic_/node2'])] rules_req_str = [str(x) for x in rules_req] self.assertTrue(not any([x for x in rules if str(x) not in rules_req_str]), "Rules does not match!") self.assertEqual(len(rules), len(rules_req), "Hz added wrong number of rules!") self.assertEqual(len(nodes), 0, "Hz should not add nodes!") self.assertEqual(len(real_nodes), 0, "Hz should not add real nodes!")
def test_generate_model_parameter1(self): # config = {'topics': [['/topicA', '/topicB']], 'type': 'velocity'} config = observer_configuration(type="velocity", resource=['/topicA', '/topicB']) topics_published_from_nodes = { '/topicA': ['/node1'], '/topicB': ['/node2'] } topics_subscribed_from_nodes = {} nodes_publish_topics = {'/node1': ['/topicA'], '/node2': ['/topicB']} nodes_subscribe_topics = {} vars, rules, nodes, real_nodes = VelocityObserver.generate_model_parameter( config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) vars_req = { 'velocity': Variable("velocity", Variable.BOOLEAN, None), ab_pred("velocity"): Variable(ab_pred("velocity"), Variable.BOOLEAN, None), 'velocity_obs_/topicA_/topicB': Variable('velocity_obs_/topicA_/topicB', 1, None), } self.assertEqual(len(vars), len(vars_req), "Velocity added wrong number of variables!") for i, obj in vars.items(): self.assertTrue( vars_req.has_key(i), "Key '" + str(i) + "' not in variables-required list!") self.assertEqual( str(vars_req[i]), str(obj), "Variable '" + str(i) + "' not generated with right parameters!") subscribed_topics = [] rules_req = [(VelocityObserver(all_ab_pred(['/node1']), all_ab_pred(['/node2']), ab_pred("velocity"), 'velocity_obs_/topicA_/topicB', all_ab_pred([])))] rules_req_str = [str(x) for x in rules_req] self.assertTrue( not any([x for x in rules if str(x) not in rules_req_str]), "Rules does not match!") self.assertEqual(len(rules), len(rules_req), "velocity added wrong number of rules!") self.assertEqual(len(nodes), 0, "Velocity should not add nodes!") self.assertEqual(len(real_nodes), 1, "Velocity should add one real node!") self.assertEqual(str(real_nodes[0]), 'velocity', "'Velocity' not added to real nodes!")
def test_generate_model_parameter_errors_2(self): # config = observer_configuration(type="hz", resource=['/topic1', '/topic2', '/topic3']) config = observer_configuration(type="hz", resource=['/topic1']) topics_published_from_nodes = {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']} topics_subscribed_from_nodes = {'node3': ['/topic2'], 'node2': ['/topic1']} nodes_publish_topics = {'node1': ['/topic1'], 'node3': ['/topic3'], 'node2': ['/topic2']} nodes_subscribe_topics = {'node3': ['/topic2'], 'node2': ['/topic1']} topics_published_from_nodes_testes = \ [ # (ValueError, {'/topic': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': [], '/topic2': ['node2'], '/topic1': ['node1']}), # (ValueError, {'/topic3': ['node3'], '/topic': ['node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': [], '/topic1': ['node1']}), # (ValueError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic': ['node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': []}), (TypeError, {1: ['node3'], '/topic2': ['node2'], '/topic1': ['node1']}), (ValueError, {'/': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']}), (ValueError, {'': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']}), (KeyError, {}), (TypeError, "no_dict"), (TypeError, 1), (ValueError, {'/topic3': ['/', 'node3'], '/topic2': ['node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['', 'node3'], '/topic2': ['node2'], '/topic1': ['node1']}), (TypeError, {'/topic3': [1, 'node3'], '/topic2': ['node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3', '/'], '/topic2': ['node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3', ''], '/topic2': ['node2'], '/topic1': ['node1']}), (TypeError, {'/topic3': ['node3', 1], '/topic2': ['node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['/', 'node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['', 'node2'], '/topic1': ['node1']}), (TypeError, {'/topic3': ['node3'], '/topic2': [1, 'node2'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['node2', '/'], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['node2', ''], '/topic1': ['node1']}), (TypeError, {'/topic3': ['node3'], '/topic2': ['node2', 1], '/topic1': ['node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['/', 'node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['', 'node1']}), (TypeError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': [1, 'node1']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1', '/']}), (ValueError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1', '']}), (TypeError, {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1', 1]}), ] for (error, topics_published_from_nodes) in topics_published_from_nodes_testes: with self.assertRaises(error): print "'" + str(error.__name__) + "' should be raised by '" + str(topics_published_from_nodes) + "'", HzObserver.generate_model_parameter(config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
def test_generate_model_parameter_errors_1(self): # config = {'nodes': ['node1', 'node2', 'node3'], 'type': 'resources'} config = observer_configuration(type="resources", resource=['node1']) topics_published_from_nodes = {'/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1']} topics_subscribed_from_nodes = {'node3': ['/topic2'], 'node2': ['/topic1']} nodes_publish_topics = {'node1': ['/topic1'], 'node3': ['/topic3'], 'node2': ['/topic2']} nodes_subscribe_topics = {'node3': ['/topic2'], 'node2': ['/topic1']} # config_tests = [(KeyError, {'nodes_wrong_name': ['node1'], 'type': 'resources'}), # (KeyError, {'type': 'resources'}), # (KeyError, {}), # (TypeError, "not_a_dict"), # (TypeError, 1), # (ValueError, {'nodes': [], 'type': 'resources'}), # (ValueError, {'nodes': [''], 'type': 'resources'}), # (TypeError, {'nodes': [1], 'type': 'resources'}), # (TypeError, {'nodes': "no_list", 'type': 'resources'}), # (TypeError, {'nodes': 1, 'type': 'resources'}) # ] config_tests = [(KeyError, observer_configuration(type="resources_wrong", resource=['/node'])), (ValueError, observer_configuration(type="resources")), (KeyError, observer_configuration()), (TypeError, observer_configuration), (TypeError, 1), (ValueError, observer_configuration(type="resources", resource=[''])), (TypeError, observer_configuration(type="resources", resource=[1])), (TypeError, observer_configuration(type="resources", resource='no_list')), (TypeError, observer_configuration(type="resources", resource=1)), (ValueError, observer_configuration(type="resources", resource=['/node1', '/node2', '/node3'])), # (ValueError, observer_configuration(type="resources", resource=['/node_wrong'])) ] for (error, config) in config_tests: with self.assertRaises(error): print "'" + str(error.__name__) + "' should be raised by '" + str(config) + "'", ResourcesObserver.generate_model_parameter(config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
def test_generate_model_parameter_errors_3(self): # config = {'topics': [['/topicA', '/topicB']], 'type': 'timing'} config = observer_configuration(type="timing", resource=['/topicA', '/topicB']) topics_published_from_nodes = { '/topicA': ['node1'], '/topicB': ['node2'] } topics_subscribed_from_nodes = {} nodes_publish_topics = {'node1': ['/topicA'], 'node2': ['/topicB']} nodes_subscribe_topics = {} topics_subscribed_from_nodes_tests = \ [ # (ValueError, {'/topicA': ['node2']}, {'/node2': ['/topicA']}), (ValueError, {'/topicA': ['node2']}, {'node2': ['/']}), (ValueError, {'/topicA': ['node2']}, {'node2': ['']}), (TypeError, {'/topicA': ['node2']}, {'node2': [1]}), (ValueError, {'/topicA': ['node2']}, {'node2': ['/topicA', '/']}), (ValueError, {'/topicA': ['node2']}, {'node2': ['/topicA', '']}), (TypeError, {'/topicA': ['node2']}, {'node2': ['/topicA', 1]}), (TypeError, {'/topicA': ['node2']}, {'node2': 'not_a_list'}), (TypeError, {'/topicA': ['node2']}, {'node2': 1}), (ValueError, {'/topicA': ['/']}, {'node2': ['/topicA']}), (ValueError, {'/topicA': ['']}, {'node2': ['/topicA']}), (TypeError, {'/topicA': [1]}, {'node2': ['/topicA']}), (ValueError, {'/topicA': ['node2', '/']}, {'node2': ['/topicA']}), (ValueError, {'/topicA': ['node2', '']}, {'node2': ['/topicA']}), (TypeError, {'/topicA': ['node2', 1]}, {'node2': ['/topicA']}), (TypeError, {'/topicA': 'not_a_list'}, {'node2': ['/topicA']}), (TypeError, {'/topicA': 1}, {'node2': ['/topicA']}), ] for (error, topics_subscribed_from_nodes, nodes_subscribe_topics) in topics_subscribed_from_nodes_tests: with self.assertRaises(error): print "'" + str( error.__name__) + "' should be raised by '" + str( topics_subscribed_from_nodes) + "' + '" + str( nodes_subscribe_topics) + "'", TimingObserver.generate_model_parameter( config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
def test_generate_model_parameter_errors_1(self): # test different arguments for the config-parameter which all should raise exeptions # config = {'topics': ['/topic1', '/topic2', '/topic3'], 'type': 'timestamp'} config = observer_configuration(type="timestamp", resource=['/topic1']) topics_published_from_nodes = { '/topic3': ['node3'], '/topic2': ['node2'], '/topic1': ['node1'] } topics_subscribed_from_nodes = { 'node3': ['/topic2'], 'node2': ['/topic1'] } nodes_publish_topics = { 'node1': ['/topic1'], 'node3': ['/topic3'], 'node2': ['/topic2'] } nodes_subscribe_topics = {'node3': ['/topic2'], 'node2': ['/topic1']} config_tests = [ (KeyError, { 'topics_wrong_name': ['/topic'], 'type': 'timestamp' }), # (KeyError, {'type': 'timestamp'}), # (KeyError, {}), # (TypeError, "not_a_dict"), # (TypeError, 1), # (ValueError, {'topics': [], 'type': 'timestamp'}), # (ValueError, {'topics': [''], 'type': 'timestamp'}), # (TypeError, {'topics': [1], 'type': 'timestamp'}), # (TypeError, {'topics': "no_list", 'type': 'timestamp'}), # (TypeError, {'topics': 1, 'type': 'timestamp'}), # (ValueError, {'topics': ['/topic', '/topic2', '/topic3'], 'type': 'timestamp'}) ] config_tests = [ (KeyError, observer_configuration(type="timestamp_wrong", resource=['/topic'])), (ValueError, observer_configuration(type="timestamp")), (KeyError, observer_configuration()), (TypeError, observer_configuration), (TypeError, 1), (ValueError, observer_configuration(type="timestamp", resource=[''])), (TypeError, observer_configuration(type="timestamp", resource=[1])), (TypeError, observer_configuration(type="timestamp", resource='no_list')), (TypeError, observer_configuration(type="timestamp", resource=1)), (ValueError, observer_configuration(type="timestamp", resource=['/topic1', '/topic2', '/topic3'])), (ValueError, observer_configuration(type="timestamp", resource=['/topic_wrong'])) ] for (error, config) in config_tests: with self.assertRaises(error): print "'" + str( error.__name__) + "' should be raised by '" + str( config) + "'", TimestampObserver.generate_model_parameter( config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
def test_generate_model_parameter_errors_2(self): # config = {'topics': [['/topicA', '/topicB']], 'type': 'timing'} config = observer_configuration(type="timing", resource=['/topicA', '/topicB']) topics_published_from_nodes = { '/topicA': ['/node1'], '/topicB': ['/node2'] } topics_subscribed_from_nodes = {} nodes_publish_topics = {'/node1': ['/topicA'], '/node2': ['/topicB']} nodes_subscribe_topics = {} topics_published_from_nodes_tests = [(ValueError, { '/topic_wrong_name': ['/node1', '/node2'] }), (ValueError, { '/topicB': [] }), (KeyError, {}), (TypeError, "no_dict"), (TypeError, 1), (ValueError, { '/topicB': ['/', '/node2'] }), (ValueError, { '/topicB': ['', '/node2'] }), (TypeError, { '/topicB': [1, '/node2'] }), (ValueError, { '/topicB': ['/node1', '/'] }), (ValueError, { '/topicB': ['/node1', ''] }), (TypeError, { '/topicB': ['/node1', 1] }), (ValueError, { '/topicB': ['/', '/node2'], '/topicA': ['/nodeA1'] }), (ValueError, { '/topicB': ['', '/node2'], '/topicA': ['/nodeA1'] }), (TypeError, { '/topicB': [1, '/node2'], '/topicA': ['/nodeA1'] }), (ValueError, { '/topicB': ['/node1', '/'], '/topicA': ['/nodeA1'] }), (ValueError, { '/topicB': ['/node1', ''], '/topicA': ['/nodeA1'] }), (TypeError, { '/topicB': ['/node1', 1], '/topicA': ['/nodeA1'] }), (ValueError, { '/topicB': ['/node2'], '/topicA': ['/', '/node1'] }), (ValueError, { '/topicB': ['/node2'], '/topicA': ['', '/node1'] }), (TypeError, { '/topicB': ['/node2'], '/topicA': [1, '/node1'] }), (ValueError, { '/topicB': ['/node2'], '/topicA': ['/node1', '/'] }), (ValueError, { '/topicB': ['/node2'], '/topicA': ['/node1', ''] }), (TypeError, { '/topicB': ['/node2'], '/topicA': ['/node1', 1] })] for (error, topics_published_from_nodes) in topics_published_from_nodes_tests: with self.assertRaises(error): print "'" + str( error.__name__) + "' should be raised by '" + str( topics_published_from_nodes) + "'", TimingObserver.generate_model_parameter( config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
def test_generate_model_parameter3(self): # +----------+ /topicA +---------+ /topicB # | starter1 |----------+ +-->| timing1 |----------+ # +----------+ | | +---------+ | # *--* +---> # +----------+ /topicA | | +---------+ /topicB | # | starter2 |----------> +-->| timing2 |----------+ # +----------+ +---------+ # config = {'topics': [['/topicA', '/topicB']], 'type': 'timing'} config = observer_configuration(type="timing", resource=['/topicA', '/topicB']) topics_published_from_nodes = { '/topicA': ['node1', 'node3'], '/topicB': ['node2', 'node4'] } topics_subscribed_from_nodes = {'/topicA': ['node2', 'node4']} nodes_publish_topics = { 'node1': ['/topicA'], 'node2': ['/topicB'], 'node3': ['/topicA'], 'node4': ['/topicB'] } nodes_subscribe_topics = {'node2': ['/topicA'], 'node4': ['/topicA']} vars, rules, nodes, real_nodes = TimingObserver.generate_model_parameter( config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) vars_req = {} vars_req = { 'timing_obs_/topicA_node1_/topicB_all': Variable('timing_obs_/topicA_node1_/topicB_all', 1, None), 'timing_obs_/topicA_node3_/topicB_node4': Variable('timing_obs_/topicA_node3_/topicB_node4', 1, None), 'timing_obs_/topicA_node3_/topicB_all': Variable('timing_obs_/topicA_node3_/topicB_all', 1, None), 'timing_obs_/topicA_node3_/topicB_node2': Variable('timing_obs_/topicA_node3_/topicB_node2', 1, None), 'timing_obs_/topicA_all_/topicB_all': Variable('timing_obs_/topicA_all_/topicB_all', 1, None), 'timing_obs_/topicA_all_/topicB_node4': Variable('timing_obs_/topicA_all_/topicB_node4', 1, None), 'timing_obs_/topicA_all_/topicB_node2': Variable('timing_obs_/topicA_all_/topicB_node2', 1, None), 'timing_obs_/topicA_node1_/topicB_node2': Variable('timing_obs_/topicA_node1_/topicB_node2', 1, None), 'timing_obs_/topicA_node1_/topicB_node4': Variable('timing_obs_/topicA_node1_/topicB_node4', 1, None), } self.assertEqual(len(vars), len(vars_req), "Timing added wrong number of variables!") for i, obj in vars.items(): self.assertTrue( vars_req.has_key(i), "Key '" + str(i) + "' not in variables-required list!") self.assertEqual( str(vars_req[i]), str(obj), "Variable '" + str(i) + "' not generated with right parameters!") rules_req = [ TimingObserver( all_ab_pred(['node2', 'node4']), 'timing_obs_/topicA_node1_/topicB_node2', all_ab_pred(nodes_subscribe_topics.get('node2', []))), TimingObserver( all_ab_pred(['node2', 'node4']), 'timing_obs_/topicA_node1_/topicB_node4', all_ab_pred(nodes_subscribe_topics.get('node4', []))), TimingObserver( all_ab_pred(['node2', 'node4']), 'timing_obs_/topicA_node3_/topicB_node2', all_ab_pred(nodes_subscribe_topics.get('node2', []))), TimingObserver( all_ab_pred(['node2', 'node4']), 'timing_obs_/topicA_node3_/topicB_node4', all_ab_pred(nodes_subscribe_topics.get('node4', []))), CalleridsObserver('timing_obs_/topicA_all_/topicB_all', [ 'timing_obs_/topicA_all_/topicB_node2', 'timing_obs_/topicA_all_/topicB_node4' ]), CalleridsObserver('timing_obs_/topicA_all_/topicB_all', [ 'timing_obs_/topicA_node1_/topicB_all', 'timing_obs_/topicA_node3_/topicB_all' ]), CalleridsObserver('timing_obs_/topicA_node1_/topicB_all', [ 'timing_obs_/topicA_node1_/topicB_node2', 'timing_obs_/topicA_node1_/topicB_node4' ]), CalleridsObserver('timing_obs_/topicA_node3_/topicB_all', [ 'timing_obs_/topicA_node3_/topicB_node2', 'timing_obs_/topicA_node3_/topicB_node4' ]), CalleridsObserver('timing_obs_/topicA_all_/topicB_node2', [ 'timing_obs_/topicA_node1_/topicB_node2', 'timing_obs_/topicA_node3_/topicB_node2' ]), CalleridsObserver('timing_obs_/topicA_all_/topicB_node4', [ 'timing_obs_/topicA_node1_/topicB_node4', 'timing_obs_/topicA_node3_/topicB_node4' ]), ] rules_req_str = [str(x) for x in rules_req] self.assertTrue( not any([x for x in rules if str(x) not in rules_req_str]), "Rules does not match!") self.assertEqual(len(rules), len(rules_req), "Timing added wrong number of rules!") self.assertEqual(len(nodes), 0, "Timing should not add nodes!") self.assertEqual(len(real_nodes), 0, "Timing should not add real nodes!")
def test_generate_model_parameter_errors_1(self): # config = {'topics': [['/topicA', '/topicB']], 'type': 'velocity'} config = observer_configuration(type="velocity", resource=['/topicA', '/topicB']) topics_published_from_nodes = { '/topicA': ['/node1'], '/topicB': ['/node2'] } topics_subscribed_from_nodes = {} nodes_publish_topics = {'/node1': ['/topicA'], '/node2': ['/topicB']} nodes_subscribe_topics = {} config_tests = [(KeyError, { 'topics_wrong_name': [['/topicA', '/topicB']], 'type': 'velocity' }), (KeyError, { 'type': 'velocity' }), (KeyError, {}), (TypeError, "not_a_dict"), (TypeError, 1), (ValueError, { 'topics': [[]], 'type': 'velocity' }), (ValueError, { 'topics': [['']], 'type': 'velocity' }), (TypeError, { 'topics': [[1]], 'type': 'velocity' }), (TypeError, { 'topics': ["no_list_list"], 'type': 'velocity' }), (TypeError, { 'topics': [1], 'type': 'velocity' }), (ValueError, { 'topics': [['/wrong_topic_name', '/topic2', '/topic3']], 'type': 'velocity' }), (ValueError, { 'topics': [], 'type': 'velocity' }), (TypeError, { 'topics': [''], 'type': 'velocity' }), (TypeError, { 'topics': [1], 'type': 'velocity' }), (TypeError, { 'topics': "no_list", 'type': 'velocity' }), (TypeError, { 'topics': 1, 'type': 'velocity' }), (TypeError, { 'topics': ['/topic', '/topic2', '/topic3'], 'type': 'velocity' })] config_tests = [ (KeyError, observer_configuration(type="velocity_wrong", resource=['/topicA', '/topicB'])), (ValueError, observer_configuration(type="velocity")), (KeyError, observer_configuration()), (TypeError, observer_configuration), (TypeError, 1), (ValueError, observer_configuration(type="velocity", resource=[''])), (ValueError, observer_configuration(type="velocity", resource=[1])), (TypeError, observer_configuration(type="velocity", resource='no_list')), (TypeError, observer_configuration(type="velocity", resource=1)), (ValueError, observer_configuration(type="velocity", resource=['/topicA', '/topicB', '/topicC'])), (ValueError, observer_configuration(type="velocity", resource=['/topicA'])), (ValueError, observer_configuration(type="velocity", resource=['/topic_wrong'])) ] for (error, config) in config_tests: with self.assertRaises(error): print "'" + str( error.__name__) + "' should be raised by '" + str( config) + "'", VelocityObserver.generate_model_parameter( config, topics_published_from_nodes, topics_subscribed_from_nodes, nodes_publish_topics, nodes_subscribe_topics) print "... DONE"
# a_config = configuration() a_config.nodes.append( node_configuration(name="node1", pub_topic=["/topic1"], sub_topic=[])) a_config.nodes.append( node_configuration(name="node2", pub_topic=["/topic2"], sub_topic=["/topic1"])) a_config.nodes.append( node_configuration(name="node3", pub_topic=["/topic3"], sub_topic=["/topic2"])) # config_a.observers.append(observer_configuration(type="movement", resource=["/topic1", "/topic2"])) a_config.observers.append( observer_configuration(type="resource", resource=["node1"])) a_config.observers.append( observer_configuration(type="resource", resource=["node2"])) a_config.observers.append( observer_configuration(type="resource", resource=["node3"])) # config_b = configuration() # config_b.nodes.append(node_configuration(name="node1", pub_topic=["/topic1"], sub_topic=[])) # config_b.nodes.append(node_configuration(name="node2", pub_topic=["/topic2"], sub_topic=["/topic1"])) # config_b.nodes.append(node_configuration(name="node3", pub_topic=["/topic3"], sub_topic=["/topic2"])) # config_b.observers.append(observer_configuration(type="resource", resource=["node1"])) # config_b.observers.append(observer_configuration(type="resource", resource=["node2"])) # config_b.observers.append(observer_configuration(type="resource", resource=["node3"])) # print compare_configuration(config_a, config_b)
node_configuration(name=str(name), pub_topic=list(pub_topic), sub_topic=list(sub_topic))) rospy.loginfo("tug_diagnosis_initialization: load observers") for observation in YamlHelper.get_param(configs, 'observations'): type = YamlHelper.get_param(observation, 'type') resource = [] if YamlHelper.has_key(observation, 'nodes'): resource = YamlHelper.get_param(observation, 'nodes', []) elif YamlHelper.has_key(observation, 'topics'): resource = YamlHelper.get_param(observation, 'topics', []) model_configuration.observers.append( observer_configuration(type=str(type), resource=list(resource))) rospy.loginfo( str(len(model_configuration.nodes)) + " nodes and " + str(len(model_configuration.observers)) + " observers loaded") rospy.loginfo("tug_diagnosis_initialization: waiting for service") rospy.wait_for_service('diagnosis_configuration_change') try: diagnosis_changer_srv = rospy.ServiceProxy( 'diagnosis_configuration_change', DiagnosisConfiguration) resp1 = diagnosis_changer_srv(model_configuration, DiagnosisConfigurationRequest.SET) error_code = resp1.errorcode error_msg = resp1.error_msg rospy.loginfo("tug_diagnosis_initialization: configuration sent")