Assert that a class matches certain conditions.
Parameters: | cls (type) – the class under test |
---|
This class provides a readable and efficient method for asserting that a class implements a particular interface. Instead of specifying the interface using abstract base classes and the like, this test specifies the interface as a set of operations, parent classes, and class attributes.
>>> probe = ClassTester(dict)
>>> probe.implements_method('keys')
True
>>> probe.has_attribute('keys')
True
>>> probe.has_attribute('__class__')
True
Each assertion is implemented as a separate method that returns True or False. This is test runner agnostic so you can use the assertions with nose, unittest, or py.test.
Does the class have an attribute named name?
Parameters: |
---|
This method does not inspect the attributes of instances of the class. It only examines the named attributes of the class itself.
Does the class implement a method named name?
Is the class a subclass of parent_class?
Parameters: | parent_class – a dotted class name or anything acceptable to lookup_class(). |
---|
Arrange, Act, Assert test case.
Sub-classes implement test cases by arranging the environment in the arrange() class method, perform the action in the act() class method, and implement assertions as test methods. The individual assertion methods have to be written in such a way that the test runner in use finds them.
The exception or list of exceptions that the test case is interested in capturing. An exception raised from act() will be stored in exception.
The exception that was thrown during the action or None.
The action to test.
Subclasses are required to replace this method.
Catch this set of exception classes.
Arrange the testing environment.
Concrete test classes will probably override this method and should invoke this implementation via super().
Perform post-test cleanup.
Concrete tests classes may override this method if there are actions that need to be performed after act() is called. Subclasses should invoke this implementation via super().
This method is guaranteed to be called after the action under test is invoked and before teardown_class(). It will be called after any captured exception has been caught.
Patch a named class or method.
Parameters: | target (str) – the dotted-name to patch |
---|---|
Returns: | the result of starting the patch. |
This method calls mock.patch() with target and **kwargs, saves the result, and returns the running patch.
Patch a named class and return the created instance.
Parameters: | target (str) – the dotted-name of the class to patch |
---|---|
Returns: | tuple of (patched class, patched instance) |
This method calls patch() with **kwargs to patch target and returns a tuple containing the patched class as well as the return_value attribute of the patched class. This is useful if you want to patch a class and manipulate the result of the code under test creating an instance of the class.
Arrange the environment and perform the action.
This method ensures that arrange() and act() are invoked exactly once before the assertions are fired. If you do find the need to extend this method, you should call this implementation as the last statement in your extension method as it will perform the action under test when it is called.
Stop any patches that have been created.
Return a ClassTester instance for cls.
Parameters: |
|
---|