def raises_on_out_of_range_sum_test(self): data = self.data try: aggregate.group(data, by=0, sum=3) raise except ValueError: pass
def avg_points_by_city_test(self): actual = aggregate.group(self.data, by='city', avg='points') print(actual) Detroit = [i for i in actual if i['city']=='Detroit'][0] Milan = [i for i in actual if i['city']=='Milan'][0] eq_( 1000, Detroit['avg(points)'] ) eq_( 10000, Milan['avg(points)'] )
def force_return_list_test(self): actual = aggregate.group(self.data, by='city', avg='points', returnas='list') print(actual) Detroit = [i for i in actual if i[0]=='Detroit'][0] Milan = [i for i in actual if i[0]=='Milan'][0] eq_( 1000, Detroit[1] ) eq_( 10000, Milan[1] )
def sum_test(self): data = self.dict_data actual = aggregate.group(data, by='name', sum='score') Lilly = [person for person in actual if person['name']=='Lilly'][0] Mom = [person for person in actual if person['name']=='Mom'][0] Dad = [person for person in actual if person['name']=='Dad'][0] eq_( Lilly['sum(score)'], 300) eq_( Dad['sum(score)'], 10) eq_( Mom['sum(score)'], 450)
def list_min_test(self): data = self.data actual = aggregate.group(data, by=0, mins=2) Lilly = [person for person in actual if person[0]=='Lilly'][0] Mom = [person for person in actual if person[0]=='Mom'][0] Dad = [person for person in actual if person[0]=='Dad'][0] eq_( Lilly[1], 20) eq_( Dad[1], 10) eq_( Mom[1], 10)
def list_count_test(self): data = self.data actual = aggregate.group(data, by=0, count=True) Lilly = [person for person in actual if person[0]=='Lilly'][0] Mom = [person for person in actual if person[0]=='Mom'][0] Dad = [person for person in actual if person[0]=='Dad'][0] eq_(2, Lilly[1]) eq_(2, Dad[1]) eq_(1, Mom[1])
def mixed_aggregate_test(self): actual = aggregate.group(self.data, by=0, avg=[1,2,3], mins=[1,2,3], maxs=[1,2,3]) eq_('a', actual[0][0]) eq_('b', actual[1][0]) eq_(31/3, actual[0][1]) eq_(13, actual[1][1]) eq_(200, actual[0][2]) eq_(75, actual[1][2]) eq_(3224/3, actual[0][3]) eq_(31, actual[1][3]) eq_(1, actual[0][4]) eq_(6, actual[1][4]) eq_(100, actual[0][5]) eq_(50, actual[1][5]) eq_(1000, actual[0][6]) eq_(22, actual[1][6]) eq_(20, actual[0][7]) eq_(20, actual[1][7]) eq_(300, actual[0][8]) eq_(100, actual[1][8]) eq_(1124, actual[0][9]) eq_(40, actual[1][9])
def sum_points_by_city_test(self): actual = aggregate.group(self.data, by='city', sum='points') Detroit = [i for i in actual if i['city']=='Detroit'][0] Milan = [i for i in actual if i['city']=='Milan'][0] eq_( 4000, Detroit['sum(points)'] ) eq_( 40000, Milan['sum(points)'] )
def force_return_dict_test(self): actual = aggregate.group(self.data, by='city', avg='points', returnas='dict') Detroit = [i for i in actual if i['city']=='Detroit'][0] Milan = [i for i in actual if i['city']=='Milan'][0] eq_( 1000, Detroit['avg(points)'] ) eq_( 10000, Milan['avg(points)'] )