Skip to content

Commit

Permalink
Start testing suite (#10)
Browse files Browse the repository at this point in the history
* Start testing suite (io.read_yaml and spectral module)

* formatting and better asserting

* fix assertion
  • Loading branch information
HealthyPear authored Jun 24, 2024
1 parent 13afd29 commit f216460
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/iact_estimator/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Testing suite for iact-estimator."""
18 changes: 18 additions & 0 deletions src/iact_estimator/tests/test_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def test_read_yaml(tmp_path):
from ..io import read_yaml

test_file = tmp_path / "test_file.yml"
test_file.write_text(
"""
a: 1
b:
c: 3
d: 4
"""
)

data = read_yaml(test_file)

assert data["a"] == 1
assert data["b"]["c"] == 3
assert data["b"]["d"] == 4
24 changes: 24 additions & 0 deletions src/iact_estimator/tests/test_spectral.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Test cases automatically generated by Pynguin (https://www.pynguin.eu).
# Please check them before you use them.

import astropy.units as u
import numpy as np


def test_crab_nebula_spectrum():
from ..spectral import crab_nebula_spectrum

spectrum = crab_nebula_spectrum()

assert spectrum.amplitude.unit == u.Unit("TeV^-1 s^-1 cm^-2")
assert spectrum.reference.unit == u.TeV

assert np.allclose(
[
spectrum.alpha.value,
spectrum.beta.value,
spectrum.amplitude.value,
spectrum.reference.value,
],
[2.51, 0.21 / np.log(10), 3.39e-11, 1.0],
)

0 comments on commit f216460

Please sign in to comment.