API Reference¶
-
class
chide.
Collection
(mapping)¶ A collection of attributes to use to make sample objects.
Parameters: mapping – A dictionary mapping object types to a dictionary of attributes to make a sample object of that type. -
attributes
(type_, **attrs)¶ Make a sample object of the specified
type_
using the default attributes for that type in thisCollection
.The
attrs
mapping will be overlayed onto the sample attributes before being used withtype_
to instantiate and return a new sample object.
-
make
(type_, **attrs)¶ Make the attributes for a sample object of the specified
type_
using the default attributes for that type in thisCollection
.The
attrs
mapping will be overlayed onto the sample attributes and returned as adict
.
-
-
class
chide.
Set
(collection, identify=None)¶ A collection of sample objects where only one object with a given identity may exist at one time.
Parameters: - collection – The
Collection
instance used to create sample objects when necessary. - identify –
A callable that takes type_ and attrs parameters.
type_, usually a class, is the type of the sample object being requested.
attrs is a
dict
of the attributes being requested for the sample object to have.The callable should return a hashable value that indicates the identity to use for the requested sample object. For each unique hashable value, only one sample object will be instantiated and returned each time a sample is requested where this callable returns the given identity.
None
may be returned to indicate that a new object should always be returned for the provided parameters.
-
get
(type_, **attrs)¶ Return an appropriate sample object of the specified
type_
.The
attrs
mapping will be overlaid onto the sample attributes found in this set’sCollection
before checking if an appropriate sample object already exists in the set.If one exists, it is returned. If not, one is created using this set’s
Collection
, added to the set and then returned.
-
identify
= None¶ You may also want to subclass
Set
and implement anidentify()
method, seechide.sqlalchemy.Set
for an example.
- collection – The