From 687e05cbe2fd212ec8ef8efcb824097e37f2b6ab Mon Sep 17 00:00:00 2001 From: Evgeniy Unzhakov Date: Tue, 29 Sep 2026 13:06:22 +0300 Subject: [PATCH] style: reformat assertion blocks in test files --- tests/common/test_property_tests.py | 35 ++++++++++----------- tests/integration/test_spectrum_pipeline.py | 7 +++-- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/tests/common/test_property_tests.py b/tests/common/test_property_tests.py index 9731f0f..91b1af7 100644 --- a/tests/common/test_property_tests.py +++ b/tests/common/test_property_tests.py @@ -82,9 +82,9 @@ def _test_positive_values(component, W, component_name="Component"): f"W range: [{W_arr.min():.3f}, {W_arr.max():.3f}], " f"result range: [{np.nanmin(result):.6f}, {np.nanmax(result):.6f}]" ) - assert not np.any( - np.isinf(result) - ), f"{component_name}: Inf values found in output." + assert not np.any(np.isinf(result)), ( + f"{component_name}: Inf values found in output." + ) assert np.all(result > 0), ( f"{component_name}: non-positive values found. " f"Min = {np.min(result):.10f} at W = {W_arr[np.argmin(result)][0]:.4f}" @@ -108,21 +108,20 @@ def _test_non_negative_values( W_arr = np.asarray(W, dtype=float) result = component(W_arr) - assert not np.any( - np.isnan(result) - ), f"{component_name}: NaN values found in output." - assert not np.any( - np.isinf(result) - ), f"{component_name}: Inf values found in output." + assert not np.any(np.isnan(result)), ( + f"{component_name}: NaN values found in output." + ) + assert not np.any(np.isinf(result)), ( + f"{component_name}: Inf values found in output." + ) if allow_zero: assert np.all(result >= 0), ( - f"{component_name}: negative values found. " f"Min = {np.min(result):.10f}" + f"{component_name}: negative values found. Min = {np.min(result):.10f}" ) else: assert np.all(result > 0), ( - f"{component_name}: non-positive values found. " - f"Min = {np.min(result):.10f}" + f"{component_name}: non-positive values found. Min = {np.min(result):.10f}" ) @@ -137,12 +136,11 @@ def _test_output_shape_preserved(component, W, component_name="Component"): W_arr = np.asarray(W, dtype=float) result = component(W_arr) - assert isinstance( - result, np.ndarray - ), f"{component_name}: output is {type(result)}, expected np.ndarray" + assert isinstance(result, np.ndarray), ( + f"{component_name}: output is {type(result)}, expected np.ndarray" + ) assert result.shape == W_arr.shape, ( - f"{component_name}: shape mismatch. " - f"Input {W_arr.shape} → Output {result.shape}" + f"{component_name}: shape mismatch. Input {W_arr.shape} → Output {result.shape}" ) @@ -217,8 +215,7 @@ def _test_output_is_ndarray(component, W, component_name="Component"): result = component(W_arr) assert isinstance(result, np.ndarray), ( - f"{component_name}: output type is {type(result).__name__}, " - f"expected np.ndarray" + f"{component_name}: output type is {type(result).__name__}, expected np.ndarray" ) diff --git a/tests/integration/test_spectrum_pipeline.py b/tests/integration/test_spectrum_pipeline.py index 47c6690..0a30152 100644 --- a/tests/integration/test_spectrum_pipeline.py +++ b/tests/integration/test_spectrum_pipeline.py @@ -179,6 +179,7 @@ class TestDeclarativeDetectorResponse: detector = BetaSpectrum.create_detector_from_config(config) from beta_spectrum.components.detector_response import DetectorResponse + assert isinstance(detector, DetectorResponse) assert detector.n_channels == 512 assert detector._mode == "analytical" @@ -278,9 +279,9 @@ class TestDeclarativeDetectorResponse: assert convolved.shape == (256,) # Normalized spectrum should integrate to ~1 over channel energies integral = np.trapezoid(convolved, detector.channel_energies) - assert np.isclose( - integral, 1.0, rtol=0.05 - ), f"Integral should be ~1.0, got {integral}" + assert np.isclose(integral, 1.0, rtol=0.05), ( + f"Integral should be ~1.0, got {integral}" + ) @pytest.mark.skip(reason="DetectorResponse not yet implemented") def test_detector_range_extends_to_endpoint(self):