Skip to content

Commit

Permalink
Merge pull request #279 from gunthercox/test_strings
Browse files Browse the repository at this point in the history
Test strings
  • Loading branch information
gunthercox authored Sep 4, 2016
2 parents 7bbd81d + 9a78a36 commit 6e73f7b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions chatterbot/chatterbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions tests/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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

4 changes: 2 additions & 2 deletions tests/test_chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?"))
Expand Down
12 changes: 6 additions & 6 deletions tests/training_tests/test_list_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)

0 comments on commit 6e73f7b

Please sign in to comment.