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

Updated tests

parent 18c8ef2e
No related branches found
No related tags found
No related merge requests found
Pipeline #15226 passed
...@@ -10,26 +10,32 @@ __maintainer__ = "Johannes Schumann" ...@@ -10,26 +10,32 @@ __maintainer__ = "Johannes Schumann"
__email__ = "jschumann@km3net.de" __email__ = "jschumann@km3net.de"
__status__ = "Development" __status__ = "Development"
import csv
import unittest import unittest
import numpy as np import numpy as np
from km3buu.jobcard import * from km3buu.jobcard import *
from km3buu.ctrl import run_jobcard from km3buu.ctrl import run_jobcard
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory, NamedTemporaryFile
from os import listdir from os import listdir
from os.path import abspath, join, dirname from os.path import abspath, join, dirname
from thepipe.logger import get_logger from thepipe.logger import get_logger
from km3net_testdata import data_path
JOBCARD_FOLDER = abspath(join(dirname(__file__), "../../jobcards")) TESTDATA_DIR = data_path("gibuu")
# class TestCTRLmisc(unittest.TestCase):
# def test_invalid_jobcard(self):
class TestCTRLbyJobcardFile(unittest.TestCase): class TestCTRLbyJobcardFile(unittest.TestCase):
def setUp(self): def setUp(self):
self.filename = join(JOBCARD_FOLDER, "examples/example.job") self.filename = join(TESTDATA_DIR, "km3net_testdata.job")
self.output_dir = TemporaryDirectory() self.output_dir = TemporaryDirectory()
self.retval = run_jobcard(self.filename, self.output_dir.name) self.flux_file = NamedTemporaryFile(suffix='.dat')
with open(self.flux_file.name, 'w') as f:
ene = np.linspace(0.1, 20, 100)
writer = csv.writer(f, delimiter=' ')
writer.writerows(zip(ene, np.power(ene, -1)))
self.retval = run_jobcard(self.filename,
self.output_dir.name,
fluxfile=self.flux_file.name)
log = get_logger("ctrl.py") log = get_logger("ctrl.py")
log.setLevel("INFO") log.setLevel("INFO")
...@@ -38,7 +44,7 @@ class TestCTRLbyJobcardFile(unittest.TestCase): ...@@ -38,7 +44,7 @@ class TestCTRLbyJobcardFile(unittest.TestCase):
def test_output_files_existing(self): def test_output_files_existing(self):
files = listdir(self.output_dir.name) files = listdir(self.output_dir.name)
assert "FinalEvents.dat" in files assert "EventOutput.Pert.00000001.root" in files
class TestCTRLbyJobcardObject(unittest.TestCase): class TestCTRLbyJobcardObject(unittest.TestCase):
......
...@@ -36,3 +36,11 @@ class TestGiBUUOutput(unittest.TestCase): ...@@ -36,3 +36,11 @@ class TestGiBUUOutput(unittest.TestCase):
def test_attr(self): def test_attr(self):
assert hasattr(self.output, "df") assert hasattr(self.output, "df")
def test_mean_xsec(self):
df = self.output.df
df = df.groupby(level=0).head(1)
df = df[(df.lepIn_E > 0.7) & (df.lepIn_E < 1.0)]
xsec = np.sum(df.xsec / df.lepIn_E)
n_evts = self.output.flux_interpolation.integral(0.7, 1.0) / 0.02
self.assertAlmostEqual(xsec / n_evts, 0.8, places=2)
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