Testing
The automated tests live in the repository’s tests/ directory and are not
included in the installed wheel. Clone the source repository before running
them.
Fresh setup with venv
Create a source checkout and isolated Python environment:
git clone https://github.com/ChunHuangPhy/CompactObject.git
cd CompactObject
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[test]"
On Windows, activate the environment with .venv\Scripts\activate.
Run the complete suite from the repository root:
python -m pytest
The test extra installs pytest, pytest-cov, and Dynesty in addition to the
package’s runtime dependencies.
Conda setup
The supplied Conda environment already includes pytest:
git clone https://github.com/ChunHuangPhy/CompactObject.git
cd CompactObject
conda env create --file environment.yml
conda activate CompactObject
python -m pip install --no-deps --no-build-isolation -e .
python -m pytest
Running selected tests
Pass a file path to run one test module:
python -m pytest tests/test_ddh_char23.py
Pass a pytest node ID to run one test:
python -m pytest tests/test_ddh_char23.py::DDHChar23Tests::test_builtin_char23_matches_user_defined_form
Use -vv for more detailed output:
python -m pytest -vv
Troubleshooting the test extra
If pip reports that compactobject-tov 2.1 does not provide the extra
'test', the environment or source checkout is still using the older 2.1
metadata. Update the source checkout and reinstall it:
git switch main
git pull --ff-only
python -m pip install -e ".[test]"
Pytest can also be installed explicitly while working from a source checkout:
python -m pip install -e .
python -m pip install pytest
python -m pytest
Confirm which CompactObject release is installed with:
python -c "from importlib.metadata import version; print(version('CompactObject-TOV'))"
Continuous integration
The pytest configuration is stored in pyproject.toml. Runtime warnings are
treated as failures so numerical domain errors cannot pass unnoticed. GitHub
Actions runs the complete suite automatically for pushes and pull requests.
Coverage and functional reference checks
Run coverage from the same source checkout as the tests:
python -m pip install -e ".[test]"
python -m pytest --cov --cov-report=term-missing --cov-report=html --cov-report=xml
Open htmlcov/index.html for per-line results. CI runs the suite on Python
3.11 and 3.14 and uploads the HTML and XML reports as versioned artifacts.
Coverage includes all Python modules under EOSgenerators,
InferenceWorkflow, TOVsolver, and postprocessing. Tests and notebook
copies are excluded by this source selection.
With that same source selection on Python 3.11, overall line coverage rose
from 41% at d859db2 to 66% with the additional reference tests.
This includes modules that have no tests yet. The representative modules
identified during review improved as follows:
Module |
Before |
After |
|---|---|---|
|
92% |
99% |
|
15% |
100% |
|
29% |
97% |
|
28% |
58% |
|
44% |
100% |
|
45% |
100% |
|
3% |
97% |
|
10% |
93% |
The tests include:
The analytic Schwarzschild uniform-density solution and an independently integrated polytropic TOV solution, checking mass, radius, and unit conversions.
Boundary and interior maximum-mass searches against known mass curves, and a comparison against a real integrated stellar sequence.
RMF thermodynamic identities in beta equilibrium and fixed-composition matter; MIT-bag and strangeon surface and pressure relations, and monotone pressure integration for the speed-of-sound EOS.
Analytic Gaussian and kernel likelihoods, consistent tidal mass units, invalid EOS rejection, and finite likelihood tails for empty or poor-fitting samples.
DDH nuclear derivatives against analytic symmetric and pure-neutron energy curves, plus calculations with a real DDH parameter set.
pQCD derivative and zero-temperature thermodynamic identities, evaluated with both compiled and Python functions, and deterministic causal-constraint weights.
Real UltraNest sampling and resume, and Dynesty sampling in serial and with a pool, for a known one-parameter Gaussian posterior. These use small fixed budgets; production analyses require their own convergence checks.
The regression checks identified and corrected RMF rows evaluated at the previous density, a redundant symmetric-matter field in the nonlinear solve, nonmonotone speed-of-sound pressure quadrature, maximum-mass boundary and radius mismatches, missing pQCD scale arguments, mixed tidal mass units, and unstable log-likelihood tails. These fixes change the affected numerical outputs. Nonphysical DDH prior draws are rejected without aborting sampling. The primary TOV integrator also uses centimeters internally to avoid early termination caused by extreme natural-unit scales on newer SciPy builds; its public inputs and outputs keep the same unit convention.
Python line tracing leaves many Numba-compiled statements unmarked even when compiled functions run. FastRMF is checked through EOS comparisons and thermodynamic tests. Remaining coverage gaps include the legacy K/J/L estimators, some EOS families, and plotting utilities. The comparisons above validate the listed cases; they are not an exhaustive validation of every model and prior.
Polytrope tutorial checks
test_Inference_polytrope.ipynb separates the inexpensive EOS unit check
from stellar integrations and full inference. Its default unit check draws
three EOS curves without calling the TOV solver. The optional mass-radius
survey is enabled with RUN_MASS_RADIUS_CHECK=True and prints progress for
each curve.
The default UltraNest interface check uses eight live points and a coarse
six-point central-density grid over log10 density 14.6–15.6 with a small
call/iteration budget. This restricted demonstration prior checks execution
only; its output is not a converged posterior or evidence estimate.
The full inference is enabled separately with RUN_FULL_INFERENCE=True and
uses the 50-point density grid over log10 density 14.3–15.6. Individual TOV integrations can remain slow,
so a call budget is not a wall-clock timeout.
The documentation workflow executes the default notebook checks with
jupyter nbconvert and excludes cells tagged long-running. Regression
tests exercise the canonical tutorial notebook, checking
EOS units, the density grid used by the prior, empty stellar sequences, and
the absence of TOV calls in the default unit check:
python -m pytest tests/test_polytrope_notebook.py
Notebook sources and documentation
Edit tutorial notebooks in Test_Case/ and the emcee examples in
Emcee_Workflow/. Each notebook has one maintained source file. The
.nblink files in docs/source/ point to those originals using
nbsphinx-link; do not add notebook copies to the documentation directory.
The existing tutorial page names are retained.
The documentation build renders the notebooks without executing them. CI executes the lightweight example checks separately, so publishing documentation does not launch production sampling or timing benchmarks.
Check all notebook links and build the documentation from the repository root:
python -m pip install -e ".[docs,notebooks,test]"
python -m pytest tests/test_notebook_documentation.py
sphinx-build -W docs/source _build