Ensure that records() always returns a list.

A lot of the code stores the items for later, and using an iterator will
result in unhappiness when the data can't be iterated over more than once.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2014-03-04 01:34:55 +00:00
parent dc4a1b21e7
commit daa3d6fef7
No known key found for this signature in database
GPG key ID: BF535D811F52F68B
2 changed files with 2 additions and 1 deletions

View file

@ -439,7 +439,7 @@ class Database:
if self._needs_upgrade:
raise newfol.exception.UpgradeError("Database needs upgrading")
if select is not None:
return filter(select, self._records)
return list(filter(select, self._records))
return self._records
def location(self):
return self._location

View file

@ -176,6 +176,7 @@ class TestDatabaseFiltering(unittest.TestCase):
return False
return True
selected = db.records(has_only_numbers)
self.assertEqual(type(selected), list)
self.assertEqual(set(selected), set(records[1:]))
ddir.cleanup()