Chide¶
Quickly create and compare sample objects.
Chide’s philosophy is to give you a simple registry of parameters needed to instantiate objects for your tests. There’s also support for simplifying objects down to mappings of their attributes for easier comparison and rendering, along with parsing and rendering of formats for inserting or asserting about multiple objects that are naturally tabular.
Quickstart¶
Say we have two classes that each require two parameters in order to be instantiated:
from dataclasses import dataclass
@dataclass
class ClassOne:
x: int
y: int
@dataclass
class ClassTwo:
a: int
b: ClassOne
We can set up a registry of sample values as follows:
from chide import Collection, nest
samples = Collection({
ClassOne: {'x': 1, 'y': 2},
ClassTwo: {'a': 1, 'b': nest(ClassOne)},
})
Now we can quickly make sample objects:
>>> samples.make(ClassOne)
ClassOne(x=1, y=2)
We can provide our own overrides if we want:
>>> samples.make(ClassOne, y=3)
ClassOne(x=1, y=3)
We can also create nested trees of objects:
>>> samples.make(ClassTwo)
ClassTwo(a=1, b=ClassOne(x=1, y=2))
Documentation¶
If you’re looking to create simple sample objects, read the Collections documentation.
If your sample objects have relationships between them, have a look at Sets. There is a specialised set implementation for use with SQLAlchemy.
If you need to deal with multiple sample objects that have many different attribute values, read about Formats.
If you need to make assertions about many objects and want to use formats to do so, you will probably want to use Simplifiers. There are specialised simplifiers for SQLAlchemy rows and ORM-mapped objects.
If you’re interested in seeing patterns of using the above in “real world” ways, see Patterns of Use.
Why chide?¶
Well, it’s hardly mocking…