Ejemplo n.º 1
0
def test_changing_field_without_context_manager_should_error(option: Options):
    # Run
    with pytest.raises(AssertionError) as exception:
        option.output_directory = Path("start")

    # Assert
    assert str(exception.value) == "Attempting to edit an Options, but it wasn't made editable"
Ejemplo n.º 2
0
def test_single_save_with_nested_context_manager(mock_save_to_disk: MagicMock,
                                                 option: Options):
    # Setup
    option._output_directory = Path("start")

    # Run
    with option:
        option.output_directory = Path("end")
        with option:
            pass

    # Assert
    mock_save_to_disk.assert_called_once_with(option)
Ejemplo n.º 3
0
def test_save_with_context_manager(mock_save_to_disk: MagicMock,
                                   option: Options):
    # Setup
    settings_changed = MagicMock()
    option._output_directory = Path("start")
    option.on_options_changed = settings_changed

    # Run
    with option:
        option.output_directory = Path("end")

    # Assert
    mock_save_to_disk.assert_called_once_with(option)
    settings_changed.assert_called_once_with()
Ejemplo n.º 4
0
def test_edit_during_options_changed(tmpdir):
    # Setup
    option = Options(Path(tmpdir))
    option._output_directory = Path("start")

    def on_changed():
        with option:
            option.output_directory = Path("final")

    option.on_options_changed = on_changed

    # Run
    with option:
        option.output_directory = Path("middle")

    second_option = Options(Path(tmpdir))
    second_option.load_from_disk()

    # Assert
    assert option.output_directory == Path("final")
    assert option.output_directory == second_option.output_directory