From 1fb8d18d3ca5c61c78a636403baf514c54cbe9aa Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sun, 4 Sep 2016 16:47:29 -0400 Subject: [PATCH 1/2] Remove output format setter from base test case. This will now default to return object types for tests. --- tests/base_case.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/base_case.py b/tests/base_case.py index b0cb4a87f..b55d976fb 100644 --- a/tests/base_case.py +++ b/tests/base_case.py @@ -13,7 +13,6 @@ def get_kwargs(self): return { 'input_adapter': 'chatterbot.adapters.input.VariableInputTypeAdapter', 'output_adapter': 'chatterbot.adapters.output.OutputFormatAdapter', - 'output_format': 'text', 'database': self.create_test_data_directory() } @@ -72,6 +71,5 @@ def get_kwargs(self): kwargs = super(ChatBotMongoTestCase, self).get_kwargs() kwargs['database'] = self.random_string() kwargs['storage_adapter'] = 'chatterbot.adapters.storage.MongoDatabaseAdapter' - kwargs['output_format'] = 'object' return kwargs From 9a78a368a2c4e935451c89c2f67c77200a3ac210 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sun, 4 Sep 2016 16:56:32 -0400 Subject: [PATCH 2/2] Update tests now that get_response returns an object. --- chatterbot/chatterbot.py | 4 ++-- tests/test_chatbot.py | 4 ++-- tests/training_tests/test_list_training.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chatterbot/chatterbot.py b/chatterbot/chatterbot.py index 7c19bf3c2..823be8f62 100644 --- a/chatterbot/chatterbot.py +++ b/chatterbot/chatterbot.py @@ -143,12 +143,12 @@ def get_response(self, input_item): existing_statement = self.storage.find(input_statement.text) if existing_statement: - self.logger.info(u'{} is a known statement'.format(input_statement.text)) + self.logger.info(u'"{}" is a known statement'.format(input_statement.text)) if input_statement.extra_data: existing_statement.extra_data.update(input_statement.extra_data) input_statement = existing_statement else: - self.logger.info(u'{} is not a known statement'.format(input_statement.text)) + self.logger.info(u'"{}" is not a known statement'.format(input_statement.text)) # Select a response to the input statement confidence, response = self.logic.process(input_statement) diff --git a/tests/test_chatbot.py b/tests/test_chatbot.py index 3b56d2b6e..0536a4500 100644 --- a/tests/test_chatbot.py +++ b/tests/test_chatbot.py @@ -110,7 +110,7 @@ def test_response_format(self): self.chatbot.storage.update(self.test_statement) response = self.chatbot.get_response("Hi") - statement_object = self.chatbot.storage.find(response) + statement_object = self.chatbot.storage.find(response.text) self.assertEqual(response, self.test_statement.text) self.assertEqual(len(statement_object.in_response_to), 1) @@ -122,7 +122,7 @@ def test_second_response_format(self): response = self.chatbot.get_response("Hi") # response = "Hello" second_response = self.chatbot.get_response("How are you?") - statement = self.chatbot.storage.find(second_response) + statement = self.chatbot.storage.find(second_response.text) # Make sure that the second response was saved to the database self.assertIsNotNone(self.chatbot.storage.find("How are you?")) diff --git a/tests/training_tests/test_list_training.py b/tests/training_tests/test_list_training.py index d2cfd178c..8e1479470 100644 --- a/tests/training_tests/test_list_training.py +++ b/tests/training_tests/test_list_training.py @@ -31,7 +31,7 @@ def test_training_adds_statements(self): response = self.chatbot.get_response("Thank you.") - self.assertEqual(response, "You are welcome.") + self.assertEqual(response.text, "You are welcome.") def test_training_increments_occurrence_count(self): @@ -178,14 +178,14 @@ def test_answer_to_known_input(self): input_text = "What... is your favourite colour?" response = self.chatbot.get_response(input_text) - self.assertIn("Blue", response) + self.assertIn("Blue", response.text) def test_answer_close_to_known_input(self): input_text = "What is your favourite colour?" response = self.chatbot.get_response(input_text) - self.assertIn("Blue", response) + self.assertIn("Blue", response.text) def test_match_has_no_response(self): """ @@ -196,13 +196,13 @@ def test_match_has_no_response(self): input_text = "Siri is my cat" response = self.chatbot.get_response(input_text) - self.assertGreater(len(response), 0) + self.assertGreater(len(response.text), 0) def test_empty_input(self): """ If empty input is provided, anything may be returned. """ - output = self.chatbot.get_response("") + response = self.chatbot.get_response("") - self.assertTrue(len(output) >= 0) + self.assertTrue(len(response.text) >= 0)