def setUp(self): self.client = LiteClient(conf.API_KEY)
class Test(unittest.TestCase): def setUp(self): self.client = LiteClient(conf.API_KEY) def testGetSimilarTerms(self): terms = self.client.getSimilarTerms(inputText) self.assertEqual(20, len(terms)) for term in terms: self.assertGreater(len(term), 0) self.assertTrue(conf.isString(term)) terms = self.client.getSimilarTerms(list(range(500))) self.assertEqual(20, len(terms)) for term in terms: self.assertGreater(len(term), 0) self.assertTrue(conf.isString(term)) try: self.client.getSimilarTerms(45) self.fail("An exception should have been thrown") except CorticalioException: pass try: self.client.getSimilarTerms([]) self.fail("An exception should have been thrown") except CorticalioException: pass def testGetKeywords(self): terms = self.client.getKeywords(inputText) self.assertGreater(len(terms), 2) for term in terms: self.assertGreater(len(term), 0) self.assertTrue(conf.isString(term)) def testGetFingerprint(self): self.assertGreater(len(self.client.getFingerprint("apple")), 100) self.assertGreater(len(self.client.getFingerprint("which was the son of")), 100) try: self.client.getFingerprint("") self.fail("An exception should have been thrown") except CorticalioException: pass def testCompare(self): appleString = "apple" bananaString = "banana is a kind of fruit" appleFingerprint = self.client.getFingerprint(appleString) bananaFingerprint = self.client.getFingerprint(bananaString) fingerprint = list(range(500)) self.assertGreater(self.client.compare(appleString, bananaString), 0.1) self.assertGreater(self.client.compare(appleString, bananaFingerprint), 0.1) self.assertGreater(self.client.compare(appleFingerprint, bananaString), 0.1) self.assertGreater(self.client.compare(appleFingerprint, bananaFingerprint), 0.1) self.assertGreater(self.client.compare(fingerprint, "language"), 0.1) self.assertGreater(self.client.compare(fingerprint, list(range(100))), 0.1) self.assertGreater(self.client.compare("language", fingerprint), 0.1) self.assertGreater(self.client.compare(fingerprint, "Linguistics is the scientific study of language"), 0.1) try: self.client.compare("", 2) self.fail("An exception should have been thrown") except CorticalioException: pass def testCategoryF2ilter(self): fingerprint = self.client.createCategoryFilter(["once upon a time", "lived a noble prince"]) self.assertEqual(type(fingerprint), list) self.assertGreater(len(fingerprint), 50) self.assertEqual(type(fingerprint[0]), int) try: self.client.createCategoryFilter([]) self.fail("An exception should have been thrown") except CorticalioException: pass