Exemplo n.º 1
0
 def test_alert_should_fall_back(self):
     with NamedTemporaryFile(mode='a+t') as fallback_file:
         sut = FileNotifier(fallback_file=fallback_file)
         message = 'Something happened!'
         sut.alert(message)
         fallback_file.seek(0)
         self.assertEquals(fallback_file.read(), message + '\n')
Exemplo n.º 2
0
 def test_state(self):
     with NamedTemporaryFile(mode='a+t') as state_file:
         with NamedTemporaryFile(mode='a+t') as fallback_file:
             sut = FileNotifier(state_file=state_file,
                                fallback_file=fallback_file)
             message = 'Something happened!'
             sut.state(message)
             state_file.seek(0)
             fallback_file.seek(0)
             self.assertEquals(state_file.read(), message + '\n')
             self.assertEquals(fallback_file.read(), '')
Exemplo n.º 3
0
 def test_confirm(self):
     with NamedTemporaryFile(mode='a+t') as confirm_file:
         with NamedTemporaryFile(mode='a+t') as fallback_file:
             sut = FileNotifier(confirm_file=confirm_file,
                                fallback_file=fallback_file)
             message = 'Something happened!'
             sut.confirm(message)
             confirm_file.seek(0)
             fallback_file.seek(0)
             self.assertEquals(confirm_file.read(), message + '\n')
             self.assertEquals(fallback_file.read(), '')
Exemplo n.º 4
0
 def test_init_without_alert_and_fallback(self):
     with NamedTemporaryFile(mode='a+t') as state_file:
         with NamedTemporaryFile(mode='a+t') as inform_file:
             with NamedTemporaryFile(mode='a+t') as confirm_file:
                 with self.assertRaises(ValueError):
                     FileNotifier(
                         state_file=state_file, inform_file=inform_file, confirm_file=confirm_file)
Exemplo n.º 5
0
def _new_file_notifier_from_configuration_data(configuration, configuration_data):
    """Parse configuration from raw, built-in types such as dictionaries, lists, and scalars.

    :param configuration: Configuration
    :param configuration_data: dict
    :return: CommandNotifier
    :raise: ValueError
    """
    state_file = open(
        configuration_data['state'], mode='a+t') if 'state' in configuration_data else None
    inform_file = open(
        configuration_data['inform'], mode='a+t') if 'inform' in configuration_data else None
    confirm_file = open(
        configuration_data['confirm'], mode='a+t') if 'confirm' in configuration_data else None
    alert_file = open(
        configuration_data['alert'], mode='a+t') if 'alert' in configuration_data else None
    fallback_file = open(
        configuration_data['fallback'], mode='a+t') if 'fallback' in configuration_data else None
    if None in [state_file, inform_file, confirm_file, alert_file] and fallback_file is None:
        raise ValueError(
            '`fallback` must be given if one or more of the other arguments are omitted.')

    return FileNotifier(state_file, inform_file, confirm_file, alert_file, fallback_file)