def test_source_is_set_to_hyphen_when_source_is_empty(self):
        notification = new_notification(source='')

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertIn('-', notify_cmd)
    def test_does_not_include_urgency_in_command_when_urgency_is_not_set(self):
        notification = new_notification(urgency='')

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertNotIn('--urgency', notify_cmd)
    def test_does_not_include_transient_hint_in_command_when_transient_is_off(self):
        notification = new_notification(transient=False)

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertNotIn('int:transient:1', notify_cmd)
    def test_calls_correct_command_when_all_notification_parameters_are_set(
            self):
        notification = new_notification(source='source',
                                        message='message',
                                        icon='icon.png',
                                        desktop_entry='weechat',
                                        timeout=5000,
                                        transient=True,
                                        urgency='normal')

        send_notification(notification)

        class AnyDevNullStream:
            def __eq__(self, other):
                return other.name == os.devnull

        self.subprocess.check_call.assert_called_once_with(
            [
                'notify-send', '--app-name', 'weechat', '--icon', 'icon.png',
                '--hint', 'string:desktop-entry:weechat', '--expire-time',
                '5000', '--hint', 'int:transient:1', '--urgency', 'normal',
                '--', 'source', 'message'
            ],
            stderr=self.subprocess.STDOUT,
            stdout=AnyDevNullStream())
    def test_does_not_include_urgency_in_command_when_urgency_is_not_set(self):
        notification = new_notification(urgency='')

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertNotIn('--urgency', notify_cmd)
    def test_does_not_include_expire_time_in_command_when_timeout_is_not_set(self):
        notification = new_notification(timeout='')

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertNotIn('--expire-time', notify_cmd)
    def test_source_is_set_to_hyphen_when_source_is_empty(self):
        notification = new_notification(source='')

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertIn('-', notify_cmd)
    def test_calls_correct_command_when_all_notification_parameters_are_set(self):
        notification = new_notification(
            source='source',
            message='message',
            icon='icon.png',
            timeout=5000,
            transient=True,
            urgency='normal'
        )

        send_notification(notification)

        class AnyDevNullStream:
            def __eq__(self, other):
                return other.name == os.devnull

        self.subprocess.check_call.assert_called_once_with(
            [
                'notify-send',
                '--app-name', 'weechat',
                '--icon', 'icon.png',
                '--expire-time', '5000',
                '--hint', 'int:transient:1',
                '--urgency', 'normal',
                '--',
                'source',
                'message'
            ],
            stderr=self.subprocess.STDOUT,
            stdout=AnyDevNullStream()
        )
Esempio n. 9
0
    def test_does_not_include_expire_time_in_command_when_timeout_is_not_set(self):
        notification = new_notification(timeout='')

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertNotIn('--expire-time', notify_cmd)
    def test_prints_error_message_when_notification_sending_fails(self):
        self.subprocess.check_call.side_effect = OSError(
            'No such file or directory: notify-send')

        send_notification(new_notification())

        self.assertIn('OSError: No such file or directory',
                      self.print_mock.call_args[0][0])
    def test_does_not_include_transient_hint_in_command_when_transient_is_off(
            self):
        notification = new_notification(transient=False)

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertNotIn('int:transient:1', notify_cmd)
    def test_does_not_include_desktop_entry_in_command_when_it_is_not_set(
            self):
        notification = new_notification(desktop_entry='')

        send_notification(notification)

        notify_cmd = self.subprocess.check_call.call_args[0][0]
        self.assertNotIn('desktop-entry', notify_cmd)
    def test_prints_error_message_when_notification_sending_fails(self):
        self.subprocess.check_call.side_effect = OSError(
            'No such file or directory: notify-send'
        )

        send_notification(new_notification())

        self.assertIn(
            'OSError: No such file or directory',
            self.print_mock.call_args[0][0]
        )
Esempio n. 14
0
from notify_send_tests import new_notification
from notify_send import send_notification

import warnings

# import sys
# import traceback

# def warn_with_traceback(message, category, filename, lineno, file=None, line=None):

#     log = file if hasattr(file, "write") else sys.stderr
#     traceback.print_stack(file=log)
#     log.write(warnings.formatwarning(message, category, filename, lineno, line))

# warnings.showwarning = warn_with_traceback

notification = new_notification()
send_notification(notification)

notification = new_notification(message="second", transient=False)
send_notification(notification)

notification = new_notification(message="third", urgency="low")
send_notification(notification)

notification = new_notification(message="third", urgency="critical")
send_notification(notification)
notification = new_notification(message="a" * 2000, urgency="critical")
send_notification(notification)