Esempio n. 1
0
def test_open_aborts_empty_filename(qtbot, monkeypatch):
    """ When creating, an empty filename will abort the creation """
    # Given
    manager = ProjectFileManager()
    monkeypatch.setattr(QFileDialog, "getOpenFileName",
                        lambda _, __, ___, ____: ("", False))

    # When
    with qtbot.assertNotEmitted(manager.project_changed):
        manager.open_project()

    # Then
    assert manager.project is None
Esempio n. 2
0
def test_open_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")
    filename.write("gedcom: none\n" + "plans: []\n" + "version: '1.0'")
    manager = ProjectFileManager()
    monkeypatch.setattr(QFileDialog, "getOpenFileName",
                        lambda _, __, ___, ____: (str(filename), False))

    # When
    with qtbot.waitSignals([manager.project_changed]):
        manager.open_project()

    # Then
    assert manager.project is not None
    assert manager.project.filename == filename
Esempio n. 3
0
def test_open_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, "getOpenFileName")
    monkeypatch.setattr(manager.project_discard, "exec_",
                        lambda: QMessageBox.Cancel)

    # When
    with qtbot.assertNotEmitted(manager.project_changed):
        manager.open_project()

    # Then
    assert manager.project is None
Esempio n. 4
0
def test_open_saves_after_confirming(qtbot, monkeypatch, tmpdir):
    """ When creating new, confirm discarding unsaved changes will then create new """
    # Given
    filename = tmpdir.join("test_open_saves_after_confirming.txt")
    filename.write("gedcom: none\n" + "plans: []\n" + "version: '1.0'")
    manager = ProjectFileManager()
    manager.needs_saving = True
    monkeypatch.setattr(manager.project_discard, "exec_",
                        lambda: QMessageBox.Ok)
    monkeypatch.setattr(QFileDialog, "getOpenFileName",
                        lambda _, __, ___, ____: (str(filename), False))

    # When
    with qtbot.waitSignals([manager.project_changed]):
        manager.open_project()

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