Skip to content
Snippets Groups Projects
Commit 24cf773f authored by Johannes Schumann's avatar Johannes Schumann
Browse files

Add tests

parent 57b49bee
No related branches found
No related tags found
No related merge requests found
Pipeline #16241 passed with warnings
...@@ -297,7 +297,7 @@ def write_detector_file(gibuu_output, ...@@ -297,7 +297,7 @@ def write_detector_file(gibuu_output,
ofile="gibuu.aanet.root", ofile="gibuu.aanet.root",
can=(0, 476.5, 403.4), can=(0, 476.5, 403.4),
livetime=3.156e7, livetime=3.156e7,
propagate_tau=True): propagate_tau=True): # pragma: no cover
""" """
Convert the GiBUU output to a KM3NeT MC (AANET) file Convert the GiBUU output to a KM3NeT MC (AANET) file
......
...@@ -11,6 +11,7 @@ __email__ = "jschumann@km3net.de" ...@@ -11,6 +11,7 @@ __email__ = "jschumann@km3net.de"
__status__ = "Development" __status__ = "Development"
import unittest import unittest
from unittest.mock import patch
import numpy as np import numpy as np
import pytest import pytest
import km3io import km3io
...@@ -18,7 +19,7 @@ from km3buu.output import * ...@@ -18,7 +19,7 @@ from km3buu.output import *
from os import listdir from os import listdir
from os.path import abspath, join, dirname from os.path import abspath, join, dirname
from km3net_testdata import data_path from km3net_testdata import data_path
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile, TemporaryDirectory
TESTDATA_DIR = data_path("gibuu") TESTDATA_DIR = data_path("gibuu")
...@@ -40,9 +41,17 @@ class TestXSection(unittest.TestCase): ...@@ -40,9 +41,17 @@ class TestXSection(unittest.TestCase):
class TestGiBUUOutput(unittest.TestCase): class TestGiBUUOutput(unittest.TestCase):
def setUp(self): def setup_class(self):
self.output = GiBUUOutput(TESTDATA_DIR) self.output = GiBUUOutput(TESTDATA_DIR)
def test_tmp_dir_init(self):
with patch('tempfile.TemporaryDirectory',
spec=TemporaryDirectory) as mock:
instance = mock.return_value
instance.name = abspath(TESTDATA_DIR)
output = GiBUUOutput(instance)
assert output.data_path == abspath(TESTDATA_DIR)
def test_attr(self): def test_attr(self):
assert hasattr(self.output, "df") assert hasattr(self.output, "df")
...@@ -54,6 +63,15 @@ class TestGiBUUOutput(unittest.TestCase): ...@@ -54,6 +63,15 @@ class TestGiBUUOutput(unittest.TestCase):
n_evts = self.output.flux_interpolation.integral(0.7, 1.0) / 0.02 n_evts = self.output.flux_interpolation.integral(0.7, 1.0) / 0.02
self.assertAlmostEqual(xsec / n_evts, 0.8, places=2) self.assertAlmostEqual(xsec / n_evts, 0.8, places=2)
def test_nucleus_properties(self):
assert self.output.Z == 8
assert self.output.A == 16
def test_w2weights(self):
w2 = self.output.w2weights(123.0, 2.6e28, 4 * np.pi)
np.testing.assert_array_almost_equal(
w2[:3], [7.63360911e+01, 3.60997502e-01, 1.13273189e+03])
@pytest.mark.skipif(not AANET_AVAILABLE, reason="aanet required") @pytest.mark.skipif(not AANET_AVAILABLE, reason="aanet required")
class TestAANET(unittest.TestCase): class TestAANET(unittest.TestCase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment