Ejemplo n.º 1
0
def test_handle_invalid_configuration_file_cli_action(mocker, config, test_emitter, capsys, bad_config_payload):
    config_class = config.__class__
    config_file = Path(config.filepath)
    mocker.patch.object(config_class, '_read_configuration_file', return_value=bad_config_payload)
    with pytest.raises(config_class.ConfigurationError):
        handle_invalid_configuration_file(emitter=test_emitter,
                                          config_class=config_class,
                                          filepath=config_file)
    captured = capsys.readouterr()
    message_1 = INVALID_CONFIGURATION_FILE_WARNING.format(filepath=config_file)
    assert message_1 in captured.out
Ejemplo n.º 2
0
def test_handle_corrupted_configuration_file_cli_action(mocker, config, test_emitter, capsys, side_effect):
    config_class = config.__class__
    config_file = Path(config.filepath)
    mocker.patch('__main__.open', return_value=b'AAAAAAAAAAAAA')
    mocker.patch.object(config_class, '_read_configuration_file', side_effect=side_effect)
    with pytest.raises(side_effect):
        handle_invalid_configuration_file(emitter=test_emitter,
                                          config_class=config_class,
                                          filepath=config_file)
    captured = capsys.readouterr()
    message_1 = INVALID_CONFIGURATION_FILE_WARNING.format(filepath=config_file)
    message_2 = INVALID_JSON_IN_CONFIGURATION_WARNING.format(filepath=config_file)
    assert message_1 in captured.out
    assert message_2 in captured.out