def test_row2dict(db): item = db.session.execute(db['table'].select().limit(1)).fetchall()[0] assert set(item.keys()) == {'num', 'word'} assert set(row2dict(item).keys()) == {'num', 'word'} assert isinstance(row2dict(item), OrderedDict) assert set(row2dict(item, ignore_keys=('num',)).keys()) == {'word'} assert row2dict(item, ignore_keys=('num', 'word')) == OrderedDict()
def __iter__(self): for item in self.items: if hasattr(item, 'keys') and callable(getattr(item, 'keys')): yield row2dict(item) elif hasattr(item, 'asdict') and callable(getattr(item, 'asdict')): yield item.asdict() else: yield item