Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Apr 11, 2023
1 parent 35cc7eb commit 7e7d0e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/cosmology/api/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ class Cosmology(Protocol[ArrayT_co, InputT_contra]): # type: ignore[misc]
"""Cosmology API Protocol."""

def __cosmology_namespace__(
self, /, *, api_version: str | None = None
self, *, api_version: str | None = None
) -> CosmologyNamespace:
"""Returns an object that has all the cosmology API functions on it.
Parameters
----------
api_version: Optional[str]
api_version: str | None, keyword-only
string representing the version of the cosmology API specification
to be returned, in ``'YYYY.MM'`` form, for example, ``'2020.10'``.
If it is ``None``, it should return the namespace corresponding to
latest version of the cosmology API specification. If the given
version is invalid or not implemented for the given module, an error
should be raised. Default: ``None``.
should be raised. Default: `None`.
Returns
-------
Expand All @@ -57,19 +57,19 @@ def name(self) -> str | None:
# Convenience methods

def constants(
self, /, *, api_version: str | None = None
self, *, api_version: str | None = None
) -> CosmologyConstantsNamespace:
"""Returns an object that has all the cosmology API functions on it.
Parameters
----------
api_version: Optional[str]
api_version: str | None, keyword-only
string representing the version of the cosmology API specification
to be returned, in ``'YYYY.MM'`` form, for example, ``'2020.10'``.
If it is ``None``, it should return the namespace corresponding to
latest version of the cosmology API specification. If the given
version is invalid or not implemented for the given module, an error
should be raised. Default: ``None``.
should be raised. Default: `None`.
Returns
-------
Expand Down
9 changes: 7 additions & 2 deletions tests/api/compat/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
from cosmology.api import (
Cosmology,
CosmologyConstantsNamespace,
CosmologyNamespace,
CosmologyWrapper,
StandardCosmology,
Expand Down Expand Up @@ -40,7 +41,7 @@ class ExampleStandardCosmologyWrapper:
# TODO: more examples?


def test_compliant_bkg_wrapper(cosmology_ns, standard_attrs, standard_meths):
def test_compliant_standard_wrapper(cosmology_ns, standard_attrs, standard_meths):
"""
Test that a compliant instance is a
`cosmology.api.CosmologyWrapper`. In particular, this tests
Expand All @@ -55,7 +56,6 @@ def _return_1arg(self, z: Array, /) -> Array:

def _cosmology_namespace_(
self,
/,
*,
api_version: str | None = None,
) -> CosmologyNamespace:
Expand All @@ -67,6 +67,11 @@ def name(self) -> str | None:
def _getattr_(self, name: str) -> object:
return getattr(self.cosmo, name)

def constants(
self, *, api_version: str | None = None
) -> CosmologyConstantsNamespace:
return cosmology_ns.constants

ExampleStandardCosmologyWrapper = make_dataclass(
"ExampleStandardCosmologyWrapper",
[("cosmo", object)],
Expand Down
3 changes: 1 addition & 2 deletions tests/api/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ class Cosmology:

def __cosmology_namespace__(
self,
/,
*,
api_version: str | None = None,
) -> CosmologyNamespace:
return cosmology_ns

def constants(self, /, *, api_version: str | None = None):
def constants(self, *, api_version: str | None = None):
return self.__cosmology_namespace__(api_version=api_version).constants

cosmo = Cosmology()
Expand Down

0 comments on commit 7e7d0e5

Please sign in to comment.