These are used when you need to compare objects that do not natively support comparison.
| Parameters: |
|
|---|
These are used to capture entries logged to the Python logging framework and make assertions about what was logged.
| Parameters: |
|
|---|
This will compare the captured entries with the expected entries provided and raise an AssertionError if they do not match.
| Parameters: | expected – A sequence of 3-tuples containing the expected log entries. Each tuple should be of the form (logger_name, string_level, message) |
|---|
Clear any entries that have been captured.
Install this LogHandler into the Python logging framework for the named loggers.
This will remove any existing handlers for those loggers and drop their level to 1 in order to capture all logging.
Un-install this LogHandler from the Python logging framework for the named loggers.
This will re-instate any existing handlers for those loggers that were removed during installation and retore their level that prior to installation.
This will uninstall all existing LogHandler objects.
A context manager for capturing output to the sys.stdout and sys.stderr streams.
A property containing any output that has been captured so far.
Compare the captured output to that expected. If the output is not the same, an AssertionError will be raised.
| Parameters: | expected – A string containing the expected output. |
|---|
Disable the output capture if it is enabled.
Enable the output capture if it is disabled.
These are used to manage the mocking out of objects so that units of code can be tested without having to rely on their normal dependencies.
Replace the specified target with the supplied replacement.
| Parameters: |
|
|---|
This context manager is used to assert that an exception is raised within the context it is managing.
| Parameters: | exception – This can be one of the following:
|
|---|
An object that can be used in comparisons of expected and actual strings where the string expected matches a pattern rather than a specific concrete string.
| Parameters: | regex_source – A string containing the source for a regular expression that will be used whenever this StringComparison is compared with any basestring instance. |
|---|
A class representing a temporary directory on disk.
| Parameters: |
|
|---|
Make an empty directory at the specified path within the temporary directory. Any intermediate subdirectories that do not exist will also be created.
| Parameters: | dirpath – The directory to create, which can be:
|
|---|---|
| Returns: | The full path of the created directory. |
Write the supplied data to a file at the specified path within the temporary directory. Any subdirectories specified that do not exist will also be created.
The file will always be written in binary mode.
| Parameters: |
|
|---|---|
| Returns: | The full path of the file written. |
Compare the contents of the temporary directory with the expected contents supplied.
This method only checks the root of the temporary directory.
| Parameters: | expected – A sequence of strings containing the names expected in the directory. |
|---|
Recursively compare the contents of the specified directory with the expected contents supplied.
| Parameters: |
|
|---|
Compare the contents of the specified subdirectory of the temporary directory with the expected contents supplied.
This method will only check the contents of the subdirectory specified and will not recursively check subdirectories.
| Parameters: |
|
|---|
Delete the temporary directory and anything in it. This TempDirectory cannot be used again unless create() is called.
Delete all temporary directories associated with all TempDirectory objects.
Create a temporary directory for this instance to use if one has not already been created.
Return the full path on disk that corresponds to the path relative to the temporary directory that is passed in.
| Parameters: | path – The path to the file to create, which can be:
|
|---|---|
| Returns: | A string containing the full path. |
Print the contents of the specified directory.
| Parameters: |
|
|---|
The physical path of the TempDirectory on disk
Reading the file at the specified path within the temporary directory.
The file is always read in binary mode.
| Parameters: |
|
|---|---|
| Returns: | A string containing the data read. |
Compare the two supplied arguments and raise an AssertionError if they are not the same. The AssertionError raised will attempt to provide descriptions of the differences found.
Any keywords parameters supplied will be passed to the function that ends up doing the comparison. See the API documentation below for details of these.
| Parameters: |
|
|---|
Register the supplied comparer for the specified type. This registration is global and will be in effect from the point this function is called until the end of the current process.
Returns a textual description of the differences between the two supplied sequences.
Returns a textual description of the differences between the two supplied generators.
This is done by first unwinding each of the generators supplied into tuples and then passing those tuples to compare_sequence().
Returns a textual description of the differences between the two supplied dictionaries.
Returns a textual description of the differences between the two supplied sets.
Returns an informative string describing the differences between the two supplied strings. The way in which this comparison is performed can be controlled using the following parameters:
| Parameters: |
|
|---|
A shorthand function that uses difflib to return a string representing the differences between the two string arguments.
Most useful when comparing multi-line strings.
A utility function for creating a generator that will yield the supplied arguments.
A decorator for making a LogCapture installed an available for the duration of a test function.
| Parameters: | names – An optional sequence of names specifying the loggers to be captured. If not specified, the root logger will be captured. |
|---|
A decorator to replace a target object for the duration of a test function.
| Parameters: |
|
|---|
A decorator to assert that the decorated function will raised an exception. An exception class or exception instance may be passed to check more specifically exactly what exception will be raised.
| Parameters: | exception – This can be one of the following:
|
|---|
A decorator for making a TempDirectory available for the duration of a test function.
All arguments and parameters are passed through to the TempDirectory constructor.
A function that returns a mock object that can be used in place of the datetime.date class but where the return value of today() can be controlled.
If a single positional argument of None is passed, then the queue of dates to be returned will be empty and you will need to call set() or add() before calling today().
| Parameters: |
|
|---|
The mock returned will behave exactly as the datetime.date class with the exception of the following members:
This will add the datetime.date created from the supplied parameters to the queue of dates to be returned by today(). An instance of date may also be passed as a single positional argument.
This will set the datetime.date created from the supplied parameters as the next date to be returned by today(), regardless of any dates in the queue. An instance of date may also be passed as a single positional argument.
This will return the next supplied or calculated date from the internal queue, rather than the actual current date.
A function that returns a mock object that can be used in place of the datetime.datetime class but where the return value of now() can be controlled.
If a single positional argument of None is passed, then the queue of datetimes to be returned will be empty and you will need to call set() or add() before calling now() or utcnow().
| Parameters: |
|
|---|
The mock returned will behave exactly as the datetime.datetime class with the exception of the following members:
This will add the datetime.datetime created from the supplied parameters to the queue of datetimes to be returned by now() or utcnow(). An instance of datetime may also be passed as a single positional argument.
This will set the datetime.datetime created from the supplied parameters as the next datetime to be returned by now() or utcnow(), clearing out any datetimes in the queue. An instance of datetime may also be passed as a single positional argument.
| Parameters: | tz – An optional timezone to apply to the returned time. If supplied, it must be an instance of a tzinfo subclass. |
|---|
This will return the next supplied or calculated datetime from the internal queue, rather than the actual current datetime.
If tz is supplied, it will be applied to the datetime that would have have been returned from the internal queue, treating that datetime as if it were in the UTC timezone.
This will return the next supplied or calculated datetime from the internal queue, rather than the actual current UTC datetime.
No timezone will be applied, even that supplied to the constructor.
This will return the date component of the current mock instance, but using the date type supplied when the mock class was created.
A function that returns a mock object that can be used in place of the time.time function but where the return value can be controlled.
If a single positional argument of None is passed, then the queue of times to be returned will be empty and you will need to call set() or add() before calling the mock.
| Parameters: |
|
|---|
The mock additionally has the following methods available on it:
This will add the time specified by the supplied parameters to the queue of times to be returned by calls to the mock. The parameters are the same as the datetime.datetime constructor. An instance of datetime may also be passed as a single positional argument.
This will set the time specified by the supplied parameters as the next time to be returned by a call to the mock, regardless of any times in the queue. The parameters are the same as the datetime.datetime constructor. An instance of datetime may also be passed as a single positional argument.
A decorator that causes the supplied callables to be called before or after the wrapped callable, as appropriate.
A helper for providing a sterile registry when testing with zope.component.
Instantiation will install an empty registry that will be returned by zope.component.getSiteManager().
Remove the sterile registry and replace it with the one that was in place before this TestComponents was instantiated.
A Manuel plugin that parses certain ReST sections to read and write files in the configured TempDirectory.
| Parameters: | name – This is the name of the TempDirectory to use in the Manual global namespace (ie: globs). |
|---|
A singleton used to identify comparisons of objects that are found to be identical.
A singleton used to represent the absence of a particular attribute.