View module source on GitHub

Mock writer for testing purposes.

This module provides a mock implementation of LogWriter that captures logs in memory for testing purposes.

MockLogWriter

class MockLogWriter()

Mock implementation of LogWriter for testing.

This class captures all logs and commands in memory, allowing tests to verify what was logged without making actual API calls.

__init__

def __init__(config: LogWriterConfig)

Initialize a MockLogWriter instance.

Arguments:

NameDescription
configConfiguration for the LogWriter.

repository_id

@property
def repository_id()

Get the repository ID.

commit

def commit(log: CommitLog)

Mock commit that stores the log instead of queuing it.

Arguments:

NameDescription
logCommitLog object to store.

flush

def flush(is_sync=False)

Mock flush that moves queued logs to flushed logs.

Arguments:

NameDescription
is_syncWhether to flush synchronously (ignored in mock).

flush_commit_logs

def flush_commit_logs(is_sync=False)

Mock flush for commit logs only.

flush_upload_attachment_logs

def flush_upload_attachment_logs(is_sync=False)

Mock flush for upload attachment logs only.

cleanup

def cleanup(is_sync=False)

Mock cleanup that flushes remaining logs.

Arguments:

NameDescription
is_syncWhether to cleanup synchronously (ignored in mock).

get_all_logs

def get_all_logs() -> list[CommitLog]

Get all logs (committed, flushed, and uploaded).

get_committed_logs

def get_committed_logs()

Get only committed logs.

get_flushed_logs

def get_flushed_logs()

Get only flushed logs.

get_uploaded_attachments

def get_uploaded_attachments()

Get only uploaded attachment logs.

get_logs_by_action

def get_logs_by_action(action)

Get logs filtered by action type.

get_logs_by_entity_action

def get_logs_by_entity_action(entity, action)

Get logs filtered by entity and action type.

get_logs_by_entity

def get_logs_by_entity(entity)

Get logs filtered by entity type.

get_logs_by_entity_and_action

def get_logs_by_entity_and_action(entity, action)

Get logs filtered by entity and action type.

get_logs_by_entity_id

def get_logs_by_entity_id(entity_id)

Get logs filtered by entity ID.

clear_logs

def clear_logs()

Clear all stored logs.

assert_log_count

def assert_log_count(expected_count)

Assert the total number of logs.

assert_entity_action_count

def assert_entity_action_count(entity, action, expected_count)

Assert the number of logs for a specific entity and action.

assert_action_count

def assert_action_count(action, expected_count)

Assert the number of logs for a specific action.

assert_entity_count

def assert_entity_count(entity, expected_count)

Assert the number of logs for a specific entity.

def print_logs_summary()

Print a summary of all captured logs for debugging.