Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Co-authored-by: ntessore
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Apr 15, 2023
1 parent 5913546 commit d2bd722
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 65 deletions.
12 changes: 6 additions & 6 deletions src/cosmology/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
from cosmology.api._constants import CosmologyConstantsNamespace
from cosmology.api._core import Cosmology
from cosmology.api._distances import (
BackgroundTemperature,
CMBTemperature,
DistanceMeasures,
HasScaleFactor,
HasScaleFactor0,
HasTcmb,
HasTcmb0,
HasTCMB,
HasTCMB0,
ScaleFactor,
)
from cosmology.api._extras import (
Expand Down Expand Up @@ -112,9 +112,9 @@
"HasScaleFactor0",
"ScaleFactor",
# background temperature
"HasTcmb0",
"HasTcmb",
"BackgroundTemperature",
"HasTCMB0",
"HasTCMB",
"CMBTemperature",
# -- Wrappers --
"CosmologyWrapper",
"StandardCosmologyWrapper",
Expand Down
24 changes: 18 additions & 6 deletions src/cosmology/api/_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def Omega_tot(self, z: InputT_contra, /) -> ArrayT_co:


class TotalComponent(
HasOmegaTot[ArrayT_co, InputT_contra], HasOmegaTot0[ArrayT_co], Protocol
HasOmegaTot[ArrayT_co, InputT_contra],
HasOmegaTot0[ArrayT_co],
Protocol,
):
r"""The cosmology has attributes and methods for the total density."""

Expand Down Expand Up @@ -74,7 +76,9 @@ def Omega_k(self, z: InputT_contra, /) -> ArrayT_co:


class CurvatureComponent(
HasOmegaK[ArrayT_co, InputT_contra], HasOmegaK0[ArrayT_co], Protocol
HasOmegaK[ArrayT_co, InputT_contra],
HasOmegaK0[ArrayT_co],
Protocol,
):
r"""The cosmology has attributes and methods for the global curvature."""

Expand Down Expand Up @@ -115,7 +119,9 @@ def Omega_m(self, z: InputT_contra, /) -> ArrayT_co:


class MatterComponent(
HasOmegaM[ArrayT_co, InputT_contra], HasOmegaM0[ArrayT_co], Protocol
HasOmegaM[ArrayT_co, InputT_contra],
HasOmegaM0[ArrayT_co],
Protocol,
):
r"""The cosmology has attributes and methods for the matter density."""

Expand Down Expand Up @@ -151,7 +157,9 @@ def Omega_b(self, z: InputT_contra, /) -> ArrayT_co:


class BaryonComponent(
HasOmegaB[ArrayT_co, InputT_contra], HasOmegaB0[ArrayT_co], Protocol
HasOmegaB[ArrayT_co, InputT_contra],
HasOmegaB0[ArrayT_co],
Protocol,
):
r"""The cosmology has attributes and methods for the baryon density."""

Expand Down Expand Up @@ -286,7 +294,9 @@ def Omega_dm(self, z: InputT_contra, /) -> ArrayT_co:


class DarkMatterComponent(
HasOmegaDM[ArrayT_co, InputT_contra], HasOmegaDM0[ArrayT_co], Protocol
HasOmegaDM[ArrayT_co, InputT_contra],
HasOmegaDM0[ArrayT_co],
Protocol,
):
r"""The cosmology has attributes and methods for the dark matter."""

Expand Down Expand Up @@ -322,6 +332,8 @@ def Omega_gamma(self, z: InputT_contra, /) -> ArrayT_co:


class PhotonComponent(
HasOmegaGamma[ArrayT_co, InputT_contra], HasOmegaGamma0[ArrayT_co], Protocol
HasOmegaGamma[ArrayT_co, InputT_contra],
HasOmegaGamma0[ArrayT_co],
Protocol,
):
r"""The cosmology has attributes and methods for the photons."""
16 changes: 10 additions & 6 deletions src/cosmology/api/_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
__all__: list[str] = []


class HasTcmb0(Protocol[ArrayT_co]):
class HasTCMB0(Protocol[ArrayT_co]):
r"""The object contains a background temperature -- :math:`T_{CMB}`."""

@property
Expand All @@ -19,7 +19,7 @@ def T_cmb0(self) -> ArrayT_co:
...


class HasTcmb(Protocol[ArrayT_co, InputT_contra]):
class HasTCMB(Protocol[ArrayT_co, InputT_contra]):
r"""The object contains a background temperature method."""

def T_cmb(self, z: InputT_contra, /) -> ArrayT_co:
Expand All @@ -37,8 +37,10 @@ def T_cmb(self, z: InputT_contra, /) -> ArrayT_co:
...


class BackgroundTemperature(
HasTcmb[ArrayT_co, InputT_contra], HasTcmb0[ArrayT_co], Protocol
class CMBTemperature(
HasTCMB[ArrayT_co, InputT_contra],
HasTCMB0[ArrayT_co],
Protocol,
):
r"""The object has attributes and methods for the background temperature."""

Expand Down Expand Up @@ -76,7 +78,9 @@ def scale_factor(self, z: InputT_contra, /) -> ArrayT_co:


class ScaleFactor(
HasScaleFactor[ArrayT_co, InputT_contra], HasScaleFactor0[ArrayT_co], Protocol
HasScaleFactor[ArrayT_co, InputT_contra],
HasScaleFactor0[ArrayT_co],
Protocol,
):
"""The object has attributes and methods for the scale factor."""

Expand All @@ -87,7 +91,7 @@ class ScaleFactor(

class DistanceMeasures(
ScaleFactor[ArrayT_co, InputT_contra],
BackgroundTemperature[ArrayT_co, InputT_contra],
CMBTemperature[ArrayT_co, InputT_contra],
Protocol,
):
"""Cosmology API protocol for isotropic cosmologies.
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/api/components/test_photon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cosmology.api import PhotonComponent
from cosmology.api._array_api import Array

from ..conftest import _default_one, _return_1arg, _return_one
from ..conftest import _default_one, _return_1arg

################################################################################
# TESTS
Expand All @@ -31,16 +31,16 @@ class ExamplePhotonComponent:
# TODO: more examples?


def test_compliant_photoncomponent(dists_cls):
def test_compliant_photoncomponent(cosmology_cls):
"""
Test that a compliant instance is a
`cosmology.api.PhotonComponent`.
"""
ExamplePhotonComponent = make_dataclass(
"ExamplePhotonComponent",
[(n, Array, field(default_factory=_default_one)) for n in {}],
bases=(dists_cls,),
namespace={"Omega_gamma0": _return_one, "Omega_gamma": _return_1arg},
[(n, Array, field(default_factory=_default_one)) for n in {"Omega_gamma0"}],
bases=(cosmology_cls,),
namespace={"Omega_gamma": _return_1arg},
frozen=True,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/api/components/test_total.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ExampleTotalComponent:
# TODO: more examples?


def test_compliant_totalomponent(comptotal_cls):
def test_compliant_totalcomponent(comptotal_cls):
"""
Test that a compliant instance is a
`cosmology.api.TotalComponent`.
Expand Down
6 changes: 3 additions & 3 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy.array_api as xp
import pytest
from cosmology.api import (
BackgroundTemperature,
TCMB,
BaryonComponent,
Cosmology,
CosmologyConstantsNamespace,
Expand Down Expand Up @@ -229,9 +229,9 @@ def scalefactor_cls(
@pytest.fixture(scope="session")
def bkgt_cls(
cosmology_cls: type[Cosmology],
) -> type[BackgroundTemperature | Cosmology]:
) -> type[TCMB | Cosmology]:
"""An example standard cosmology API class."""
return make_cls(BackgroundTemperature, {"T_cmb0"})
return make_cls(TCMB, {"T_cmb0"})


DISTANCES_ATTRS, DISTANCES_METHS = _get_attrs_meths(DistanceMeasures, Cosmology)
Expand Down
24 changes: 6 additions & 18 deletions tests/api/distances/test_scalefactor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test ``cosmology.api.BackgroundTemperature``."""
"""Test ``cosmology.api.ScaleFactor``."""

from __future__ import annotations

Expand All @@ -15,10 +15,7 @@


def test_noncompliant_scalefactor():
"""
Test that a non-compliant instance is not a
`cosmology.api.BackgroundTemperature`.
"""
"""Test that a non-compliant instance is not a `cosmology.api.ScaleFactor`."""
# Simple example: missing everything

class ExampleScaleFactor:
Expand All @@ -32,18 +29,12 @@ class ExampleScaleFactor:


def test_compliant_scalefactor(scalefactor_cls):
"""
Test that a compliant instance is a
`cosmology.api.BackgroundTemperature`.
"""
"""Test that a compliant instance is a `cosmology.api.ScaleFactor`."""
ExampleScaleFactor = make_dataclass(
"ExampleScaleFactor",
[(n, Array, field(default_factory=_default_one)) for n in {"H0"}],
[(n, Array, field(default_factory=_default_one)) for n in {"scale_factor0"}],
bases=(scalefactor_cls,),
namespace={
"T_cmb0": _default_one,
"Tcmb": _return_1arg,
},
namespace={"scale_factor": _return_1arg},
frozen=True,
)

Expand All @@ -53,8 +44,5 @@ def test_compliant_scalefactor(scalefactor_cls):


def test_fixture(scalefactor_cls):
"""
Test that the ``scalefactor_cls`` fixture is a
`cosmology.api.ScaleFactor`.
"""
"""Test that the ``scalefactor_cls`` fixture is a `cosmology.api.ScaleFactor`."""
assert isinstance(scalefactor_cls(), ScaleFactor)
33 changes: 15 additions & 18 deletions tests/api/distances/test_tcmb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Test ``cosmology.api.BackgroundTemperature``."""
"""Test ``cosmology.api.TCMB``."""

from __future__ import annotations

from dataclasses import field, make_dataclass

from cosmology.api import BackgroundTemperature
from cosmology.api import TCMB
from cosmology.api._array_api import Array

from ..conftest import _default_one, _return_1arg
Expand All @@ -17,44 +17,41 @@
def test_noncompliant_hastcmbs():
"""
Test that a non-compliant instance is not a
`cosmology.api.BackgroundTemperature`.
`cosmology.api.TCMB`.
"""
# Simple example: missing everything

class ExampleBackgroundTemperature:
class ExampleTCMB:
pass

cosmo = ExampleBackgroundTemperature()
cosmo = ExampleTCMB()

assert not isinstance(cosmo, BackgroundTemperature)
assert not isinstance(cosmo, TCMB)

# TODO: more examples?


def test_compliant_hastcmbs(bkgt_cls):
"""
Test that a compliant instance is a
`cosmology.api.BackgroundTemperature`.
`cosmology.api.TCMB`.
"""
ExampleBackgroundTemperature = make_dataclass(
"ExampleBackgroundTemperature",
[(n, Array, field(default_factory=_default_one)) for n in {"H0"}],
ExampleTCMB = make_dataclass(
"ExampleTCMB",
[(n, Array, field(default_factory=_default_one)) for n in {"T_cmb0"}],
bases=(bkgt_cls,),
namespace={
"T_cmb0": _default_one,
"Tcmb": _return_1arg,
},
namespace={"T_cmb": _return_1arg},
frozen=True,
)

cosmo = ExampleBackgroundTemperature()
cosmo = ExampleTCMB()

assert isinstance(cosmo, BackgroundTemperature)
assert isinstance(cosmo, TCMB)


def test_fixture(bkgt_cls):
"""
Test that the ``bkgt_cls`` fixture is a
`cosmology.api.BackgroundTemperature`.
`cosmology.api.TCMB`.
"""
assert isinstance(bkgt_cls(), BackgroundTemperature)
assert isinstance(bkgt_cls(), TCMB)
4 changes: 2 additions & 2 deletions tests/api/extras/test_hubble.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
################################################################################


def test_noncompliant_hubbleparametrized():
def test_noncompliant_hubbleparameter():
"""
Test that a non-compliant instance is not a
`cosmology.api.HubbleParameter`.
Expand All @@ -31,7 +31,7 @@ class ExampleHubbleParameter:
# TODO: more examples?


def test_compliant_hubbleparametrized(hubble_cls):
def test_compliant_hubbleparameter(hubble_cls):
"""
Test that a compliant instance is a
`cosmology.api.HubbleParameter`.
Expand Down

0 comments on commit d2bd722

Please sign in to comment.