Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-450: move all pytest.fixture into conftest.py #451

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
import numpy as np
import numpy.typing as npt
import pytest

from cosmology import Cosmology

from glass import RadialWindow


@pytest.fixture(scope="session")
def cosmo() -> Cosmology:
class MockCosmology:
@property
def omega_m(self) -> float:
return 0.3

def ef(self, z: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
return (self.omega_m * (1 + z) ** 3 + 1 - self.omega_m) ** 0.5

def xm(
self,
z: npt.NDArray[np.float64],
z2: npt.NDArray[np.float64] | None = None,
) -> npt.NDArray[np.float64]:
if z2 is None:
return np.array(z) * 1000
return (np.array(z2) - np.array(z)) * 1000

return MockCosmology()


@pytest.fixture(scope="session")
def rng() -> np.random.Generator:
return np.random.default_rng(seed=42)


@pytest.fixture(scope="session")
def shells() -> list[RadialWindow]:
return [
RadialWindow(np.array([0.0, 1.0, 2.0]), np.array([0.0, 1.0, 0.0]), 1.0),
RadialWindow(np.array([1.0, 2.0, 3.0]), np.array([0.0, 1.0, 0.0]), 2.0),
RadialWindow(np.array([2.0, 3.0, 4.0]), np.array([0.0, 1.0, 0.0]), 3.0),
RadialWindow(np.array([3.0, 4.0, 5.0]), np.array([0.0, 1.0, 0.0]), 4.0),
RadialWindow(np.array([4.0, 5.0, 6.0]), np.array([0.0, 1.0, 0.0]), 5.0),
]
34 changes: 0 additions & 34 deletions tests/test_lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import healpix
import numpy as np
import numpy.typing as npt
import pytest

from glass import (
Expand All @@ -19,39 +18,6 @@
from cosmology import Cosmology


@pytest.fixture
def shells() -> list[RadialWindow]:
return [
RadialWindow(np.array([0.0, 1.0, 2.0]), np.array([0.0, 1.0, 0.0]), 1.0),
RadialWindow(np.array([1.0, 2.0, 3.0]), np.array([0.0, 1.0, 0.0]), 2.0),
RadialWindow(np.array([2.0, 3.0, 4.0]), np.array([0.0, 1.0, 0.0]), 3.0),
RadialWindow(np.array([3.0, 4.0, 5.0]), np.array([0.0, 1.0, 0.0]), 4.0),
RadialWindow(np.array([4.0, 5.0, 6.0]), np.array([0.0, 1.0, 0.0]), 5.0),
]


@pytest.fixture
def cosmo() -> Cosmology:
class MockCosmology:
@property
def omega_m(self) -> float:
return 0.3

def ef(self, z: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
return (self.omega_m * (1 + z) ** 3 + 1 - self.omega_m) ** 0.5

def xm(
self,
z: npt.NDArray[np.float64],
z2: npt.NDArray[np.float64] | None = None,
) -> npt.NDArray[np.float64]:
if z2 is None:
return np.array(z) * 1000
return (np.array(z2) - np.array(z)) * 1000

return MockCosmology()


@pytest.mark.parametrize("usecomplex", [True, False])
def test_deflect_nsew(usecomplex: bool) -> None: # noqa: FBT001
d = 5.0
Expand Down