Beispiel #1
0
 def test_hookup(self, main_win: MainWindow, qtbot):
     main_win.show()
     qtbot.addWidget(main_win)
     main_win.show_find_and_replace_dialog = MagicMock()
     qtbot.keyClick(main_win.text_edit, Qt.Key_F, modifier=Qt.ControlModifier)
     qtbot.keyClick(main_win.text_edit, Qt.Key_J, modifier=(Qt.ControlModifier | Qt.ShiftModifier))
     assert main_win.show_find_and_replace_dialog.call_count == 2
Beispiel #2
0
 def test_del_missing_word(self, main_win: MainWindow, qtbot):
     main_win.show()
     qtbot.addWidget(main_win)
     main_win.delete_word_act.trigger()
     vd = main_win.findChildren(ValidatingDialog)[-1]
     qtbot.keyClicks(vd.line_edit, 'mat')
     qtbot.keyClick(vd, Qt.Key_Enter)
     assert not main_win.dict_modified
Beispiel #3
0
 def test_basic(self, main_win: MainWindow, qtbot):
     main_win.show()
     qtbot.addWidget(main_win)
     main_win.print_ = MagicMock()
     main_win.update_markdown_viewer = MagicMock()
     main_win.print_preview_markdown_act.trigger()
     assert main_win.print_.call_args.args[1] == main_win.md_text_edit
     assert main_win.print_.call_count == 1
     assert main_win.update_markdown_viewer.call_count == 1
Beispiel #4
0
 def test_clear_recent(self, mainwin_recentfiles: MainWindow, qtbot):
     mainwin_recentfiles.show()
     qtbot.addWidget(mainwin_recentfiles)
     mainwin_recentfiles.clear_recent_files_act.trigger()
     for act in mainwin_recentfiles.recent_file_acts:
         assert not act.isVisible()
     for widget in QApplication.topLevelWidgets():
         if isinstance(widget, MainWindow):
             assert not widget.clear_recent_files_act.isEnabled()
Beispiel #5
0
 def test_open_recent_hookup(self, mainwin_recentfiles: MainWindow, qtbot):
     MainWindow.open_file = MagicMock()
     mainwin_recentfiles.show()
     qtbot.addWidget(mainwin_recentfiles)
     win3: MainWindow = MainWindow.window_list[1]
     win3.close()
     assert not win3.isVisible()
     mainwin_recentfiles.recent_file_acts[1].trigger()  # ref: prior test
     MainWindow.open_file.assert_called_once_with(win3.cur_file)
Beispiel #6
0
 def test_hookup(self, main_win: MainWindow, qtbot):
     main_win.show()
     qtbot.addWidget(main_win)
     main_win.print_ = MagicMock()
     main_win.update_markdown_viewer = MagicMock()
     qtbot.keyClick(main_win.text_edit, Qt.Key_P, modifier=(Qt.ControlModifier | Qt.ShiftModifier))
     qtbot.keyClick(main_win.text_edit, Qt.Key_R, modifier=(Qt.ControlModifier | Qt.ShiftModifier))
     assert main_win.print_.call_args.args[1] == main_win.md_text_edit
     assert main_win.print_.call_count == 2
     assert main_win.update_markdown_viewer.call_count == 2
Beispiel #7
0
 def test_dock_updates_markdown_when_its_made_visible(self, main_win: MainWindow, qtbot):
     main_win.show()
     qtbot.addWidget(main_win)
     main_win.update_markdown_viewer = MagicMock()
     dock = main_win.findChild(QDockWidget)
     qtbot.keyClick(main_win.text_edit, Qt.Key_M)
     qtbot.keyClick(main_win.text_edit, Qt.Key_M, modifier=(Qt.ControlModifier | Qt.ShiftModifier))
     assert dock.isVisible()
     qtbot.keyClick(main_win.text_edit, Qt.Key_M)
     qtbot.keyClick(main_win.text_edit, Qt.Key_C, modifier=(Qt.ControlModifier | Qt.ShiftModifier))
     qtbot.keyClick(main_win.text_edit, Qt.Key_M)
     assert not dock.isVisible()
     assert main_win.update_markdown_viewer.call_count == 1
Beispiel #8
0
def mainwin_recentfiles():
    MainWindow.dict_modified = False
    MainWindow.max_recent_files = 2

    # resetting recent files
    settings = QSettings('PMA', 'OneHandTextEdit')
    settings.setValue('recent_files', [])

    src = 'test_words.txt'
    dest = 'test_out.json'
    words = ["may", "cat"]

    with open(src, 'w') as f:
        for word in words:
            f.write("%s\n" % word)

    create_regex_map([src], [True], dest)

    with open(dest) as f:
        regex_map = json.load(f)
    yield MainWindow(regex_map, dict_src=dest)

    os.remove(src)
    os.remove(dest)
    os.remove('document1.txt')
    os.remove('document2.txt')
    os.remove('document3.txt')
    # resetting recent files
    settings = QSettings('PMA', 'OneHandTextEdit')
    settings.setValue('recent_files', [])
Beispiel #9
0
def main():
    app = QApplication([])

    QApplication.setApplicationName("OneHandTextEdit")
    QApplication.setOrganizationName("PMA")

    file_name = 'regex_map.json'
    dict_src: str = QStandardPaths.locate(QStandardPaths.AppDataLocation, file_name)
    if not dict_src:
        dict_src = file_name  # TODO Change to app's packaged resource for deploy.
    with open(dict_src) as f:
        regex_map: dict = json.load(f)

    app.aboutToQuit.connect(functools.partial(save_dictionary, file_name, dict_src, regex_map))

    main_win = MainWindow(regex_map, dict_src=dict_src)
    main_win.show()
    sys.exit(app.exec_())
Beispiel #10
0
def main_win():
    MainWindow.dict_modified = False

    src = 'test_words.txt'
    dest = 'test_out.json'
    words = ["may", "cat"]

    with open(src, 'w') as f:
        for word in words:
            f.write("%s\n" % word)

    create_regex_map([src], [True], dest)

    with open(dest) as f:
        regex_map = json.load(f)
    yield MainWindow(regex_map, dict_src=dest)

    os.remove(src)
    os.remove(dest)
Beispiel #11
0
 def test_inactive_clear_recent(self, mainwin_recentfiles: MainWindow, qtbot):
     mainwin_recentfiles.show()
     qtbot.addWidget(mainwin_recentfiles)
     assert not mainwin_recentfiles.clear_recent_files_act.isEnabled()
Beispiel #12
0
 def test_doesnt_exceed_max_md_textedit_position(self, main_win: MainWindow, qtbot):
     main_win.show()
     qtbot.addWidget(main_win)
     qtbot.keyClicks(main_win.text_edit, "# hi")
     main_win.update_markdown_viewer()
     assert main_win.md_text_edit.textCursor().position() == 2