nicolaiarocci/cerberus — pull request #38 by ch3pjw (2014-05-17 12:27:58+00:00)
Title: Mock-like objects with schema enforcement

Being able to validate data structures is great, but often in unit tests I'm seeing people make throw away objects that conform to a schema at the time of writing, but later on, once the schema changes, these objects and their tests may continue to work despite being out-of-date.

I propose this set of additions to make a `CerberusMock` object, a little like an auto-specced `Mock` object from the `mock` library, which will create you blank throwaway objects that conform to the schema, without needing manual initialisation, and then will enforce that any updates to them made in the unit test will conform to the current schema.

Let me know if you a) think this is even a good idea(!) b) think that this is suitable to combine into your module and c) whether you need me to make any ammendments to my current implementation.

Also, just a quick heads up - I changed your type-checking in the main `cerberus.py` file to use more generic type checking (`MutableMapping` and `MutableSequence` over `dict` and `list`) because that felt more Python-duck-type-like, and meant that my `Mock`-like implementation of a `MutableMapping` would still parse validation without any monkey business!

Look forward to hearing from you :-)