コード例 #1
0
def test_blank_notes_called(qtbot, fake_link):
    """Test the blank note message is present."""
    with patch.object(MainWindow, "render_blank") as blank_render:

        main_window = MainWindow()
        qtbot.add_widget(main_window)

        blank_render.assert_called_once()
コード例 #2
0
def test_resize_stored(qtbot, fake_link):
    """Check the new size is stored in settings when a window is resized."""
    main_window = MainWindow()
    qtbot.add_widget(main_window)

    assert main_window.settings.width == 800
    assert main_window.settings.height == 800

    oldsize = QtCore.QSize(800, 800)
    newsize = QtCore.QSize(1000, 1000)
    resize_event = QtGui.QResizeEvent(oldsize, newsize)

    # Resize doesn't send the event and sending the event doesn't resize :/
    main_window.resize(newsize)
    QtCore.QCoreApplication.sendEvent(main_window, resize_event)

    assert main_window.settings.width == 1000
    assert main_window.settings.height == 1000
コード例 #3
0
def test_init_link(qtbot, fake_link):
    fake_link_instance = MagicMock()
    fake_link.return_value = fake_link_instance

    main_window = MainWindow()
    qtbot.add_widget(main_window)

    assert main_window.ui.statusbar.currentMessage(
    ) == "Not connected to server."

    fake_link.assert_called_with(main_window.client, main_window)
    fake_link_instance.start_loops.assert_called_once()
コード例 #4
0
def test_update_notes(qtbot, fake_link, idx):
    """Test the update method renders as expected"""
    main_window = MainWindow()
    qtbot.add_widget(main_window)

    main_window.settings.previous_splits = 0
    main_window.settings.next_splits = 2

    fake_notes = MagicMock(main_window.notes)
    fake_template = MagicMock(main_window.template)
    fake_note_ui = MagicMock(main_window.ui.notes)

    main_window.notes = fake_notes
    main_window.template = fake_template
    main_window.ui.notes = fake_note_ui

    fake_notes.render_splits.return_value = "Fake Splits"
    fake_template.render.return_value = "Fake HTML"

    main_window.update_notes(idx, refresh=True)

    used_idx = max(idx, 0)

    fake_notes.render_splits.assert_called_once_with(used_idx - 0,
                                                     used_idx + 3)
    fake_template.render.assert_called_once_with(
        font_size=main_window.settings.font_size,
        font_color=main_window.settings.font_color,
        bg_color=main_window.settings.background_color,
        css=main_window.css,
        notes="Fake Splits",
    )
    fake_note_ui.setHtml.assert_called_once_with("Fake HTML")

    assert main_window.split_index == used_idx
コード例 #5
0
def test_rc_menu_open(qtbot, fake_link):
    with patch.object(MainWindow, "show_menu") as mock_method:
        main_window = MainWindow()
        qtbot.add_widget(main_window)

        # Simulate a right click
        qtbot.mouseClick(
            main_window.ui.notes,
            QtCore.Qt.RightButton,
            pos=main_window.ui.notes.rect().center(),
        )

        mock_method.assert_called_once()
コード例 #6
0
def test_toggle_on_top(qtbot, fake_link):
    """Check the 'on top' toggle menu switches on and off correctly"""
    with patch.object(MainWindow, "show") as fake_show:
        main_window = MainWindow()
        qtbot.add_widget(main_window)

        on_top = main_window.settings.on_top
        assert on_top is False  # Default Settinng

        # Toggle On
        main_window.toggle_on_top()
        # Check settings have changed
        assert main_window.settings.on_top is True

        # Check menu item checked matches setting
        assert main_window.menu_on_top.isChecked() is True

        # Check window flag has been set
        # noinspection PyUnresolvedReferences
        assert bool(main_window.windowFlags()
                    & QtCore.Qt.WindowStaysOnTopHint) is True

        # Check window shown
        fake_show.assert_called_once()
        fake_show.reset_mock()

        # Toggle Back
        main_window.toggle_on_top()
        # Check settings have reverted
        assert main_window.settings.on_top is False

        # Check menu item checked matches setting
        assert main_window.menu_on_top.isChecked() is False

        # Check window flag has been set
        # noinspection PyUnresolvedReferences
        assert bool(main_window.windowFlags()
                    & QtCore.Qt.WindowStaysOnTopHint) is False

        # Check window shown again
        fake_show.assert_called_once()
コード例 #7
0
def test_open_settings(qtbot, fake_link):
    fake_link_inst = MagicMock()
    fake_link.return_value = fake_link_inst

    with patch("splitnotes2.ui.main_window.SettingsDialog") as fake_settings_dialog_cls, \
            patch.object(Notes, "from_file") as mock_notes:
        # Mock setup
        fake_settings_dialog = MagicMock()
        fake_settings_dialog_cls.return_value = fake_settings_dialog

        fake_settings_dialog.exec_.return_value = 1

        main_window = MainWindow()
        qtbot.add_widget(main_window)

        fake_link.assert_called_once_with(main_window.client, main_window)

        # Change hostname to trigger reconnect
        main_window.settings.hostname = "newhost"

        # Change separator to /split
        main_window.settings.split_separator = "/split"
        main_window.notefile = "fake_file"
        main_window.split_index = 2

        assert main_window.client.connection.server != main_window.settings.hostname

        main_window.open_settings()

        fake_settings_dialog.setWindowIcon.assert_called_once_with(
            main_window.icon)
        fake_settings_dialog.exec_.assert_called_once()

        fake_link_inst.close.assert_called_once()
        fake_link.assert_called_with(main_window.client, main_window)
        assert fake_link_inst.start_loops.call_count == 2

        mock_notes.assert_called_once_with("fake_file", separator="/split")
コード例 #8
0
ファイル: app.py プロジェクト: DavidCEllis/SplitNotes-2
import sys
from PySide2.QtWidgets import QApplication

from splitnotes2.ui.main_window import MainWindow

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()

    sys.exit(app.exec_())