Skip to content

Refactor mass profile unit tests to be more granular#305

Merged
Jammy2211 merged 1 commit intomainfrom
feature/refactor-mass-tests
Mar 23, 2026
Merged

Refactor mass profile unit tests to be more granular#305
Jammy2211 merged 1 commit intomainfrom
feature/refactor-mass-tests

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

  • Split multi-scenario test functions into individual focused tests, each testing one specific configuration or parameter combination
  • Renamed test functions to include descriptive suffixes (e.g., __config_1, __sph, __elliptical, __ell_vs_sph, __kappa_s_2)
  • Covers all mass profile test files: total, stellar, dark, point, sheets, abstract, operate/deflections
  • No test logic, assertions, or values were changed — purely structural refactoring

Test plan

  • All existing tests pass without modification to test values
  • Each test function tests exactly one scenario
  • Test names are descriptive enough to identify what is being tested without reading the body

🤖 Generated with Claude Code

Split multi-scenario test functions into individual focused tests, each
testing one specific configuration. Renamed test functions to be more
descriptive. No test logic or values were changed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the mass-profile unit test suite to make scenarios more granular by splitting multi-scenario tests into smaller, descriptively named test functions across total/stellar/dark/point/sheets/abstract and operate/deflections tests.

Changes:

  • Split combined test functions into multiple focused tests per configuration / parameter combination.
  • Renamed tests with descriptive suffixes (e.g. __config_1, __sph, __elliptical, __elliptical_vs_spherical).
  • Expanded certain multi-point assertions into separate tests for different grids / parameter values.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test_autogalaxy/profiles/mass/total/test_power_law_multipole.py Splits deflection/convergence tests into two config-specific tests.
test_autogalaxy/profiles/mass/total/test_power_law_cored.py Splits spherical/elliptical and comparison scenarios into separate tests with descriptive names.
test_autogalaxy/profiles/mass/total/test_power_law_broken.py Breaks deflection/convergence and comparison-to-power-law scenarios into multiple config-specific tests.
test_autogalaxy/profiles/mass/total/test_power_law.py Splits deflections/convergence/potential scenarios by slope/config and adds clearer test names.
test_autogalaxy/profiles/mass/total/test_isothermal_cored.py Splits deflections/convergence/potential scenarios by spherical/elliptical/config.
test_autogalaxy/profiles/mass/total/test_isothermal.py Splits deflections/convergence/potential/shear scenarios into granular tests.
test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_potential.py Splits dPIE potential tests by spherical configs and elliptical/comparison scenarios.
test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_mass.py Splits dPIE mass tests by spherical configs and elliptical/comparison scenarios.
test_autogalaxy/profiles/mass/test_scaling_relations.py Splits scaling-relation tests by parameter combinations and profile types.
test_autogalaxy/profiles/mass/stellar/test_sersic_gradient.py Splits SersicGradient tests by gradient/config and comparison scenarios.
test_autogalaxy/profiles/mass/stellar/test_sersic_core.py Splits SersicCore convergence tests by mass-to-light ratio and adds comparison test naming.
test_autogalaxy/profiles/mass/stellar/test_sersic.py Splits Sersic tests into config-specific deflections/convergence and comparison cases.
test_autogalaxy/profiles/mass/stellar/test_gaussian_gradient.py Splits constructor-scaling tests by gradient value.
test_autogalaxy/profiles/mass/stellar/test_gaussian.py Splits Gaussian analytic/integral deflection tests by sign/config and adds more granular image/wofz tests.
test_autogalaxy/profiles/mass/stellar/test_exponential.py Splits Exponential tests by spherical/elliptical/config and parameter scaling scenarios.
test_autogalaxy/profiles/mass/stellar/test_dev_vaucouleurs.py Splits DevVaucouleurs tests by spherical/elliptical/config and parameter scaling scenarios.
test_autogalaxy/profiles/mass/stellar/test_chameleon.py Splits Chameleon tests by spherical/elliptical/config and adds clearer names.
test_autogalaxy/profiles/mass/sheets/test_mass_sheet.py Splits MassSheet tests by kappa value, geometry, and grid multiplicity.
test_autogalaxy/profiles/mass/sheets/test_external_shear.py Splits ExternalShear tests by gamma components and grid multiplicity.
test_autogalaxy/profiles/mass/point/test_smbh_binary.py Splits SMBHBinary init tests by angle/centre/mass-ratio cases.
test_autogalaxy/profiles/mass/point/test_point.py Splits PointMass deflection tests by einstein radius, grid position, and offset centre.
test_autogalaxy/profiles/mass/dark/test_nfw_truncated_mcr_scatter.py Splits NFW truncated scatter tests by scatter sign.
test_autogalaxy/profiles/mass/dark/test_nfw_truncated.py Splits NFWTruncated tests by axis/diagonal cases and parameter variations; trims commented block.
test_autogalaxy/profiles/mass/dark/test_nfw_scatter.py Splits NFW scatter tests by sph/ell and scatter sign; clarifies sph vs ell deflection comparison.
test_autogalaxy/profiles/mass/dark/test_nfw_mcr.py Splits cored-NFW MCR tests into spherical vs elliptical variants.
test_autogalaxy/profiles/mass/dark/test_nfw.py Splits NFW tests by configs and by analytic-vs-cse / precision scenarios; adds more granular convergence/shear tests.
test_autogalaxy/profiles/mass/dark/test_gnfw.py Splits gNFW tests by sph/ell configs and comparison cases.
test_autogalaxy/profiles/mass/dark/test_abstract.py Splits coord function tests by r-regime and expands parameterized coverage for helper methods.
test_autogalaxy/profiles/mass/abstract/test_mge.py Splits MGE tests by profile/config/intensity/mass-to-light variations and adds sigma-list setup in more cases.
test_autogalaxy/profiles/mass/abstract/test_abstract.py Splits abstract mass-profile tests into more focused scenarios (potential-deflection, mass within radius, regressions).
test_autogalaxy/operate/test_deflections.py Splits lensing-operate tests (hessian/critical curves/caustics/einstein radius) into targeted scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +90
def test__convergence_2d_from__isothermal_core_sph_config_2():
mp = ag.mp.IsothermalCoreSph(centre=(1, 1), einstein_radius=1.0, core_radius=0.1)

