def test_notification_unexpected_error(mock_config): expected_exception = ValueError("well, that was unexpected") expected_repo = "gabor-boros/hammurabi" mock_config.settings.repository = expected_repo channel = "APPLE" link = "https://github.com/gabor-boros/hammurabi" message_template = full_strip(""" Hello team, You got a new Hammurabi update for {repository}. You can check the changes by clicking *<{changes_link}|here>*. """) notification = TestNotification([channel], message_template) notification.notify = Mock() notification.notify.side_effect = expected_exception with pytest.raises(ValueError): notification.send(link) notification.notify.assert_called_once_with( message_template.format(repository=expected_repo, changes_link=link), link)
def __init__( self, name: str, description: str, rules: Iterable[Rule], preconditions: Iterable[Precondition] = (), ) -> None: """ :param name: Name of the law :type name: str :param description: Detailed description what kind of rules are included :type description: str :param rules: List of those rules which should be included in the law :type rules: Iterable[Rule] """ super().__init__() self.name = name.strip() self.description = full_strip(description) self.rules: Iterable[Rule] = tuple() self.preconditions = preconditions self._failed_rules: Tuple[Rule, ...] = tuple() for rule in rules: self.rules += (rule,)
def test_full_strip_multiple_lines(value): test_input = "\n".join([ f"{get_whitespace()}{''.join(value)}{get_whitespace()}", f"{get_whitespace()}{''.join(value)}{get_whitespace()}", f"{get_whitespace()}{''.join(value)}{get_whitespace()}", f"{get_whitespace()}{''.join(value)}{get_whitespace()}", ]) result = full_strip(test_input) assert not WHITESPACE_PATTERN.match(result)
def description(self) -> str: """ Return the description of the :func:`hammurabi.rules.base.Rule.task` based on its docstring. :return: Stripped description of :func:`hammurabi.rules.base.Rule.task` :rtype: str .. note:: As of this property returns the docstring of :func:`hammurabi.rules.base.Rule.task` method, it worth to take care of its description when initialized. """ return full_strip(getattr(self.task, "__doc__", ""))
def documentation(self) -> str: """ Return the documentation of the rule based on its name, docstring and the description of its task. :return: Concatenation of the rule's name, docstring, and task description :rtype: str .. note:: As of this method returns the name and docstring of the rule it worth to take care of its name and description when initialized. """ doc = full_strip(getattr(self, "__doc__", "")) return f"{self.name}\n{doc}\n{self.description}"
def __init__(self, recipients: List[str], message_template: str) -> None: self.recipients = recipients self.message_template = full_strip(message_template)
def test_full_strip_one_line(value): test_input = f"{get_whitespace()}{value}{get_whitespace()}" result = full_strip(test_input) assert not WHITESPACE_PATTERN.match(result)