Skip to content

Commit

Permalink
test(monitor): add test case for empty batch_df in collect_from_temp
Browse files Browse the repository at this point in the history
- Added `test_collect_from_temp_empty_batch_df` to verify `df` remains unchanged when `batch_df` is empty or invalid.
- Confirmed `temp_rows` is cleared even if `batch_df` is empty.
  • Loading branch information
jacksonpradolima committed Dec 22, 2024
1 parent bdd9e1d commit 4aa0b77
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions coleman4hcs/tests/utils/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,35 @@ def test_temp_limit_exceeded():
assert all(col in collector.df.columns for col in collector.col_names), "DataFrame structure is incorrect."


def test_collect_from_temp_empty_temp_rows(monitor_collector):
"""
Test that collect_from_temp does nothing when temp_rows is empty.
"""
monitor_collector.temp_rows = [] # Ensure temp_rows is empty
monitor_collector.collect_from_temp()

# Assert that df remains empty
assert monitor_collector.df.empty, "Expected df to remain empty when temp_rows is empty."


def test_collect_from_temp_empty_batch_df(monitor_collector):
"""
Test that collect_from_temp does nothing when batch_df is empty.
"""
# Create a temp_rows list that results in an empty DataFrame
monitor_collector.temp_rows = [{}] # Add a record that lacks proper data
monitor_collector.collect_from_temp()

# Assert that df remains empty
assert monitor_collector.df.empty, (
f"Expected df to remain empty when batch_df is empty. Found: {monitor_collector.df}"
)
# Assert that temp_rows is cleared
assert not monitor_collector.temp_rows, (
f"Expected temp_rows to be cleared but found: {monitor_collector.temp_rows}"
)


@pytest.mark.performance
@pytest.mark.parametrize("num_records", [1000, 10_000, 100_000])
def test_temp_limit_performance(benchmark, num_records):
Expand Down

0 comments on commit 4aa0b77

Please sign in to comment.