convergence = mp.convergence_func(grid_radius=1.0)

assert convergence == pytest.approx(0.49752, 1e-4)


Comment on lines 154 to 156
ell_deflections_yx_2d == pytest.approx(sph_deflections_yx_2d.array, 1.0e-4)



coord_f = mp.coord_func_f(grid_radius=np.array([0.5, 1.0 / 3.0]))

assert coord_f == pytest.approx(1.52069, 1.86967, 1.0e-4)
Comment on lines +123 to +130
def test__convergence_2d_from__power_law_sph_config_3():
mp = ag.mp.PowerLawSph(centre=(0.0, 0.0), einstein_radius=2.0, slope=2.2)

convergence = mp.convergence_2d_from(grid=ag.Grid2DIrregular([[2.0, 0.0]]))

assert convergence == pytest.approx(0.4, 1e-3)


Comment on lines +26 to 41
def test__deflections_yx_2d_from__isothermal_ell_config_1():
mp = ag.mp.Isothermal(centre=(0, 0), ell_comps=(0.0, 0.333333), einstein_radius=1.0)

deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]]))

assert deflections[0, 0] == pytest.approx(0.79421, 1e-3)
assert deflections[0, 1] == pytest.approx(0.50734, 1e-3)


def test__deflections_yx_2d_from__isothermal_ell_config_2():
mp = ag.mp.Isothermal(centre=(0, 0), ell_comps=(0.0, 0.333333), einstein_radius=1.0)

deflections = mp.deflections_yx_2d_from(grid=ag.Grid2DIrregular([[0.1625, 0.1625]]))

assert deflections[0, 0] == pytest.approx(0.79421, 1e-3)
assert deflections[0, 1] == pytest.approx(0.50734, 1e-3)
@Jammy2211 Jammy2211 merged commit 9083c79 into main Mar 23, 2026
12 checks passed
@Jammy2211 Jammy2211 deleted the feature/refactor-mass-tests branch April 2, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants