def testSearchWithMemberVariableNotFoundException(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] es = Searcher() es.add(BlueMarble) # Search for non existent member variable key, should not return anything self.assertRaises(KeyNotFoundException, es.search, ['Does Not Exist', BlueMarble])
def testSingleEntityAndSubEntitySpecific(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] es = Searcher() es.add(MultiResultProxy(None, [BlueMarble], None)) result = es.search("blue marble") self.assertEqual(result.getEntity(), [BlueMarble])
def testSingleEntityAndSubEntityDefAmbiguous(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] es = Searcher() es.add(MultiResultProxy(None, [BlueMarble], None)) self.assertRaises(AmbiguousKeySearchException, es.search, "blue")
def testSearchWithClass(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] es = Searcher() es.add(BlueMarble) result = es.search(BlueMarble) # Should return the entity with the least number of words self.assertEqual(result.getEntity(), [BlueMarble,])
def testReturnsEntityWithLeastNumberOfWords(self): class RedAndBlueMarble(Entity): BIG_RED_SPECK = ['bigRedSpeck', Button] BLUE_SPECK = ['blueSpeck', Button] es = Searcher() es.add(RedAndBlueMarble) result = es.search("speck") # Should return the entity with the least number of words self.assertEqual(result.getEntity(), RedAndBlueMarble.BLUE_SPECK)
def testMultiSearchSubEntityAmbiguous(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] class RedMarble(Entity): RED_SPECK = ['redSpeck', Button] es = Searcher() es.add(MultiResultProxy(None, [BlueMarble, RedMarble], None)) self.assertRaises(AmbiguousKeySearchException, es.search, "speck")
def testSearchWithMemberVariableAmbiguousException(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] class RedMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] es = Searcher() es.add(BlueMarble) es.add(RedMarble) # Both entities have the exact same member variables, should raise ambiguous exception self.assertRaises(AmbiguousKeySearchException, es.search, BlueMarble.BLUE_SPECK)
def testSearchWithMemberVariable(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] class RedMarble(Entity): RED_SPECK = ['redSpeck', Button] es = Searcher() es.add(BlueMarble) es.add(RedMarble) result = es.search(BlueMarble.BLUE_SPECK) # Should return the entity with the least number of words self.assertEqual(result.getEntity(), BlueMarble.BLUE_SPECK)
def testCanSearchMultiProxyResultWithCustomParent(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] class RedMarble(Entity): RED_SPECK = ['redSpeck', Button] customParent = RedMarble(None) es = Searcher() es.add(MultiResultProxy(None, [(BlueMarble, customParent),], None)) result = es.search("blue speck") self.assertEqual(result.getEntity(), BlueMarble.BLUE_SPECK) self.assertEqual(result.getParent(), customParent)
def testMultiSearchSubEntitySpecific(self): class BlueMarble(Entity): BLUE_SPECK = ['blueSpeck', Button] class RedMarble(Entity): RED_SPECK = ['redSpeck', Button] es = Searcher() es.add(MultiResultProxy(None, [BlueMarble, RedMarble], None)) result = es.search("red speck") self.assertEqual(result.getEntity(), RedMarble.RED_SPECK) result = es.search("blue speck") self.assertEqual(result.getEntity(), BlueMarble.BLUE_SPECK)