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

restructure and test

parent f5982b18
No related branches found
No related tags found
1 merge request!1Merge python environment
Pipeline #9435 passed
......@@ -12,7 +12,7 @@ from os.path import isfile, isdir, join, dirname, abspath
from configparser import ConfigParser, Error, NoOptionError, NoSectionError
from thepipe.logger import get_logger
from . import IMAGE_NAME
from .core import build_image
from .environment import build_image
__author__ = "Johannes Schumann"
__copyright__ = "Copyright 2020, Johannes Schumann and the KM3NeT collaboration."
......
......@@ -14,8 +14,6 @@ __status__ = "Development"
import os
from spython.main import Client
from spython.utils import get_singularity_version
from distutils.version import LooseVersion
from os.path import join, abspath, basename, isdir, isfile
from tempfile import NamedTemporaryFile, TemporaryDirectory
from thepipe.logger import get_logger
......@@ -23,16 +21,14 @@ from thepipe.logger import get_logger
from . import IMAGE_NAME
from .config import Config
from .jobcard import Jobcard
from .environment import is_singularity_version_greater, MIN_SINGULARITY_VERSION
log = get_logger(basename(__file__))
log.setLevel("INFO")
singularity_version = LooseVersion(get_singularity_version().split()[-1])
if singularity_version < LooseVersion("3.3"):
log.error("Singularity version lower than 3.3 (found: %s)" %
singularity_version.vstring)
raise OSError("Singularity version below 3.3 (found: %s)" %
singularity_version.vstring)
if not is_singularity_version_greater(
MIN_SINGULARITY_VERSION): # pragma: no cover
log.error("Singularity version lower than %" % MIN_SINGULARITY_VERSION)
raise OSError("Singularity version below %s" % MIN_SINGULARITY_VERSION)
GIBUU_SHELL = """
#!/bin/bash
......
# Filename: core.py
# Filename: environment.py
"""
Core functions for the package environment
......@@ -14,13 +14,23 @@ __status__ = "Development"
import os
from spython.main import Client
from spython.utils import get_singularity_version
from os.path import join, isdir, basename
from thepipe.logger import get_logger
from distutils.version import LooseVersion
from . import IMAGE_NAME, DOCKER_URL
log = get_logger(basename(__file__))
MIN_SINGULARITY_VERSION = "3.3"
def is_singularity_version_greater(min_version): # pragma: no cover
singularity_version = LooseVersion(get_singularity_version().split()[-1])
retval = singularity_version > LooseVersion(MIN_SINGULARITY_VERSION)
return retval
def build_image(output_dir):
if not isdir(output_dir):
......
#!/usr/bin/env python
# coding=utf-8
# Filename: test_environment.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 unittest
from unittest.mock import patch
from km3buu.environment import *
from os.path import dirname, join
from spython.main import Client
from km3buu import DOCKER_URL, IMAGE_NAME
class TestBuild(unittest.TestCase):
def test_wrong_dir_path(self):
wrong_path = "foobar"
try:
build_image(wrong_path)
assert False
except OSError as e:
assert str(e) == "Directory not found!"
@patch.object(Client, 'build', return_value=123)
def test_build_cmd(self, function):
existing_path = dirname(__file__)
assert build_image(existing_path) == 123
expected_image_path = join(existing_path, IMAGE_NAME)
function.assert_called_once_with(DOCKER_URL,
image=expected_image_path,
sudo=False,
ext="simg")
......@@ -30,7 +30,6 @@ class TestXSection(unittest.TestCase):
self.assertAlmostEqual(xsection['Delta'], 0.61537)
class TestFinalEvents(unittest.TestCase):
def setUp(self):
self.filename = join(TESTDATA_DIR, EVENT_FILENAME)
......@@ -55,7 +54,13 @@ class TestFinalEvents(unittest.TestCase):
def test_slicing(self):
assert self.final_events[0:2] is not None
def test_length(self):
assert len(self.final_events) == 5
class TestGiBUUOutput(unittest.TestCase):
def setUp(self):
pass
self.output = GiBUUOutput(TESTDATA_DIR)
def test_attr(self):
assert hasattr(self.output, "events")
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