Skip to content

Commit

Permalink
Add tests to get back to 99% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MetinSa committed Apr 28, 2024
1 parent 2eea4be commit b85fa59
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repos:
rev: v1.10.0
hooks:
- id: mypy
exclude: tests/
additional_dependencies: [numpy>=1.21.0]
hooks:
- id: poetry-export
Expand Down
25 changes: 25 additions & 0 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,28 @@ def test_interp_kind() -> None:
model.get_emission_pix(
pixels=[1, 4, 5], freq=27 * units.micron, nside=32, obs_time=OBS_TIME
)


def test_wrong_frame() -> None:
"""Tests that an error is correctly raised when an incorrect frame is passed in."""
model = Zodipy()
with pytest.raises(ValueError):
model.get_emission_pix(
[1, 4, 5],
nside=32,
freq=27 * units.micron,
obs_time=OBS_TIME,
coord_in="not a valid frame",
)


def test_non_quantity_ang_raises_error() -> None:
"""Tests that an error is correctly raised if the user inputed angles are not Quantities."""
model = Zodipy()
with pytest.raises(TypeError):
model.get_emission_ang(
32,
12,
freq=27 * units.micron,
obs_time=OBS_TIME,
)
13 changes: 6 additions & 7 deletions zodipy/_bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

import astropy.units as u
import numpy as np
from astropy import units

from zodipy._constants import (
MAX_INTERPOLATION_GRID_TEMPERATURE,
Expand All @@ -18,12 +18,11 @@
import numpy.typing as npt

from zodipy._ipd_model import InterplanetaryDustModel
from zodipy._types import FrequencyOrWavelength


@dataclass
class Bandpass:
frequencies: FrequencyOrWavelength
frequencies: units.Quantity
weights: npt.NDArray[np.float64]

def integrate(self, quantity: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
Expand All @@ -33,8 +32,8 @@ def integrate(self, quantity: npt.NDArray[np.float64]) -> npt.NDArray[np.float64
def switch_convention(self) -> None:
"""Switch the bandpass from frequency to wavelength or the other way around."""
self.frequencies = self.frequencies.to(
u.micron if self.frequencies.unit.is_equivalent(u.Hz) else u.Hz,
equivalencies=u.spectral(),
units.micron if self.frequencies.unit.is_equivalent(units.Hz) else units.Hz,
equivalencies=units.spectral(),
)
if self.frequencies.size > 1:
self.frequencies = np.flip(self.frequencies)
Expand All @@ -43,7 +42,7 @@ def switch_convention(self) -> None:


def validate_and_get_bandpass(
freq: FrequencyOrWavelength,
freq: units.Quantity,
weights: npt.ArrayLike | None,
model: InterplanetaryDustModel,
extrapolate: bool,
Expand All @@ -62,7 +61,7 @@ def get_bandpass_interpolation_table(
max_temp: float = MAX_INTERPOLATION_GRID_TEMPERATURE,
) -> npt.NDArray[np.float64]:
"""Pre-compute the bandpass integrated blackbody emission for a grid of temperatures."""
if not bandpass.frequencies.unit.is_equivalent(u.Hz):
if not bandpass.frequencies.unit.is_equivalent(units.Hz):
bandpass.switch_convention()

bandpass_integrals = np.zeros(n_points)
Expand Down
5 changes: 3 additions & 2 deletions zodipy/_ipd_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from typing import TYPE_CHECKING, Mapping, Sequence

if TYPE_CHECKING:
from astropy import units

from zodipy._ipd_comps import Component, ComponentLabel
from zodipy._types import FrequencyOrWavelength


@dataclass
Expand All @@ -20,7 +21,7 @@ class InterplanetaryDustModel(ABC):
"""

comps: Mapping[ComponentLabel, Component]
spectrum: FrequencyOrWavelength
spectrum: units.Quantity

def to_dict(self) -> dict:
"""Return a dictionary representation of the model."""
Expand Down
13 changes: 0 additions & 13 deletions zodipy/_types.py

This file was deleted.

0 comments on commit b85fa59

Please sign in to comment.