QTZPOC-20: Enhance system robustness and test coverage across bundle processing, activity error handling, and worker operations. * Strengthen bundle reader validation with new tests for archive integrity, security vulnerabilities (e.g., path traversal, duplicate entries, special file types), and I/O error resilience. * Improve error handling and status propagation in PI Web API, MLflow, and OPC activities, including partial write scenarios and OPC session management. * Add comprehensive tests for worker startup, configuration, graceful shutdown, and Prometheus metrics server initialization. * Introduce a new utility for intelligent DataFrame debugging, summarizing large dataframes for concise logging, and refine exception chain summarization. * Update code coverage configuration to exclude @overload decorator lines.
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""Debug message formatting: full dataframe when small, a summary when it would flood the log."""
|
|
|
|
from pandas import DataFrame
|
|
|
|
from laborious.utils.dataframe_debug import (
|
|
DEFAULT_MAX_DEBUG_DATAFRAME_ROWS,
|
|
build_dataframe_debug_message,
|
|
)
|
|
|
|
|
|
def test_non_dataframe_payloads_are_stringified():
|
|
assert build_dataframe_debug_message('payload:', {'a': 1}) == "payload: {'a': 1}"
|
|
|
|
|
|
def test_a_small_dataframe_is_logged_in_full():
|
|
data = DataFrame({'a': [1, 2]})
|
|
|
|
message = build_dataframe_debug_message('payload:', data)
|
|
|
|
assert message.startswith('payload:\n')
|
|
assert data.to_csv() in message
|
|
|
|
|
|
def test_a_dataframe_over_the_row_limit_is_summarized_instead():
|
|
data = DataFrame({'a': range(DEFAULT_MAX_DEBUG_DATAFRAME_ROWS + 1)})
|
|
|
|
message = build_dataframe_debug_message('payload:', data)
|
|
|
|
assert 'skipped because dataframe has' in message
|
|
assert str(data.shape) in message
|
|
assert data.to_csv() not in message
|
|
|
|
|
|
def test_the_row_limit_is_configurable():
|
|
data = DataFrame({'a': [1, 2, 3]})
|
|
|
|
message = build_dataframe_debug_message('payload:', data, max_rows=1)
|
|
|
|
assert 'skipped because dataframe has 3 rows' in message
|
|
assert '(max: 1)' in message
|