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. -
make
(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.
-
-
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.
- collection – The
-
class
chide.sqlalchemy.
Set
(collection, identify=None)¶ A specialised
chide.Set
for getting sample declaratively mapped objects when using SQLAlchemy.-
static
identify
(type_, attrs)¶ This method returns the primary key that will be used for the returned object, meaning that only one sample object will exist and be returned for each primary key in a table.
If any element of the primary key is
None
, a new object is always returned.
-
static