Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amydunphy authored Aug 29, 2023
1 parent 5989092 commit 405ebc3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/lib/model/test_fasttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ def setUp(self):
self.mock_model = MagicMock()

def test_respond(self):
query = [schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="Hello, how are you?")), schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="今天是星期二"))]
query = [schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="Hello, how are you?")),
schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="今天是星期二")),
schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="چھِ کٲشرۍ نٹن گۅرزٕ خنجر وُچھِتھ اَژان لرزٕ چھُکھ کانہہ دِلاور وُچھِتھ")),
schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="🐐🐐🐐🐐123")),
schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text=""))]


response = self.model.respond(query)

self.assertEqual(len(response), 2)
self.assertEqual(response[0].response, {'language': 'en', 'script': None, 'score': 1.0000062})
self.assertEqual(response[1].response, {'language': 'zh', 'script': 'Hans', 'score': 0.83046132})
self.assertEqual(response[0].response, {'language': 'en', 'script': None, 'score': 1.0})
self.assertEqual(response[1].response, {'language': 'zh', 'script': 'Hans', 'score': 0.8305})
self.assertEqual(response[2].response, {'language': 'ks', 'script': 'Arab', 'score': 0.9999})
self.assertEqual(response[3].response, {'language': 'bo', 'script': 'Tibt', 'score': 0.2168}) #non-text content returns random language with low certainty
self.assertEqual(response[3].response, {'language': 'en', 'script': None, 'score': 0.8267}) #empty string returns english with high-ish confidence

if __name__ == '__main__':
unittest.main()

0 comments on commit 405ebc3

Please sign in to comment.