All pastes #249006 Raw Edit

Cody Brocious

public python v1 · immutable
#249006 ·published 2006-11-15 08:09 UTC
rendered paste body
#!/usr/bin/env python# encoding: utf-8"""testBattery.pyCreated by  on 2006-11-14."""from interface import interfacefrom queryableModel import queryableModelclass pet(interface):    __public_attributes__ = ('name', 'age', 'species')        def __init__(self, name, age, species):        self.name = name        self.age = age        self.species = species        def __repr__(self):        return '%s named %s is %i years old' % (`self.species`, `self.name`, self.age)def testQueries():    testObj = queryableModel()    testObj.childAdd(pet('Daeken', 18, 'Human'))    testObj.childAdd(pet('Nikashera', 18, 'Neko'))    testObj.childAdd(pet('Joe Bob', 72, 'Human'))    testObj.childAdd(pet('Dean', 76, 'Human'))    testObj.childAdd(pet('Rudy', 15, 'Dog'))    testObj.childAdd(pet('Blu', 10, 'Cat'))    testObj.childAdd(pet('S4f3_M0D3', 19, 'Human'))    testObj.childAdd(pet("S4f3's girlfriend", 12, 'Human'))        print 'Humans:', testObj.query(lambda child: child.species == 'Human')    print '18 year olds:', testObj.query(lambda child: child.age == 18)    print 'Seniors:', testObj.query(lambda child: child.age > 65)    print 'Humans under 20:', testObj.query(lambda child: child.species == 'Human' and child.age < 20)    print 'Humans under 20 (alternative):', testObj.query(lambda child: child.species == 'Human').query(lambda child: child.age < 20)testQueries()