From bd1848d529140f5decef092085a8633009645169 Mon Sep 17 00:00:00 2001
From: Johannes Schumann <johannes.schumann@fau.de>
Date: Sat, 12 Dec 2020 03:09:37 +0100
Subject: [PATCH] Update config and introduce config tests

---
 km3buu/config.py            |  7 +++--
 km3buu/tests/test_config.py | 56 +++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 3 deletions(-)
 create mode 100644 km3buu/tests/test_config.py

diff --git a/km3buu/config.py b/km3buu/config.py
index c0d600a..083f953 100644
--- a/km3buu/config.py
+++ b/km3buu/config.py
@@ -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):
diff --git a/km3buu/tests/test_config.py b/km3buu/tests/test_config.py
new file mode 100644
index 0000000..18e2a13
--- /dev/null
+++ b/km3buu/tests/test_config.py
@@ -0,0 +1,56 @@
+#!/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"
-- 
GitLab