def test_getter_obj(self): class Thing(object): def __init__(self, a_dict): for k, v in list(a_dict.items()): setattr(self, k, v) thing = Thing({'x': 'x-val'}) assertEqual('x-val', util.getter('x')(thing)) assertEqual(None, util.getter('y')(thing))
def do_run(self, sequence, field_name, arg, scope): index_func = util.getter(field_name) current_db = self.find_db_scope() current_table = self.find_table_scope() multi = self.optargs.get('multi', False) return arg.create_index_in_table_in_db(current_db, current_table, field_name, index_func, multi=multi)
def do_run(self, table, lower_key, upper_key, arg, scope): defaults = { 'left_bound': 'closed', 'right_bound': 'open', 'index': 'id' } options = util.extend(defaults, self.optargs) if options['index'] == 'id': map_fn = util.getter('id') else: map_fn, _ = self.find_index_func_for_scope(options['index'], arg) left_test, right_test = operators_for_bounds(options['left_bound'], options['right_bound']) for document in table: doc_val = map_fn(document) if left_test(doc_val, lower_key) and right_test( doc_val, upper_key): yield document
def test_getter_dict(self): a_dict = { 'x': 'x-val' } assertEqual('x-val', util.getter('x')(a_dict)) assertEqual(None, util.getter('y')(a_dict))
def do_run(self, elems, field, arg, scope): return util.group_by_func(util.getter(field), elems)
def do_run(self, sequence, field, arg, scope): return util.min_mapped(util.getter(field), sequence)
def do_run(self, sequence, field, arg, scope): return util.safe_average(list(map(util.getter(field), sequence)))
def do_run(self, sequence, field, arg, scope): return util.safe_sum([util.getter(field)(elem) for elem in sequence])