def setUp(self): self.pathToConfgiFiles = os.path.dirname(os.path.abspath(__file__)) self.path_to_default_test_config_file = self.pathToConfgiFiles + '/test_config.cfg' self.defaultSpec = { "Section1": [ ConfigurationOption( "aPositiveInt", "", int, [ ConfigurationOptionValidation( lambda value: value > 0, "This value must be positive.")]), ConfigurationOption( "aNegativeInt", "", int, [ ConfigurationOptionValidation( lambda value: value < 0, "This value must be negative.")]), ConfigurationOption( "aBoolean", "", to_bool) ], "Section2": [ ConfigurationOption( "aPositiveInt", "", int, [ ConfigurationOptionValidation( lambda value: value > 0, "This value must be positive.")]), ConfigurationOption( "aNegativeInt", "", int, [ ConfigurationOptionValidation( lambda value: value < 0, "This value must be negative.")]), ConfigurationOption( "aFloat", "", float), ConfigurationOption( "aBoolean", "", to_bool) ], }
def test_invalid_value(self): spec = { "Section1": [ ConfigurationOption( "aPositiveInt", "", int, [ ConfigurationOptionValidation( lambda value: value > 200, "This value must be very large.")]) ] } self.assertRaises(ValueError, Configuration, self.path_to_default_test_config_file, spec)
""" Created on Nov 19, 2015 @author: Fabian Leven """ from driftchamber.core.configuration.configuration_option import ConfigurationOption from driftchamber.core.configuration.configuration_option_validation import ConfigurationOptionValidation from driftchamber.core.configuration.parsing_functions import parse_module_sequence configuration_specification = { "MultiModule": [ ConfigurationOption("moduleSequence", ( "A list of the module names that shall be executed by the run engine. " "Separate the module names using line breaks. " "The corresponding module has to be present in the module folder. " "In more detail, this means there must be a python file present called " "'ModuleNameModule' in the module folder in a sub folder also called " "'ModuleNameModule'. " "It must hold a class called 'ModuleName' " "(without the 'Module' at the end)." ), parse_module_sequence, [ ConfigurationOptionValidation( lambda value: len(value) > 0, "There must be at least one module in the module sequence of the 'MultiModule'." ) ]), ], }
# [#A list of conditions the value must satisfy. # _ConfigurationOptionValidation(lambda value: value > 0, # "This value must be greater than 0"), # _ConfigurationOptionValidation(lambda value: value < 10, # "This value must be smaller than 10"), # ] # # weather the option must be present (True) in the configuration or not (False) # False, #), ConfigurationOption( "nEvent", "The amount of events to simulate. This has to be a positive integer.", int, [ ConfigurationOptionValidation( lambda value: value > 0, "The amount of events must be a positive integer.")]), ConfigurationOption( "levelOfLogging", ("The level of the logging. Must be one of the following: " "'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'."), lambda value: {'CRITICAL': logging.CRITICAL, 'ERROR': logging.ERROR, 'WARNING': logging.WARNING, 'INFO': logging.INFO, 'DEBUG': logging.DEBUG, 'NOTSET': logging.NOTSET}[value.upper()], p_isCompulsory = False) ], "Modules":[ ConfigurationOption(
from driftchamber.core.configuration.configuration_option import ConfigurationOption from driftchamber.core.configuration.configuration_option_validation import ConfigurationOptionValidation configuration_specification = { 'Particle': [ ConfigurationOption('mass', 'The mass of the particle in GeV.', float, [ConfigurationOptionValidation( lambda value: value > 0, 'The mass of the particle must be positive.' )], p_isCompulsory=True), ConfigurationOption('name', 'The name of a particle.', lambda value: str(value), p_isCompulsory=True), ConfigurationOption('max_mom', 'The maximum momentum of a particle in GeV.', float, [ConfigurationOptionValidation( lambda value: value > 0, 'The maximum momentum of a particle must be positive.' )], p_isCompulsory=True), ConfigurationOption('x_pos', 'The initial x-position of the particle in cells of the detector', int, p_isCompulsory=True), ConfigurationOption('y_pos',
from driftchamber.core.configuration.configuration_option import ConfigurationOption from driftchamber.core.configuration.configuration_option_validation import ConfigurationOptionValidation configuration_specification = { 'Particle': [ ConfigurationOption( 'mass', 'The mass of the particle in GeV.', float, [ ConfigurationOptionValidation( lambda value: value > 0, 'The mass of the particle must be positive.') ], p_isCompulsory=True), ConfigurationOption('name', 'The name of a particle.', lambda value: str(value), p_isCompulsory=True), ConfigurationOption( 'probability', 'The probability for noise per cell and event', float, [ ConfigurationOptionValidation( lambda value: value >= 0 and value <= 1, 'The probability must be a number between 0 and 1.') ], p_isCompulsory=True) ] }
# -*- coding: utf-8 -*- """ @author: elcerdo """ __author__ = 'elcerdo' from driftchamber.core.configuration.configuration_option import ConfigurationOption from driftchamber.core.configuration.configuration_option_validation import ConfigurationOptionValidation configuration_specification = { 'Tracking': [ ConfigurationOption('precision', 'Decimal precision', float, [ ConfigurationOptionValidation( lambda value: value >= 0, 'The precision should be positive.') ], p_isCompulsory=True), ConfigurationOption('threshold', 'minimum hits in houghspace to generate Track', int, [ ConfigurationOptionValidation( lambda value: value >= 0, 'The threshold should be positive.') ], p_isCompulsory=True), ConfigurationOption('minDistance', 'minimum distance in houghspace from other Tracks', int, [ ConfigurationOptionValidation(
from ast import literal_eval from driftchamber.core.configuration.configuration_option import ConfigurationOption from driftchamber.core.configuration.configuration_option_validation import ConfigurationOptionValidation configuration_specification = { 'Detector': [ ConfigurationOption('nSuperLayers', 'The number of super layers.', int, [ConfigurationOptionValidation( lambda value: value > 0, 'The number of super layers has to be a positive integer.' )], p_isCompulsory=True), ConfigurationOption('nLayersList', 'List of layers per super layer.', lambda value: literal_eval(value), [ConfigurationOptionValidation( lambda value: isinstance(value, list), "'layers' has to be a list that can be parsed by python."), ConfigurationOptionValidation( lambda value: all(isinstance(nLayer, int) for nLayer in value), "The amount of layers per super layer must be an integer."), ConfigurationOptionValidation( lambda value: all(nLayer > 0 for nLayer in value), "The amount of layers per super layer must be a positive integer.") ], p_isCompulsory=True),