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

Update config and introduce config tests

parent 0f2ee957
No related branches found
No related tags found
1 merge request!4KM3NeT Dataformat data writeout
Pipeline #16370 passed with warnings
......@@ -37,7 +37,7 @@ GIBUU_IMAGE_PATH_KEY = "image_path"
PROPOSAL_SECTION = "PROPOSAL"
PROPOSAL_ITP_PATH_KEY = "itp_table_path"
GSEAGEN_SECTION = "gSeagen"
GSEAGEN_SECTION = "gSeaGen"
GSEAGEN_PATH_KEY = "path"
GSEAGEN_MEDIA_COMPOSITION_FILE = "MediaComposition.xml"
......@@ -71,6 +71,7 @@ class Config(object):
@property
def gibuu_image_path(self):
key = GIBUU_IMAGE_PATH_KEY
image_path = self.get(GIBUU_SECTION, GIBUU_IMAGE_PATH_KEY)
if image_path is None or not isfile(image_path):
dev_path = abspath(join(dirname(__file__), os.pardir, IMAGE_NAME))
......@@ -117,11 +118,11 @@ class Config(object):
@property
def km3net_lib_path(self):
return self.set(GENERAL_SECTION, KM3NET_LIB_PATH_KEY, None)
return self.get(GENERAL_SECTION, KM3NET_LIB_PATH_KEY, None)
@km3net_lib_path.setter
def km3net_lib_path(self, value):
return self.get(GENERAL_SECTION, KM3NET_LIB_PATH_KEY, value)
self.set(GENERAL_SECTION, KM3NET_LIB_PATH_KEY, value)
def read_media_compositions(filename):
......
#!/usr/bin/env python
# coding=utf-8
# Filename: test_ctrl.py
__author__ = "Johannes Schumann"
__copyright__ = "Copyright 2020, Johannes Schumann and the KM3NeT collaboration."
__credits__ = []
__license__ = "MIT"
__maintainer__ = "Johannes Schumann"
__email__ = "jschumann@km3net.de"
__status__ = "Development"
import os
import unittest
from unittest.mock import patch
import numpy as np
from km3buu.jobcard import *
from km3buu.config import Config, read_media_compositions
from tempfile import NamedTemporaryFile
TEST_CONFIG = """
[General]
km3net_lib_path=/tmp/km3net_lib_test
[GiBUU]
image_path=%s
[PROPOSAL]
itp_table_path=/tmp/.tables
[gSeaGen]
path=/tmp/gseagen
"""
class TestConfig(unittest.TestCase):
def setUp(self):
self.cfg_tmpfile = NamedTemporaryFile(delete=False)
self.mock_image_file = NamedTemporaryFile(delete=False)
with open(self.cfg_tmpfile.name, "w") as f:
f.write(TEST_CONFIG % self.mock_image_file.name)
self.cfg = Config(self.cfg_tmpfile.name)
def tearDown(self):
os.remove(self.cfg_tmpfile.name)
os.remove(self.mock_image_file.name)
def test_general_section(self):
assert self.cfg.km3net_lib_path == "/tmp/km3net_lib_test"
def test_gibuu_section(self):
assert self.cfg.gibuu_image_path == self.mock_image_file.name
def test_proposal_section(self):
assert self.cfg.proposal_itp_tables == "/tmp/.tables"
def test_gseagen_path(self):
assert self.cfg.gseagen_path == "/tmp/gseagen"
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