def __init__(self, charge_values: Sequence[float], charge_name: str = None) -> None: """ The constructor of the ChargeValues class. If the charge name is None, the name of the class is used. If the JF factory included an alias in the classname, the alias is used. Parameters ---------- charge_values : Sequence[float] The sequence of charges for each leaf node particle within a single tree. charge_name : str or None, optional The name of the charge. """ log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__, charge_values=charge_values, charge_name=charge_name) # If no charge name is given, we want to use the alias of the .ini file which is included in the # __class__.__name__ property in the factory. get_alias() extracts this alias self._charge_name = (charge_name if charge_name is not None else to_snake_case(get_alias(self.__class__.__name__))) self._charge_values = charge_values
def __init__( self, create: Sequence[str], trash: Sequence[str], event_handler: EventHandler, number_event_handlers: int, tag: str = None, activate: Sequence[str] = (), deactivate: Sequence[str] = () ) -> None: """ The constructor of the abstract tagger class. Parameters ---------- create : Sequence[str] Sequence of tags to create after an event handler of this tagger has committed an event to the global state. trash : Sequence[str] Sequence of tags to trash after an event handler of this tagger has committed an event to the global state. event_handler : event_handler.EventHandler A single event handler instance. number_event_handlers : int Number of event handlers to prepare. The tagger will deepcopy the given event handler instance to create this number of event handlers. tag : str or None, optional Tag used in all four lists (also of other taggers). If None, the class name (or the alias set in the factory) will be used as the tag. activate : Sequence[str], optional Sequence of tags to activate after an event handler of this tagger has committed an event to the global state. deactivate : Sequence[str], optional Sequence of tags to deactivate after an event handler of this tagger has committed an event to the global state. """ self._activates = activate self._deactivates = deactivate # Do this before calling super().__init__(), because Initializer class will overwrite public methods. self._deactivated_yield_identifiers_send_event_time = lambda separated_active_units: iter( ()) self._activated_yield_identifiers_send_event_time = self.yield_identifiers_send_event_time super().__init__() # If no tag is given, we want to use the alias of the .ini file which is included in the __class__.__name__. # property in the factory. get_alias() extracts this alias self._tag = tag if tag is not None else to_snake_case( get_alias(self.__class__.__name__)) self._creates = create self._trashes = trash self._number_event_handlers = number_event_handlers self._event_handler_to_copy = event_handler self._event_handlers = None
def __init__(self, input_handler: InputHandler, output_handlers: Sequence[OutputHandler] = ()) -> None: """ The constructor of the InputOutputHandler class. Parameters ---------- input_handler : input_output_handler.input_handler.InputHandler The input handler. output_handlers : Sequence[input_output_handler.output_handler.OutputHandler] The sequence of output handlers. """ log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__, input_handler=input_handler.__class__.__name__, output_handlers=[output_handler.__class__.__name__ for output_handler in output_handlers]) self._input_handler = input_handler # Event Handlers may refer to the alias (if there is one) of the .ini file which is included in the # __class__.__name__ property in the factory. get_alias() extracts this alias self._output_handlers_dictionary = {to_snake_case(get_alias(output_handler.__class__.__name__)): output_handler for output_handler in output_handlers}
def initialize_with_internal_states( self, internal_states: Sequence[InternalState]) -> None: """ Initialize the tagger based on the initialized internal states. Adds a second initialize method relevant to the base Initializer class. This method is called once in the beginning of the run by the tag activator. However, this method does not call the initialize method of the Initializer class. Therefore, other public methods of this class can still not be called without raising an error after this method has been used. To finalize the initialization of this class, use the initialize method (which should be called after this method). This method extracts the internal state corresponding to the internal state label out of the sequence of internal states. If a tagger needs to further initialize its event handler in the self._event_handler_to_copy attribute (for example, with a cell system), it should extend this method. The subsequent call of the initialize method will then deepcopy the initialized event handler to create all event handlers for this tagger. Parameters ---------- internal_states : Sequence[activator.internal_state.InternalState] Sequence of all initialized internal states in the activator. """ super().initialize_with_internal_states(internal_states) relevant_internal_state = [ state for state in internal_states if to_snake_case(get_alias(state.__class__.__name__)) == self._internal_state_label ] if len(relevant_internal_state) == 0: raise ConfigurationError( "The given internal state label '{0}' does not exist!".format( self._internal_state_label)) if len(relevant_internal_state) > 1: raise ConfigurationError( "The given internal state label '{0}' exists more than once!". format(self._internal_state_label)) self._internal_state = relevant_internal_state[0]
def test_get_alias_empty_string_raises_error(self, _, __, ___): with self.assertRaises(ConfigurationError): factory.get_alias("")
def test_get_alias_empty_alias_raises_error(self, _, __, ___): with self.assertRaises(ConfigurationError): factory.get_alias(" (SomeClass)")
def test_get_alias_missing_brackets_raises_error(self, _, __, ___): with self.assertRaises(ConfigurationError): factory.get_alias("Test SomeClass")
def test_get_alias_too_many_whitespaces_raises_error(self, _, __, ___): with self.assertRaises(ConfigurationError): factory.get_alias("Test (SomeClass)")
def test_get_alias_alias_not_set(self, _, __, ___): self.assertEqual(factory.get_alias("SomeClass"), "SomeClass")
def test_get_alias_alias_set(self, _, __, ___): self.assertEqual(factory.get_alias("Test (SomeClass)"), "Test")