Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_update_modifies_existing_statement(self):
statement = Statement(text="New statement")
self.adapter.update(statement)
# Check the initial values
results = list(self.adapter.filter(text=statement.text))
self.assertEqual(len(results), 1)
self.assertEqual(results[0].in_response_to, None)
# Update the statement value
statement.in_response_to = "New response"
self.adapter.update(statement)
# Check that the values have changed
results = list(self.adapter.filter(text=statement.text))
def test_levenshtein_distance_statement_integer(self):
"""
Test that an exception is not raised if a statement is initialized
with an integer value as its text attribute.
"""
statement = Statement(text=2)
other_statement = Statement(text='Hello')
value = self.compare(statement, other_statement)
self.assertEqual(value, 0)
def test_positive_input(self):
statement = Statement(text="Do you know what time it is?")
response = self.adapter.process(statement)
self.assertEqual(response.confidence, 1)
self.assertIn("The current time is ", response.text)
def process(self, statement):
response = Statement('Good morning.')
response.confidence = 0.2
return response
def test_confidence_half_match(self):
# Assume that the storage adapter returns a partial match
self.adapter.chatbot.storage.filter = MagicMock(return_value=[
Statement(text='xxyy')
])
statement = Statement(text='wwxx')
match = self.adapter.get(statement)
self.assertEqual(match.confidence, 0.5)
def test_inches_to_kilometers_variation_2(self):
statement = Statement(text='how many inches in two kilometers ?')
self.assertTrue(self.adapter.can_process(statement))
expected_value = 78740.2
response_statement = self.adapter.process(statement)
self.assertIsNotNone(response_statement)
self.assertLessEqual(abs(response_statement.confidence - 1.0), 1e-10)
self.assertLessEqual(abs(float(response_statement.text) - expected_value), 0.1)
def test_match_with_no_response(self):
"""
A response to the input should be returned if a response is known.
"""
self.chatbot.storage.create(
text='To eat pasta.',
in_response_to='What is your quest?'
)
statement = Statement(text='What is your quest?')
response = self.adapter.process(statement)
self.assertEqual(response.text, 'To eat pasta.')
self.assertEqual(response.confidence, 0)
def test_e_constant(self):
statement = Statement(text='What is e plus one ?')
response = self.adapter.process(statement)
self.assertEqual(response.text, 'e plus one = 3.718281')
self.assertEqual(response.confidence, 1)
def test_create_many_tags(self):
self.adapter.create_many([
StatementObject(text='A', tags=['first', 'letter']),
StatementObject(text='B', tags=['second', 'letter'])
])
results = list(self.adapter.filter())
self.assertEqual(len(results), 2)
self.assertIn('letter', results[0].get_tags())
self.assertIn('letter', results[1].get_tags())
self.assertIn('first', results[0].get_tags())
self.assertIn('second', results[1].get_tags())
def setUp(self):
self.test_data_directory = None
self.chatbot = ChatBot('Test Bot', **self.get_kwargs())