Extended API and switched to py.test for testing

Extended the API:
- db.count(where(...)): Count the number of matching elements
- db.contains(where(...)): Alternative (and better) syntax for
                           where(...) in db

Switched to py.test because the old testing code was ugly and
is now a whole lot better and easier to understand. In this process
also some bugs in the tests have been fixed.