nti.schema.testing

nti.schema.testing has moved to nti.testing.matchers.

has_length(match)[source]

Matches if len(item) satisfies a given matcher.

Parameters:match – The matcher to satisfy, or an expected value for equal_to() matching.

This matcher invokes the len() function on the evaluated object to get its length, passing the result to a given matcher for evaluation.

If the match argument is not a matcher, it is implicitly wrapped in an equal_to() matcher to check for :equality.

Examples:

has_length(greater_than(6))
has_length(5)
has_attr(name, match=None)

Matches if object has a property with a given name whose value satisfies a given matcher.

Parameters:
  • name – The name of the property.
  • match – Optional matcher to satisfy.

This matcher determines if the evaluated object has a property with a given name. If no such property is found, has_property is not satisfied.

If the property is found, its value is passed to a given matcher for evaluation. If the match argument is not a matcher, it is implicitly wrapped in an equal_to() matcher to check for equality.

If the match argument is not provided, the anything() matcher is used so that has_property is satisfied if a matching property is found.

Examples:

has_property('name', starts_with('J'))
has_property('name', 'Jon')
has_property('name')
is_true()[source]

Matches an object with a true boolean value.

is_false()[source]

Matches an object with a false boolean value.

provides(iface)[source]

Matches an object that provides the given interface.

verifiably_provides(*ifaces)[source]

Matches if the object verifiably provides the correct interface(s), as defined by zope.interface.verify.verifyObject(). This means having the right attributes and methods with the right signatures.

Note

This does not test schema compliance. For that (stricter) test, see validly_provides().

validly_provides(*ifaces)[source]

Matches if the object verifiably and validly provides the given schema (interface(s)).

Verification is done with zope.interface and verifiably_provides(), while validation is done with zope.schema.getValidationErrors().

implements(iface)[source]

Matches if the object implements (is a factory for) the given interface.

See also

zope.interface.interfaces.ISpecification.implementedBy()

validated_by(field, invalid=<class 'zope.interface.exceptions.Invalid'>)[source]

Matches if the data is validated by the given IField.

Parameters:invalid (exception) – The types of exceptions that are considered invalid. Anything other than this is allowed to be raised.

Changed in version 2.0.1: Add invalid and change it from Exception to zope.interface.interfaces.Invalid

not_validated_by(field, invalid=<class 'zope.interface.exceptions.Invalid'>)[source]

Matches if the data is NOT validated by the given IField.

Parameters:invalid (exception) – The types of exceptions that are considered invalid. Anything other than this is allowed to be raised.

Changed in version 2.0.1: Add invalid and change it from Exception to zope.interface.interfaces.Invalid

aq_inContextOf(parent)[source]

Matches if the data is in the acquisition context of the given object.

class TypeCheckedDict(key_class=<type 'object'>, val_class=<type 'object'>, notify=None)[source]

Bases: dict

A dictionary that ensures keys and values are of the required type when set