SCAutolib.models.log

This module provides a context manager, assert_log, designed for verifying the presence of specific log entries in a file during test execution.

It allows for asserting that a given regular expression matches a newly generated log line within a specified log file.

Functions

assert_log(path, expected_log)[source]

A context manager that asserts the creation of a new log line in a specified file that matches a given regular expression.

When entering the context, the log file’s pointer is moved to its end to ignore any existing logs. The code block within the with statement is then executed. Upon exiting the context (either normally or due to an exception), the function reads new log entries and attempts to find a match for the expected_log regular expression.

If no matching log is found among the newly generated entries, an exception is raised.

Parameters:
  • path (str) – The string path to the log file that will be monitored for new log entries.

  • expected_log (str) – The regular expression string that is expected to match one of the new log lines generated within the context.

Yield:

None. This is a context manager, so it yields control to the with block.

Raises:

Exception – If no new log line matches the expected_log regular expression by the time the context is exited.