def test_create_new_aborts_empty_filename(qtbot, monkeypatch):
    """ When creating, an empty filename will abort the creation """
    # Given
    manager = ProjectFileManager()
    monkeypatch.setattr(QFileDialog, "getSaveFileName",
                        lambda _, __, ___, ____: ("", False))

    # When
    with qtbot.assertNotEmitted(manager.project_saved):
        manager.create_new_project()

    # Then
    assert manager.project is None
def test_create_new_creates_new_project_with_signal(qtbot, monkeypatch,
                                                    tmpdir):
    """ Creating a new project sets the project attribute """
    # Given
    filename = tmpdir.join("test_save_resets_need_saving.txt")
    manager = ProjectFileManager()
    monkeypatch.setattr(QFileDialog, "getSaveFileName",
                        lambda _, __, ___, ____: (str(filename), False))

    # When
    with qtbot.waitSignals([manager.project_saved]):
        manager.create_new_project()

    # Then
    assert manager.project is not None
    assert manager.project.filename == filename
def test_create_new_confirms_discard_and_aborts(qtbot, monkeypatch):
    """ When saving, the signal is raised """
    # Given
    manager = ProjectFileManager()
    manager.needs_saving = True
    qtbot.add_widget(manager)
    monkeypatch.delattr(QFileDialog, "getSaveFileName")
    monkeypatch.setattr(manager.project_discard, "exec_",
                        lambda: QMessageBox.Cancel)

    # When
    with qtbot.assertNotEmitted(manager.project_saved):
        manager.create_new_project()

    # Then
    assert manager.project is None
def test_create_new_saves_after_confirming(qtbot, monkeypatch, tmpdir):
    """ When creating new, confirm discarding unsaved changes will then create new """
    # Given
    filename = tmpdir.join("test_save_resets_need_saving.txt")
    manager = ProjectFileManager()
    manager.needs_saving = True
    monkeypatch.setattr(manager.project_discard, "exec_",
                        lambda: QMessageBox.Ok)
    monkeypatch.setattr(QFileDialog, "getSaveFileName",
                        lambda _, __, ___, ____: (str(filename), False))

    # When
    with qtbot.waitSignals([manager.project_saved]):
        manager.create_new_project()

    # Then
    assert manager.project is not None
    assert manager.project.filename == filename