From c9a738baaba22913dc2fd2d87cd23a28c0a86d62 Mon Sep 17 00:00:00 2001 From: Evgeniy Unzhakov Date: Fri, 1 May 2026 19:15:23 +0300 Subject: [PATCH] chore(gitignore): remove notebooks and ipynb from gitignore style: fix black formatting in test files (unused imports, assert reformatting) --- .gitignore | 2 -- tests/test_exchange.py | 20 ++++++++++---------- tests/test_fermi.py | 23 ++++++++++++----------- tests/test_finite_size.py | 31 +++++++++++++++---------------- tests/test_phase_space.py | 13 ++++++------- tests/test_screening.py | 19 +++++++++---------- 6 files changed, 52 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index 36762e1..ed10be3 100644 --- a/.gitignore +++ b/.gitignore @@ -64,8 +64,6 @@ venv.bak/ # ========================= .ipynb_checkpoints/ -*.ipynb -notebooks/ # IPython diff --git a/tests/test_exchange.py b/tests/test_exchange.py index 6b344f5..21e9661 100644 --- a/tests/test_exchange.py +++ b/tests/test_exchange.py @@ -45,23 +45,23 @@ class TestExchangeLowEnergy: low_W = np.array([1.1]) # T ≈ 50 keV — still "low" but above cutoff result = ex(low_W) - assert result[0] > 1.0, ( - f"Exchange must enhance spectrum at low energy for heavy Z: got {result[0]}" - ) + assert ( + result[0] > 1.0 + ), f"Exchange must enhance spectrum at low energy for heavy Z: got {result[0]}" def test_correction_grows_as_energy_decreases(self): """X(W) should increase as W → 1 (lower momentum → stronger exchange).""" ex = ExchangeCorrection(Z=50) # Tin — moderate-heavy - low_W = np.array([1.2]) # Higher energy + low_W = np.array([1.2]) # Higher energy lower_W = np.array([1.05]) # Lower energy (above cutoff W_cut=1.005) s_low = ex(low_W)[0] s_lower = ex(lower_W)[0] - assert s_lower > s_low, ( - f"Exchange must increase at lower energy: {s_low} → {s_lower}" - ) + assert ( + s_lower > s_low + ), f"Exchange must increase at lower energy: {s_low} → {s_lower}" class TestExchangeHighEnergy: @@ -74,9 +74,9 @@ class TestExchangeHighEnergy: high_W = np.array([3.0, 5.0]) result = ex(high_W) - assert abs(result[0] - 1.0) < 0.5, ( - f"Exchange must approach unity at high energy: got {result}" - ) + assert ( + abs(result[0] - 1.0) < 0.5 + ), f"Exchange must approach unity at high energy: got {result}" class TestExchangeNumericalStability: diff --git a/tests/test_fermi.py b/tests/test_fermi.py index 38a62c0..acb0223 100644 --- a/tests/test_fermi.py +++ b/tests/test_fermi.py @@ -25,7 +25,6 @@ Common practice: When testing a function with special mathematical functions """ import numpy as np -import pytest from beta_spectrum.components.fermi import FermiFunction @@ -45,9 +44,9 @@ class TestFermiZeros: result = ff(W_test) # For Z=1, the correction from finite nuclear size and Coulomb terms gives ~3% deviation - assert np.all(np.abs(result - 1.0) < 0.05), ( - f"Z=1 Fermi function should be ≈1 but got {result}" - ) + assert np.all( + np.abs(result - 1.0) < 0.05 + ), f"Z=1 Fermi function should be ≈1 but got {result}" class TestFermiPhysicalBehavior: @@ -64,7 +63,9 @@ class TestFermiPhysicalBehavior: # Check monotonic decrease (each successive point should be smaller) diffs = np.diff(result) - assert np.all(diffs < 0), f"Fermi function must decrease with W; got diffs {diffs}" + assert np.all( + diffs < 0 + ), f"Fermi function must decrease with W; got diffs {diffs}" def test_increases_with_Z(self): """Higher Z → stronger Coulomb attraction → larger F₀ at low energy. @@ -82,9 +83,9 @@ class TestFermiPhysicalBehavior: f_30 = ff_z30(W_test)[0] f_80 = ff_z80(W_test)[0] - assert f_80 > f_30 > f_10, ( - f"Fermi function must increase with Z: {f_10} < {f_30} < {f_80}" - ) + assert ( + f_80 > f_30 > f_10 + ), f"Fermi function must increase with Z: {f_10} < {f_30} < {f_80}" def test_positive_values(self): """F₀ must be positive everywhere — it's a probability enhancement factor.""" @@ -126,6 +127,6 @@ class TestFermiOutputShape: for n_points in [1, 5, 100]: W_test = np.linspace(1.1, 3.0, n_points) result = ff(W_test) - assert result.shape == W_test.shape, ( - f"Shape mismatch: input {W_test.shape} → output {result.shape}" - ) + assert ( + result.shape == W_test.shape + ), f"Shape mismatch: input {W_test.shape} → output {result.shape}" diff --git a/tests/test_finite_size.py b/tests/test_finite_size.py index c3dba38..bc53850 100644 --- a/tests/test_finite_size.py +++ b/tests/test_finite_size.py @@ -23,7 +23,6 @@ This catches sign errors and magnitude bugs early. """ import numpy as np -import pytest from beta_spectrum.components.finite_size import FiniteSizeL0, ChargeDistributionU @@ -41,9 +40,9 @@ class TestFiniteSizeL0: W_test = np.array([2.0]) # Mid-range energy result = fs(W_test) - assert abs(result[0] - 1.0) < 0.05, ( - f"L₀ for Z=6 should be near unity but got {result[0]}" - ) + assert ( + abs(result[0] - 1.0) < 0.05 + ), f"L₀ for Z=6 should be near unity but got {result[0]}" def test_correction_increases_with_Z(self): """Higher Z → larger αZ term in L₀ expansion → larger deviation from 1.""" @@ -57,9 +56,9 @@ class TestFiniteSizeL0: dev_30 = abs(fs_z30(W_test)[0] - 1.0) dev_80 = abs(fs_z80(W_test)[0] - 1.0) - assert dev_80 > dev_30 > dev_6, ( - f"Deviation from unity must increase with Z: {dev_6}, {dev_30}, {dev_80}" - ) + assert ( + dev_80 > dev_30 > dev_6 + ), f"Deviation from unity must increase with Z: {dev_6}, {dev_30}, {dev_80}" def test_positive_everywhere(self): """L₀ should be positive — it's a correction factor multiplicative to the spectrum.""" @@ -78,9 +77,9 @@ class TestChargeDistributionU: u = ChargeDistributionU(Z=6, A=12) result = u(np.array([2.0])) - assert abs(result[0] - 1.0) < 0.01, ( - f"U for Z=6 should be near unity but got {result[0]}" - ) + assert ( + abs(result[0] - 1.0) < 0.01 + ), f"U for Z=6 should be near unity but got {result[0]}" def test_always_positive_correction(self): """U = 1 + (1/5)(αZW R)² is always > 1 since the squared term is positive.""" @@ -97,9 +96,9 @@ class TestChargeDistributionU: W_test = np.array([3.0]) - assert u_z60(W_test)[0] > u_z20(W_test)[0], ( - f"U must increase with Z: {u_z20(W_test)} < {u_z60(W_test)}" - ) + assert ( + u_z60(W_test)[0] > u_z20(W_test)[0] + ), f"U must increase with Z: {u_z20(W_test)} < {u_z60(W_test)}" class TestFiniteSizeCombined: @@ -113,9 +112,9 @@ class TestFiniteSizeCombined: W_test = np.linspace(1.5, 4.0, 10) combined = l0(W_test) * u(W_test) - assert np.all(np.abs(combined - 1.0) < 0.05), ( - f"Combined finite-size for carbon should be near unity: {combined}" - ) + assert np.all( + np.abs(combined - 1.0) < 0.05 + ), f"Combined finite-size for carbon should be near unity: {combined}" def test_combined_positive(self): """Product of two positive factors must be positive.""" diff --git a/tests/test_phase_space.py b/tests/test_phase_space.py index ef08efc..7178469 100644 --- a/tests/test_phase_space.py +++ b/tests/test_phase_space.py @@ -18,7 +18,6 @@ large arrays only when testing numerical stability or performance. """ import numpy as np -import pytest from beta_spectrum.components.phase_space import PhaseSpace @@ -82,9 +81,9 @@ class TestPhaseSpaceNeutrinoMass: val_massive = ps_massive(W_near_endpoint)[0] assert not np.isnan(val_massive), "Should produce finite value" - assert val_massive < val_zero, ( - "Massive neutrino must suppress spectrum near endpoint" - ) + assert ( + val_massive < val_zero + ), "Massive neutrino must suppress spectrum near endpoint" def test_massive_neutrino_gives_nan_below_threshold(self): """With m_nu > 0, below the effective threshold (W₀−W < m_nu), sqrt gives NaN. @@ -102,9 +101,9 @@ class TestPhaseSpaceNeutrinoMass: W_deep_below = np.array([4.95]) # W₀ − W = 0.05 < m_nu=0.1 — below threshold result_below = ps(W_deep_below) - assert np.isnan(result_below[0]), ( - "Below kinematic threshold, spectrum should be NaN" - ) + assert np.isnan( + result_below[0] + ), "Below kinematic threshold, spectrum should be NaN" class TestPhaseSpaceArrayType: diff --git a/tests/test_screening.py b/tests/test_screening.py index 489b5f0..783c11a 100644 --- a/tests/test_screening.py +++ b/tests/test_screening.py @@ -24,7 +24,6 @@ Common practice: For components with "switching" logic, always test both the on- """ import numpy as np -import pytest from beta_spectrum.components.fermi import FermiFunction from beta_spectrum.components.screening import ScreeningCorrection @@ -44,9 +43,9 @@ class TestScreeningBasicProperties: high_W = np.array([3.0, 5.0]) result = sc(high_W) - assert abs(result[0] - 1.0) < 0.1, ( - f"Screening must approach unity at high energy: got {result}" - ) + assert ( + abs(result[0] - 1.0) < 0.1 + ), f"Screening must approach unity at high energy: got {result}" def test_positive_values(self): """S(W) must be positive everywhere — it multiplies the spectrum.""" @@ -80,9 +79,9 @@ class TestScreeningEnergyDependence: # At low energy, correction is active and reduces the spectrum assert s_low < 1.1, f"Low-energy screening should suppress: {s_low}" # At mid energy, it's closer to unity - assert abs(s_mid - 1.0) < abs(s_low - 1.0), ( - "Correction must decrease toward unity as W increases" - ) + assert abs(s_mid - 1.0) < abs( + s_low - 1.0 + ), "Correction must decrease toward unity as W increases" class TestScreeningParameters: @@ -99,9 +98,9 @@ class TestScreeningParameters: result_custom = sc_custom(low_W)[0] # Different V₀ should give different results at low energy - assert abs(result_default - result_custom) > 0, ( - "Custom V₀ must change the screening behavior" - ) + assert ( + abs(result_default - result_custom) > 0 + ), "Custom V₀ must change the screening behavior" class TestScreeningOutputShape: