SIENTIAPDE-1430: Remove verbose options and direct print statements from model, preprocessor, and report utilities.

This commit is contained in:
Bruno Domingues
2025-12-18 21:09:12 -03:00
parent 13941fc3f7
commit 38fb9a9c53
4 changed files with 13 additions and 89 deletions

View File

@@ -748,11 +748,9 @@ def test_linear_regression_model_fit_with_inf_values():
assert 'var2' in model.variable_columns
def test_linear_regression_model_fit_polynomial_verbose():
"""Test fit with polynomial features and verbose output."""
model = LinearRegressionModel(
target_variable='target', variable_columns=['var1'], degree=2, verbose=True
)
def test_linear_regression_model_fit_polynomial():
"""Test fit with polynomial features."""
model = LinearRegressionModel(target_variable='target', variable_columns=['var1'], degree=2)
data = pd.DataFrame({'var1': [1, 2, 3, 4, 5], 'target': [3, 5, 7, 9, 11]})
model.fit(data)
@@ -825,7 +823,7 @@ def test_linear_regression_model_get_regressor():
@patch('model_manager.sientia.models.treat_nan')
def test_data_preprocessor_treat_discontinuities_linear_interpolation(mock_treat_nan):
"""Test treat_discontinuities with 'linear interpolation' treatment."""
preprocessor = DataPreprocessor(nan_treatment='linear interpolation', verbose=True)
preprocessor = DataPreprocessor(nan_treatment='linear interpolation')
data = pd.DataFrame({'col1': [1, np.nan, 3]})
expected_data = pd.DataFrame({'col1': [1.0, 2.0, 3.0]})
mock_treat_nan.return_value = expected_data
@@ -839,7 +837,7 @@ def test_data_preprocessor_treat_discontinuities_linear_interpolation(mock_treat
def test_data_preprocessor_range_selection_with_start_date():
"""Test range_selection filters by start_date."""
preprocessor = DataPreprocessor(start_date='2023-01-02', verbose=True)
preprocessor = DataPreprocessor(start_date='2023-01-02')
data = pd.DataFrame(
{'col1': [1, 2, 3]},
index=pd.to_datetime(['2023-01-01', '2023-01-02', '2023-01-03']),
@@ -853,7 +851,7 @@ def test_data_preprocessor_range_selection_with_start_date():
def test_data_preprocessor_range_selection_with_end_date():
"""Test range_selection filters by end_date."""
preprocessor = DataPreprocessor(end_date='2023-01-02', verbose=True)
preprocessor = DataPreprocessor(end_date='2023-01-02')
data = pd.DataFrame(
{'col1': [1, 2, 3]},
index=pd.to_datetime(['2023-01-01', '2023-01-02', '2023-01-03']),
@@ -895,7 +893,7 @@ def test_data_preprocessor_range_selection_with_invalid_end_date():
def test_data_preprocessor_range_selection_with_removed_intervals():
"""Test range_selection removes specified intervals."""
preprocessor = DataPreprocessor(removed_intervals=[['2023-01-02', '2023-01-03']], verbose=True)
preprocessor = DataPreprocessor(removed_intervals=[['2023-01-02', '2023-01-03']])
data = pd.DataFrame(
{'col1': [1, 2, 3, 4, 5]},
index=pd.to_datetime(
@@ -999,51 +997,6 @@ def test_data_preprocessor_predict_preserves_feature_order():
# ============================================================================
def test_data_preprocessor_range_selection_start_date_non_verbose():
"""Test range_selection with start_date but verbose=False."""
preprocessor = DataPreprocessor(start_date='2023-01-02', verbose=False)
data = pd.DataFrame(
{'col1': [1, 2, 3]},
index=pd.to_datetime(['2023-01-01', '2023-01-02', '2023-01-03']),
)
result = preprocessor.range_selection(data)
assert len(result) == 2
assert result.index[0] == pd.Timestamp('2023-01-02')
def test_data_preprocessor_range_selection_end_date_non_verbose():
"""Test range_selection with end_date but verbose=False."""
preprocessor = DataPreprocessor(end_date='2023-01-02', verbose=False)
data = pd.DataFrame(
{'col1': [1, 2, 3]},
index=pd.to_datetime(['2023-01-01', '2023-01-02', '2023-01-03']),
)
result = preprocessor.range_selection(data)
assert len(result) == 2
assert result.index[-1] == pd.Timestamp('2023-01-02')
def test_data_preprocessor_range_selection_removed_intervals_non_verbose():
"""Test range_selection with removed_intervals but verbose=False."""
preprocessor = DataPreprocessor(removed_intervals=[['2023-01-02', '2023-01-03']], verbose=False)
data = pd.DataFrame(
{'col1': [1, 2, 3, 4, 5]},
index=pd.to_datetime(
['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05']
),
)
result = preprocessor.range_selection(data)
assert len(result) == 3
assert pd.Timestamp('2023-01-02') not in result.index
assert pd.Timestamp('2023-01-03') not in result.index
def test_data_preprocessor_predict_target_not_in_columns():
"""Test predict when target_variable is not in transformed data columns."""
preprocessor = DataPreprocessor(

View File

@@ -24,15 +24,13 @@ def test_load_html_from_file_success(tmp_path):
assert content == '<p>Hello</p>'
def test_load_html_from_file_missing_file(capsys):
def test_load_html_from_file_missing_file():
result = reports.load_html_from_file('non-existent.html')
captured = capsys.readouterr()
assert result is None
assert 'File not found: non-existent.html' in captured.out
def test_load_html_from_file_os_error(monkeypatch, capsys):
def test_load_html_from_file_os_error(monkeypatch):
def fake_open(*_args, **_kwargs):
raise OSError('boom')
@@ -40,9 +38,7 @@ def test_load_html_from_file_os_error(monkeypatch, capsys):
result = reports.load_html_from_file('path.html')
captured = capsys.readouterr()
assert result is None
assert 'Error reading file: boom' in captured.out
def test_inject_content_replaces_section():
@@ -57,15 +53,15 @@ def test_inject_content_replaces_section():
assert section.find('span').text == 'new'
def test_inject_content_missing_section(capsys):
def test_inject_content_missing_section():
main_html = "<html><body><div id='other'>keep</div></body></html>"
result = reports.inject_content(main_html, 'missing', '<p>ignored</p>')
captured = capsys.readouterr()
assert "Section with id 'missing' not found" in captured.out
# Content should be unchanged when section is missing
soup = BeautifulSoup(result, 'html.parser')
assert soup.find(id='other') is not None
assert soup.find(id='other').text == 'keep'
def test_reports_init_sets_defaults(stub_color_options):