def setUp(self): # Init neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'}) neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'}) neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3'}) neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4'}) signal1 = Signal(name="order", parameters="this is the sentence") signal2 = Signal(name="order", parameters="this is the second sentence") signal3 = Signal(name="order", parameters="that is part of the third sentence") self.synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) self.synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) self.synapse3 = Synapse(name="Synapse3", neurons=[neuron2, neuron4], signals=[signal3]) self.all_synapse_list = [self.synapse1, self.synapse2, self.synapse3] self.brain_test = Brain(synapses=self.all_synapse_list) self.settings_test = Settings() # clean the LiFO Singleton._instances = dict() LifoManager.clean_saved_lifo()
def test_get_list_synapse_with_raise_missing_parameters(self): # Init neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'}) neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'}) neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3'}) neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4'}) fake_geolocation_parameters = { "longitude": 66, "radius": 66, } signal1 = Signal(name="geolocation", parameters=fake_geolocation_parameters) signal2 = Signal(name="order", parameters="this is the second sentence") synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) synapses_list = [synapse1, synapse2] br = Brain(synapses=synapses_list) # Stubbing the Geolocation Signal with the brain geo = Geolocation() geo.brain = br with self.assertRaises(MissingParameter): geo.run()
def setUp(self): # Kill the singleton Singleton._instances = dict() # Init neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'}) neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'}) neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3'}) neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4'}) signal1 = Signal(name="order", parameters="this is the sentence") signal2 = Signal(name="order", parameters="this is the second sentence") signal3 = Signal(name="order", parameters="that is part of the third sentence") self.synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) self.synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) self.synapse3 = Synapse(name="Synapse3", neurons=[neuron2, neuron4], signals=[signal3]) self.all_synapse_list1 = [self.synapse1, self.synapse2, self.synapse3] self.all_synapse_list2 = [self.synapse2, self.synapse3] self.brain_test1 = Brain(synapses=self.all_synapse_list1) self.brain_test2 = Brain(synapses=self.all_synapse_list2) # this brain is the same as the first one self.brain_test3 = Brain(synapses=self.all_synapse_list1) self.settings_test = Settings() # clean the LiFO LIFOBuffer.lifo_list = list()
def test_get_list_synapse_with_mqtt_subscriber(self): # test with one signal mqtt neuron = Neuron(name='say', parameters={'message': ['test message']}) signal1 = Signal(name="mqtt_subscriber", parameters={ "topic": "test", "broker_ip": "192.168.0.1" }) synapse1 = Synapse(name="synapse1", neurons=[neuron], signals=[signal1]) synapses = [synapse1] brain = Brain() brain.synapses = synapses expected_result = synapses mq = Mqtt_subscriber() mq.brain = brain generator = mq.get_list_synapse() self.assertEqual(expected_result, list(generator)) # test with two synapse neuron = Neuron(name='say', parameters={'message': ['test message']}) signal1 = Signal(name="order", parameters="test_order") signal2 = Signal(name="mqtt_subscriber", parameters={ "topic": "test", "broker_ip": "192.168.0.1" }) synapse1 = Synapse(name="synapse1", neurons=[neuron], signals=[signal1]) synapse2 = Synapse(name="synapse2", neurons=[neuron], signals=[signal1, signal2]) synapses = [synapse1, synapse2] brain = Brain() brain.synapses = synapses expected_result = [synapse2] mq = Mqtt_subscriber() mq.brain = brain generator = mq.get_list_synapse() self.assertEqual(expected_result, list(generator))
def test_get_list_broker_to_instantiate(self): # ---------------- # only one synapse # ---------------- neuron = Neuron(name='say', parameters={'message': ['test message']}) signal1 = Signal(name="mqtt_subscriber", parameters={ "topic": "topic1", "broker_ip": "192.168.0.1" }) synapse1 = Synapse(name="synapse1", neurons=[neuron], signals=[signal1]) brain = Brain() brain.synapses = [synapse1] list_synapse_with_mqtt_subscriber = [synapse1] expected_broker = Broker() expected_broker.broker_ip = "192.168.0.1" expected_broker.topics = list() expected_topic = Topic() expected_topic.name = "topic1" # add the current synapse to the topic expected_topic.synapses = list() expected_topic.synapses.append(synapse1) expected_broker.topics.append(expected_topic) expected_retuned_list = [expected_broker] mq = Mqtt_subscriber() mq.brain = brain self.assertListEqual( expected_retuned_list, mq.get_list_broker_to_instantiate( list_synapse_with_mqtt_subscriber)) # ---------------- # one synapse, two different broker # ---------------- neuron = Neuron(name='say', parameters={'message': ['test message']}) signal1 = Signal(name="mqtt_subscriber", parameters={ "topic": "topic1", "broker_ip": "192.168.0.1", "is_json": False }) signal2 = Signal(name="mqtt_subscriber", parameters={ "topic": "topic2", "broker_ip": "172.16.0.1", "is_json": False }) synapse1 = Synapse(name="synapse1", neurons=[neuron], signals=[signal1, signal2]) brain = Brain() brain.synapses = [synapse1] list_synapse_with_mqtt_subscriber = [synapse1] expected_broker1 = Broker() expected_broker1.broker_ip = "192.168.0.1" expected_broker1.topics = list() expected_topic = Topic() expected_topic.name = "topic1" # add the current synapse to the topic expected_topic.synapses = list() expected_topic.synapses.append(synapse1) expected_broker1.topics.append(expected_topic) expected_broker2 = Broker() expected_broker2.broker_ip = "172.16.0.1" expected_broker2.topics = list() expected_topic = Topic() expected_topic.name = "topic2" # add the current synapse to the topic expected_topic.synapses = list() expected_topic.synapses.append(synapse1) expected_broker2.topics.append(expected_topic) expected_retuned_list = [expected_broker1, expected_broker2] mq = Mqtt_subscriber() mq.brain = brain self.assertEqual( expected_retuned_list, mq.get_list_broker_to_instantiate( list_synapse_with_mqtt_subscriber)) # ---------------- # two synapse, same broker, different topics # ---------------- # synapse 1 neuron1 = Neuron(name='say', parameters={'message': ['test message']}) signal1 = Signal(name="mqtt_subscriber", parameters={ "topic": "topic1", "broker_ip": "192.168.0.1" }) synapse1 = Synapse(name="synapse1", neurons=[neuron1], signals=[signal1]) # synapse 2 neuron2 = Neuron(name='say', parameters={'message': ['test message']}) signal2 = Signal(name="mqtt_subscriber", parameters={ "topic": "topic2", "broker_ip": "192.168.0.1" }) synapse2 = Synapse(name="synapse2", neurons=[neuron2], signals=[signal2]) brain = Brain() brain.synapses = [synapse1, synapse2] list_synapse_with_mqtt_subscriber = [synapse1, synapse2] expected_broker1 = Broker() expected_broker1.broker_ip = "192.168.0.1" expected_broker1.topics = list() expected_topic1 = Topic() expected_topic1.name = "topic1" expected_topic2 = Topic() expected_topic2.name = "topic2" # add the current synapse to the topic expected_topic1.synapses = [synapse1] expected_topic2.synapses = [synapse2] # add both topic to the broker expected_broker1.topics.append(expected_topic1) expected_broker1.topics.append(expected_topic2) expected_retuned_list = [expected_broker1] mq = Mqtt_subscriber() mq.brain = brain self.assertEqual( expected_retuned_list, mq.get_list_broker_to_instantiate( list_synapse_with_mqtt_subscriber)) # ---------------- # two synapse, same broker, same topic # ---------------- # synapse 1 neuron1 = Neuron(name='say', parameters={'message': ['test message']}) signal1 = Signal(name="mqtt_subscriber", parameters={ "topic": "topic1", "broker_ip": "192.168.0.1" }) synapse1 = Synapse(name="synapse1", neurons=[neuron1], signals=[signal1]) # synapse 2 neuron2 = Neuron(name='say', parameters={'message': ['test message']}) signal2 = Signal(name="mqtt_subscriber", parameters={ "topic": "topic1", "broker_ip": "192.168.0.1" }) synapse2 = Synapse(name="synapse2", neurons=[neuron2], signals=[signal2]) brain = Brain() brain.synapses = [synapse1, synapse2] list_synapse_with_mqtt_subscriber = [synapse1, synapse2] expected_broker1 = Broker() expected_broker1.broker_ip = "192.168.0.1" expected_broker1.topics = list() expected_topic1 = Topic() expected_topic1.name = "topic1" # add both synapses to the topic expected_topic1.synapses = [synapse1, synapse2] # add the topic to the broker expected_broker1.topics.append(expected_topic1) expected_retuned_list = [expected_broker1] mq = Mqtt_subscriber() mq.brain = brain self.assertEqual( expected_retuned_list, mq.get_list_broker_to_instantiate( list_synapse_with_mqtt_subscriber))
def test_get_matching_synapse(self): # Init neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'}) neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'}) neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3'}) neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4'}) signal1 = Signal(name="order", parameters="this is the sentence") signal2 = Signal(name="order", parameters="this is the second sentence") signal3 = Signal(name="order", parameters="that is part of the third sentence") signal4 = Signal(name="order", parameters={ "matching-type": "strict", "text": "that is part of the fourth sentence" }) signal5 = Signal(name="order", parameters={ "matching-type": "ordered-strict", "text": "sentence 5 with specific order" }) signal6 = Signal(name="order", parameters={ "matching-type": "normal", "text": "matching type normal" }) signal7 = Signal(name="order", parameters={ "matching-type": "non-existing", "text": "matching type non existing" }) signal8 = Signal(name="order", parameters={ "matching-type": "non-existing", "non-existing-parameter": "will not match order" }) signal9 = Signal( name="order", parameters= "order that should be triggered because synapse is disabled") synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) synapse3 = Synapse(name="Synapse3", neurons=[neuron2, neuron4], signals=[signal3]) synapse4 = Synapse(name="Synapse4", neurons=[neuron2, neuron4], signals=[signal4]) synapse5 = Synapse(name="Synapse5", neurons=[neuron1, neuron2], signals=[signal5]) synapse6 = Synapse(name="Synapse6", neurons=[neuron1, neuron2], signals=[signal6]) synapse7 = Synapse(name="Synapse7", neurons=[neuron1, neuron2], signals=[signal7]) synapse8 = Synapse(name="Synapse8", neurons=[neuron1, neuron2], signals=[signal8]) synapse9 = Synapse(name="Synapse9", enabled=False, neurons=[neuron1, neuron2], signals=[signal9]) all_synapse_list = [ synapse1, synapse2, synapse3, synapse4, synapse5, synapse6, synapse7, synapse8, synapse9 ] br = Brain(synapses=all_synapse_list) # TEST1: should return synapse1 spoken_order = "this is the sentence" # Create the matched synapse expected_matched_synapse_1 = MatchedSynapse(matched_synapse=synapse1, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 1) self.assertTrue(expected_matched_synapse_1 in matched_synapses) # with defined normal matching type spoken_order = "matching type normal" expected_matched_synapse_5 = MatchedSynapse(matched_synapse=synapse6, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 1) self.assertTrue(expected_matched_synapse_5 in matched_synapses) # TEST2: should return synapse1 and 2 spoken_order = "this is the second sentence" expected_matched_synapse_2 = MatchedSynapse(matched_synapse=synapse1, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 2) self.assertTrue(expected_matched_synapse_1, expected_matched_synapse_2 in matched_synapses) # TEST3: should empty spoken_order = "not a valid order" matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertFalse(matched_synapses) # TEST4: with matching type strict spoken_order = "that is part of the fourth sentence" expected_matched_synapse_3 = MatchedSynapse(matched_synapse=synapse4, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertTrue(expected_matched_synapse_3 in matched_synapses) spoken_order = "that is part of the fourth sentence with more word" matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertFalse(matched_synapses) # TEST5: with matching type ordered strict spoken_order = "sentence 5 with specific order" expected_matched_synapse_4 = MatchedSynapse(matched_synapse=synapse5, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 1) self.assertTrue(expected_matched_synapse_4 in matched_synapses) spoken_order = "order specific with 5 sentence" matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertFalse(matched_synapses) # TEST6: non supported type of matching. should fallback to normal spoken_order = "matching type non existing" expected_matched_synapse_5 = MatchedSynapse(matched_synapse=synapse7, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertTrue(expected_matched_synapse_5 in matched_synapses) # TEST7: should not match the disabled synapse spoken_order = "order that should be triggered because synapse is disabled" # we expect an empty list matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertTrue(len(matched_synapses) == 0)
class TestModels(unittest.TestCase): def setUp(self): # Kill the singleton Singleton._instances = dict() # Init neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'}) neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'}) neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3'}) neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4'}) signal1 = Signal(name="order", parameters="this is the sentence") signal2 = Signal(name="order", parameters="this is the second sentence") signal3 = Signal(name="order", parameters="that is part of the third sentence") self.synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) self.synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) self.synapse3 = Synapse(name="Synapse3", neurons=[neuron2, neuron4], signals=[signal3]) self.all_synapse_list1 = [self.synapse1, self.synapse2, self.synapse3] self.all_synapse_list2 = [self.synapse2, self.synapse3] self.brain_test1 = Brain(synapses=self.all_synapse_list1) self.brain_test2 = Brain(synapses=self.all_synapse_list2) # this brain is the same as the first one self.brain_test3 = Brain(synapses=self.all_synapse_list1) self.settings_test = Settings() # clean the LiFO LIFOBuffer.lifo_list = list() def test_APIResponse(self): user_order = "user order" self.matched_synapse = MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order) api_response = APIResponse() api_response.user_order = user_order api_response.list_processed_matched_synapse = [self.matched_synapse] expected_result_serialize = { 'status': None, 'matched_synapses': [{ 'matched_order': 'user order', 'neuron_module_list': [], 'synapse_name': 'Synapse1' }], 'user_order': 'user order' } self.assertDictEqual(expected_result_serialize, api_response.serialize()) def test_Brain(self): # test get synapse by name expect_result = self.synapse1 synapse_name = "Synapse1" self.assertEqual(self.brain_test1.get_synapse_by_name(synapse_name), expect_result) # test equals self.assertTrue(self.brain_test1.__eq__(self.brain_test3)) # test not equals self.assertFalse(self.brain_test1.__eq__(self.brain_test2)) def test_Dna(self): # create DNA object dna1 = Dna(name="dna1", module_type="neuron", author="brain", brain_supported_version="0.1.4", tags="test") dna2 = Dna(name="dna2", module_type="neuron", author="community", brain_supported_version="0.1.2", tags="other") # this dna is exactly the same as the first one dna3 = Dna(name="dna1", module_type="neuron", author="brain", brain_supported_version="0.1.4", tags="test") expected_result_serialize = { 'brain_supported_version': '0.1.4', 'tags': 'test', 'type': 'neuron', 'name': 'dna1', 'author': 'brain' } self.assertDictEqual(expected_result_serialize, dna1.serialize()) self.assertTrue(dna1.__eq__(dna3)) self.assertFalse(dna1.__eq__(dna2)) def test_MatchedSynapse(self): user_order = "user order" matched_synapse1 = MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order) matched_synapse2 = MatchedSynapse(matched_synapse=self.synapse2, matched_order=user_order) matched_synapse3 = MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order) expected_result_serialize = { 'matched_order': 'user order', 'neuron_module_list': [], 'synapse_name': 'Synapse1' } self.assertDictEqual(expected_result_serialize, matched_synapse1.serialize()) self.assertTrue(matched_synapse1.__eq__(matched_synapse3)) self.assertFalse(matched_synapse1.__eq__(matched_synapse2)) # test neuron parameter loader is called with mock.patch("brain.core.NeuronParameterLoader.get_parameters" ) as mock_get_parameters: MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order, user_order=user_order) mock_get_parameters.assert_called_once_with( synapse_order=user_order, user_order=user_order) mock_get_parameters.reset_mock() def test_Neuron(self): neuron1 = Neuron(name="test", parameters={ "key1": "val1", "key2": "val2" }) neuron2 = Neuron(name="test", parameters={ "key3": "val3", "key4": "val4" }) neuron3 = Neuron(name="test", parameters={ "key1": "val1", "key2": "val2" }) expected_result_serialize = { 'name': 'test', 'parameters': { 'key2': 'val2', 'key1': 'val1' } } self.assertDictEqual(expected_result_serialize, neuron1.serialize()) self.assertTrue(neuron1.__eq__(neuron3)) self.assertFalse(neuron1.__eq__(neuron2)) # test password neuron_name = "test" neuron_parameters = {"password": "******", "parameter": "test"} neuron = Neuron() neuron.name = neuron_name neuron.parameters = neuron_parameters expected_result_str = "{'name': 'test', 'parameters': {'password': '******', 'parameter': 'test'}}" self.assertDictEqual(ast.literal_eval(neuron.__str__()), ast.literal_eval(expected_result_str)) neuron_name = "test" neuron_parameters = { "password_parameter": "my secret", "parameter": "test" } neuron = Neuron() neuron.name = neuron_name neuron.parameters = neuron_parameters expected_result_str = "{'name': 'test', 'parameters': {'parameter': 'test', 'password_parameter': '*****'}}" self.assertDictEqual(ast.literal_eval(neuron.__str__()), ast.literal_eval(expected_result_str)) def test_Resources(self): resource1 = Resources(neuron_folder="/path/neuron", stt_folder="/path/stt", tts_folder="/path/tts", trigger_folder="/path/trigger") resource2 = Resources(neuron_folder="/other_path/neuron", stt_folder="/other_path/stt", tts_folder="/other_path/tts", trigger_folder="/other_path/trigger") resource3 = Resources(neuron_folder="/path/neuron", stt_folder="/path/stt", tts_folder="/path/tts", trigger_folder="/path/trigger") expected_result_serialize = { 'tts_folder': '/path/tts', 'neuron_folder': '/path/neuron', 'stt_folder': '/path/stt', 'trigger_folder': '/path/trigger', 'signal_folder': None } self.assertDictEqual(expected_result_serialize, resource1.serialize()) self.assertTrue(resource1.__eq__(resource3)) self.assertFalse(resource1.__eq__(resource2)) def test_RestAPI(self): rest_api1 = RestAPI(password_protected=True, login="******", password="******", active=True, port=5000, allowed_cors_origin="*") rest_api2 = RestAPI(password_protected=False, active=False, port=5000, allowed_cors_origin=None) rest_api3 = RestAPI(password_protected=True, login="******", password="******", active=True, port=5000, allowed_cors_origin="*") expected_result_serialize = { 'password_protected': True, 'port': 5000, 'active': True, 'allowed_cors_origin': '*', 'password': '******', 'login': '******' } self.assertDictEqual(expected_result_serialize, rest_api1.serialize()) self.assertTrue(rest_api1.__eq__(rest_api3)) self.assertFalse(rest_api1.__eq__(rest_api2)) def test_Settings(self): with mock.patch('platform.machine', return_value='pumpkins'): rest_api1 = RestAPI(password_protected=True, login="******", password="******", active=True, port=5000, allowed_cors_origin="*") tts1 = Tts(name="tts1", parameters=dict()) tts2 = Tts(name="tts2", parameters=dict()) stt1 = Stt(name="stt1", parameters=dict()) stt2 = Stt(name="stt2", parameters=dict()) trigger1 = Trigger(name="snowboy", parameters=dict()) player = Player(name="player1") resources = Resources() options = Options() setting1 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=[tts1], stts=[stt1], triggers=[trigger1], players=[player], rest_api=rest_api1, cache_path="/tmp/brain", resources=resources, variables={"key1": "val1"}, options=options) setting1.brain_version = "0.1.5" setting2 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=[tts2], stts=[stt2], triggers=[trigger1], players=[player], rest_api=rest_api1, cache_path="/tmp/brain", resources=resources, variables={"key1": "val1"}, options=options) setting3 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=[tts1], stts=[stt1], triggers=[trigger1], players=[player], rest_api=rest_api1, cache_path="/tmp/brain", resources=resources, variables={"key1": "val1"}, options=options) setting3.brain_version = "0.1.5" expected_result_serialize = { 'default_tts_name': 'pico2wav', 'default_stt_name': 'google', 'default_trigger_name': 'swoyboy', 'default_player_name': 'mplayer', 'ttss': [{ 'name': 'tts1', 'parameters': {} }], 'stts': [{ 'name': 'stt1', 'parameters': {} }], 'triggers': [{ 'name': 'snowboy', 'parameters': {} }], 'players': [{ 'name': 'player1', 'parameters': None }], 'rest_api': { 'password_protected': True, 'login': '******', 'password': '******', 'active': True, 'port': 5000, 'allowed_cors_origin': '*' }, 'cache_path': '/tmp/brain', 'resources': { 'neuron_folder': None, 'stt_folder': None, 'tts_folder': None, 'trigger_folder': None, 'signal_folder': None }, 'variables': { 'key1': 'val1' }, 'machine': 'pumpkins', 'brain_version': '0.1.1', 'options': { 'name': 'Options', 'energy_threshold': 4000, 'adjust_for_ambient_noise_second': 0, 'deaf': None, 'mute': None, 'stt_timeout': 0 }, 'hooks': None } self.maxDiff = None self.assertDictEqual(expected_result_serialize, setting1.serialize()) self.assertTrue(setting1.__eq__(setting3)) self.assertFalse(setting1.__eq__(setting2)) def test_Stt(self): stt1 = Stt(name="stt1", parameters={"key1": "val1"}) stt2 = Stt(name="stt2", parameters={"key2": "val2"}) stt3 = Stt(name="stt1", parameters={"key1": "val1"}) expected_result_serialize = { 'name': 'stt1', 'parameters': { 'key1': 'val1' } } self.assertDictEqual(expected_result_serialize, stt1.serialize()) self.assertTrue(stt1.__eq__(stt3)) self.assertFalse(stt1.__eq__(stt2)) def test_Synapse(self): neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'}) neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'}) neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3'}) neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4'}) signal1 = Signal(name="order", parameters="this is the sentence") signal2 = Signal(name="order", parameters="this is the second sentence") synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) synapse3 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) expected_result_serialize = { 'signals': [{ 'name': 'order', 'parameters': 'this is the sentence' }], 'neurons': [{ 'name': 'neurone1', 'parameters': { 'var1': 'val1' } }, { 'name': 'neurone2', 'parameters': { 'var2': 'val2' } }], 'name': 'Synapse1', 'enabled': True } self.assertDictEqual(expected_result_serialize, synapse1.serialize()) self.assertTrue(synapse1.__eq__(synapse3)) self.assertFalse(synapse1.__eq__(synapse2)) def test_Trigger(self): trigger1 = Trigger(name="trigger1", parameters={"key1": "val1"}) trigger2 = Trigger(name="trigger2", parameters={"key2": "val2"}) trigger3 = Trigger(name="trigger1", parameters={"key1": "val1"}) expected_result_serialize = { 'name': 'trigger1', 'parameters': { 'key1': 'val1' } } self.assertDictEqual(expected_result_serialize, trigger1.serialize()) self.assertTrue(trigger1.__eq__(trigger3)) self.assertFalse(trigger1.__eq__(trigger2)) def test_Player(self): player1 = Player(name="player1", parameters={"key1": "val1"}) player2 = Player(name="player2", parameters={"key2": "val2"}) player3 = Player(name="player1", parameters={"key1": "val1"}) expected_result_serialize = { 'name': 'player1', 'parameters': { 'key1': 'val1' } } self.assertDictEqual(expected_result_serialize, player1.serialize()) self.assertTrue(player1.__eq__(player3)) self.assertFalse(player1.__eq__(player2)) def test_Tts(self): tts1 = Tts(name="tts1", parameters={"key1": "val1"}) tts2 = Tts(name="tts2", parameters={"key2": "val2"}) tts3 = Tts(name="tts1", parameters={"key1": "val1"}) expected_result_serialize = { 'name': 'tts1', 'parameters': { 'key1': 'val1' } } self.assertDictEqual(expected_result_serialize, tts1.serialize()) self.assertTrue(tts1.__eq__(tts3)) self.assertFalse(tts1.__eq__(tts2))