From bd430d61e3540a51d3018e29a526be4f8f87c774 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 19 Aug 2020 22:33:33 +0200 Subject: [PATCH 01/22] Added test for the project load dialog --- tests/test_gui.py | 55 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/test_gui.py b/tests/test_gui.py index d6ac126b..5c656a6b 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -9,13 +9,16 @@ from nwtools import cmpFiles from os import path from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QAction +from PyQt5.QtWidgets import QAction, QDialogButtonBox from nw.gui import ( GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel, - GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard + GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard, + GuiProjectLoad +) +from nw.constants import ( + nwItemType, nwItemLayout, nwItemClass, nwDocAction, nwUnicode ) -from nw.constants import nwItemType, nwItemLayout, nwItemClass, nwDocAction, nwUnicode keyDelay = 2 stepDelay = 20 @@ -1064,3 +1067,49 @@ def testInsertMenu(qtbot, nwTempGUI, nwFuncTemp, nwTemp): # qtbot.stopForInteraction() nwGUI.closeMain() + +@pytest.mark.gui +def testLoadProject(qtbot, nwTempGUI, nwTemp): + nwGUI = nw.main(["--testmode", "--config=%s" % nwTempGUI, "--data=%s" % nwTemp]) + qtbot.addWidget(nwGUI) + nwGUI.show() + qtbot.waitForWindowShown(nwGUI) + qtbot.wait(stepDelay) + + nwLoad = GuiProjectLoad(nwGUI) + nwLoad.show() + + recentCount = nwLoad.listBox.topLevelItemCount() + assert recentCount > 1 + + selItem = nwLoad.listBox.topLevelItem(1) + selPath = selItem.data(nwLoad.C_NAME, Qt.UserRole) + + nwLoad.selPath.setText("") + nwLoad.listBox.setCurrentItem(selItem) + assert nwLoad.selPath.text() == selPath + + qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Open), Qt.LeftButton) + assert nwLoad.openPath == selPath + assert nwLoad.openState == nwLoad.OPEN_STATE + + del nwLoad + nwLoad = GuiProjectLoad(nwGUI) + nwLoad.show() + + qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Cancel), Qt.LeftButton) + assert nwLoad.openPath is None + assert nwLoad.openState == nwLoad.NONE_STATE + + nwLoad.show() + qtbot.mouseClick(nwLoad.newButton, Qt.LeftButton) + assert nwLoad.openPath is None + assert nwLoad.openState == nwLoad.NEW_STATE + + nwLoad.show() + nwLoad._keyPressDelete() + assert nwLoad.listBox.topLevelItemCount() == recentCount - 1 + del nwLoad + + # qtbot.stopForInteraction() + nwGUI.closeMain() From d9b092b5933430b44bd7da43a01e99a074cca7ea Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 19 Aug 2020 22:50:37 +0200 Subject: [PATCH 02/22] Fixed bug where word and paragraph count was swapped in outline details panel --- nw/gui/outlinedetails.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nw/gui/outlinedetails.py b/nw/gui/outlinedetails.py index 9e53653f..6360a321 100644 --- a/nw/gui/outlinedetails.py +++ b/nw/gui/outlinedetails.py @@ -249,8 +249,8 @@ class GuiOutlineDetails(QScrollArea): self.itemValue.setText(nwItem.itemStatus) self.cCValue.setText("{:n}".format(checkInt(novIdx["cCount"], 0))) - self.wCValue.setText("{:n}".format(checkInt(novIdx["pCount"], 0))) - self.pCValue.setText("{:n}".format(checkInt(novIdx["wCount"], 0))) + self.wCValue.setText("{:n}".format(checkInt(novIdx["wCount"], 0))) + self.pCValue.setText("{:n}".format(checkInt(novIdx["pCount"], 0))) self.synopValue.setText(novIdx["synopsis"]) From 7941cbbd34953c1fa8aec4f44ade2ac52ae0bec5 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 19 Aug 2020 23:55:23 +0200 Subject: [PATCH 03/22] Added test for outline panel --- tests/lipsum/nwProject.nwx | 2 +- tests/test_gui.py | 67 +++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx index ebfbde69..d6a58a7a 100644 --- a/tests/lipsum/nwProject.nwx +++ b/tests/lipsum/nwProject.nwx @@ -48,7 +48,7 @@ True - Lorem Ipusm + Lorem Ipsum FILE NOVEL Finished diff --git a/tests/test_gui.py b/tests/test_gui.py index 5c656a6b..9f211dd9 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -8,8 +8,8 @@ import json from nwtools import cmpFiles from os import path -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QAction, QDialogButtonBox +from PyQt5.QtCore import Qt, QPoint +from PyQt5.QtWidgets import QAction, QDialogButtonBox, QTreeWidgetItem from nw.gui import ( GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel, @@ -17,7 +17,7 @@ from nw.gui import ( GuiProjectLoad ) from nw.constants import ( - nwItemType, nwItemLayout, nwItemClass, nwDocAction, nwUnicode + nwItemType, nwItemLayout, nwItemClass, nwDocAction, nwUnicode, nwOutline ) keyDelay = 2 @@ -1109,7 +1109,66 @@ def testLoadProject(qtbot, nwTempGUI, nwTemp): nwLoad.show() nwLoad._keyPressDelete() assert nwLoad.listBox.topLevelItemCount() == recentCount - 1 - del nwLoad + + nwLoad.close() + # qtbot.stopForInteraction() + nwGUI.closeMain() + +@pytest.mark.gui +def testOutline(qtbot, nwTempBuild, nwLipsum, nwTemp): + + nwGUI = nw.main(["--testmode", "--config=%s" % nwTempBuild, "--data=%s" % nwTemp]) + qtbot.addWidget(nwGUI) + nwGUI.show() + qtbot.waitForWindowShown(nwGUI) + qtbot.wait(stepDelay) + + assert nwGUI.openProject(nwLipsum) + nwGUI.mainConf.lastPath = nwTempBuild + + nwGUI.rebuildIndex() + nwGUI.tabWidget.setCurrentIndex(nwGUI.idxTabProj) + + assert nwGUI.projView.topLevelItemCount() > 0 + + # Context Menu + nwGUI.projView._headerRightClick(QPoint(1, 1)) + nwGUI.projView.headerMenu.actionMap[nwOutline.CCOUNT].activate(QAction.Trigger) + nwGUI.projView.headerMenu.close() + qtbot.mouseClick(nwGUI.projView, Qt.LeftButton) + + nwGUI.projView._loadHeaderState() + assert not nwGUI.projView.colHidden[nwOutline.CCOUNT] + + # First Item + nwGUI.rebuildOutline() + selItem = nwGUI.projView.topLevelItem(0) + assert isinstance(selItem, QTreeWidgetItem) + + nwGUI.projView.setCurrentItem(selItem) + assert nwGUI.projMeta.titleLabel.text() == "Title" + assert nwGUI.projMeta.titleValue.text() == "Lorem Ipsum" + assert nwGUI.projMeta.fileValue.text() == "Lorem Ipsum" + assert nwGUI.projMeta.itemValue.text() == "Finished" + + assert nwGUI.projMeta.cCValue.text() == "122" + assert nwGUI.projMeta.wCValue.text() == "18" + assert nwGUI.projMeta.pCValue.text() == "2" + + # Scene One + actItem = nwGUI.projView.topLevelItem(1) + chpItem = actItem.child(0) + selItem = chpItem.child(0) + + nwGUI.projView.setCurrentItem(selItem) + assert nwGUI.projMeta.titleLabel.text() == "Scene" + assert nwGUI.projMeta.titleValue.text() == "Scene One" + assert nwGUI.projMeta.fileValue.text() == "Scene One" + assert nwGUI.projMeta.itemValue.text() == "Finished" + + # Click POV Link + qtbot.mouseClick(nwGUI.projMeta.povKeyValue, Qt.LeftButton) + assert nwGUI.docViewer.theHandle == "4c4f28287af27" # qtbot.stopForInteraction() nwGUI.closeMain() From d32451be1c52438bec0d0091c8ece60198aa9459 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 00:02:56 +0200 Subject: [PATCH 04/22] Add a delay for loading the document view ite from outline --- tests/test_gui.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_gui.py b/tests/test_gui.py index 9f211dd9..662a2f6b 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -1168,6 +1168,7 @@ def testOutline(qtbot, nwTempBuild, nwLipsum, nwTemp): # Click POV Link qtbot.mouseClick(nwGUI.projMeta.povKeyValue, Qt.LeftButton) + qtbot.wait(500) assert nwGUI.docViewer.theHandle == "4c4f28287af27" # qtbot.stopForInteraction() From d1f570336945a7f5c63eb2a3440fb2dc1b9d367a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 00:11:05 +0200 Subject: [PATCH 05/22] Drop the mouseclick and just pass the value --- tests/test_gui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_gui.py b/tests/test_gui.py index 662a2f6b..e512fbca 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -1167,8 +1167,8 @@ def testOutline(qtbot, nwTempBuild, nwLipsum, nwTemp): assert nwGUI.projMeta.itemValue.text() == "Finished" # Click POV Link - qtbot.mouseClick(nwGUI.projMeta.povKeyValue, Qt.LeftButton) - qtbot.wait(500) + assert nwGUI.projMeta.povKeyValue.text() == "Bod" + nwGUI.projMeta._tagClicked("#pov=Bod") assert nwGUI.docViewer.theHandle == "4c4f28287af27" # qtbot.stopForInteraction() From 9d2563c72bd23f63fec3ff2d771a617f249334cd Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 09:54:36 +0200 Subject: [PATCH 06/22] Minor changes to flake8 check --- .github/workflows/syntax.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index c12279af..0dcd100b 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -2,9 +2,9 @@ name: Flake8 Checks on: push: - branches: [ main ] + branches: [ main, dev ] pull_request: - branches: [ main ] + branches: [ main, dev ] jobs: checkSyntax: @@ -15,13 +15,11 @@ jobs: with: python-version: 3.7 architecture: x64 - - name: Checkout novelWriter + - name: Checkout Source uses: actions/checkout@v2 - name: Install flake8 run: pip install flake8 - - name: Check for Syntax Error in novelWriter - run: flake8 nw --count --select=E9,F63,F7,F82 --show-source --statistics - - name: Check for Syntax Error in Tests - run: flake8 tests --count --select=E9,F63,F7,F82 --show-source --statistics - - name: Check for Code Style Violations - run: flake8 nw --count --max-line-length=99 --ignore E203,E221,E226,E241,E251,E261,E266,E302,E305 --show-source --statistics + - name: Syntax Error Check + run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + - name: Coding Style Violations + run: flake8 . --count --max-line-length=99 --ignore E203,E221,E226,E241,E251,E261,E266,E302,E305 --show-source --statistics From d4ccb369f4d8665ac2ea95e0ae24d8e847ad4362 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 09:56:39 +0200 Subject: [PATCH 07/22] nw and tests folders only --- .github/workflows/syntax.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index 0dcd100b..20736e91 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -20,6 +20,10 @@ jobs: - name: Install flake8 run: pip install flake8 - name: Syntax Error Check - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + run: | + flake8 nw --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 tests --count --select=E9,F63,F7,F82 --show-source --statistics - name: Coding Style Violations - run: flake8 . --count --max-line-length=99 --ignore E203,E221,E226,E241,E251,E261,E266,E302,E305 --show-source --statistics + run: | + flake8 nw --count --max-line-length=99 --ignore E203,E221,E226,E241,E251,E261,E266,E302,E305 --show-source --statistics + flake8 tests --count --max-line-length=99 --ignore E203,E221,E226,E241,E251,E261,E266,E302,E305 --show-source --statistics From e08bd436d7ed63aeb84e5d2b398d072b740cd60f Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:03:12 +0200 Subject: [PATCH 08/22] Added pytest workflow --- .github/workflows/pytest_cov.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/pytest_cov.yml diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml new file mode 100644 index 00000000..d2b260f6 --- /dev/null +++ b/.github/workflows/pytest_cov.yml @@ -0,0 +1,31 @@ +name: PyTest + Coverage + +on: + push: + branches: [ main, dev ] + pull_request: + branches: [ main, dev ] + +jobs: + pyTest: + runs-on: ubuntu-latest + steps: + - name: Python Setup + uses: actions/setup-python@v1 + with: + python-version: 3.8 + architecture: x64 + - name: Install Packages + - run: sudo apt-get install xvfb + - name: Checkout Source + uses: actions/checkout@v2 + - name: Install Dependencies + run: | + pip install -r requirements.txt + pip install PyVirtualDisplay + pip install pytest-cov + pip install pytest-xvfb + pip install pytest-qt + pip install codecov + - name: Run Tests + run: xvfb-run pytest -v --cov=nw From d7235297081b743ce2e7cead11781c9dfd4d3c10 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:04:57 +0200 Subject: [PATCH 09/22] Fix workflow file error --- .github/workflows/pytest_cov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index d2b260f6..2fd269c2 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -16,7 +16,7 @@ jobs: python-version: 3.8 architecture: x64 - name: Install Packages - - run: sudo apt-get install xvfb + run: sudo apt-get install xvfb - name: Checkout Source uses: actions/checkout@v2 - name: Install Dependencies From dc0d80c622d083fb8736983f88a41db183542a93 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:05:39 +0200 Subject: [PATCH 10/22] Disable travis while we do this --- .travis.yml => .travis.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis.yml => .travis.txt (100%) diff --git a/.travis.yml b/.travis.txt similarity index 100% rename from .travis.yml rename to .travis.txt From c0769581ea77ebfd0eaff1e25abad8755c2c523c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:09:42 +0200 Subject: [PATCH 11/22] Add more packages --- .github/workflows/pytest_cov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index 2fd269c2..cc1044cb 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -16,7 +16,7 @@ jobs: python-version: 3.8 architecture: x64 - name: Install Packages - run: sudo apt-get install xvfb + run: sudo apt install xvfb libenchant-dev python3-pyqt5 python3-pyqt5.qtsvg python3-lxml - name: Checkout Source uses: actions/checkout@v2 - name: Install Dependencies From 8b2d7e29171dbaf763f085e214034ec0b582a128 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:24:40 +0200 Subject: [PATCH 12/22] test other packages and add delays to project editor test --- .github/workflows/pytest_cov.yml | 3 ++- tests/test_gui.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index cc1044cb..8a5ceff9 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -16,11 +16,12 @@ jobs: python-version: 3.8 architecture: x64 - name: Install Packages - run: sudo apt install xvfb libenchant-dev python3-pyqt5 python3-pyqt5.qtsvg python3-lxml + run: sudo apt install xvfb libenchant-dev qt5-default # python3-pyqt5 python3-pyqt5.qtsvg python3-lxml - name: Checkout Source uses: actions/checkout@v2 - name: Install Dependencies run: | + pip install --upgrade pip pip install -r requirements.txt pip install PyVirtualDisplay pip install pytest-cov diff --git a/tests/test_gui.py b/tests/test_gui.py index e512fbca..cb6aa05e 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -297,6 +297,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): projEdit.show() qtbot.addWidget(projEdit) + qtbot.wait(stepDelay) projEdit.tabMain.editName.setText("") for c in "Project Name": qtbot.keyClick(projEdit.tabMain.editName, c, delay=keyDelay) @@ -309,6 +310,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.keyClick(projEdit.tabMain.editAuthors, c, delay=keyDelay) # Test Status Tab + qtbot.wait(stepDelay) projEdit._tabBox.setCurrentWidget(projEdit.tabStatus) projEdit.tabStatus.listBox.item(2).setSelected(True) qtbot.mouseClick(projEdit.tabStatus.delButton, Qt.LeftButton) @@ -321,6 +323,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.mouseClick(projEdit.tabStatus.saveButton, Qt.LeftButton) # Auto-Replace Tab + qtbot.wait(stepDelay) projEdit._tabBox.setCurrentWidget(projEdit.tabReplace) qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton) @@ -331,6 +334,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.keyClick(projEdit.tabReplace.editValue, c, delay=keyDelay) qtbot.mouseClick(projEdit.tabReplace.saveButton, Qt.LeftButton) + qtbot.wait(stepDelay) projEdit.tabReplace.listBox.clearSelection() qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton) projEdit.tabReplace.listBox.topLevelItem(0).setSelected(True) @@ -340,10 +344,12 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.keyClick(projEdit.tabReplace.editValue, c, delay=keyDelay) qtbot.mouseClick(projEdit.tabReplace.saveButton, Qt.LeftButton) + qtbot.wait(stepDelay) projEdit.tabReplace.listBox.clearSelection() projEdit.tabReplace.listBox.topLevelItem(0).setSelected(True) qtbot.mouseClick(projEdit.tabReplace.delButton, Qt.LeftButton) + qtbot.wait(stepDelay) projEdit._doSave() # Open again, and check project settings From d4052568be4950f08290445793dddb721db115bb Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:36:33 +0200 Subject: [PATCH 13/22] Make sure new replace items in project settings are inserted at the top --- nw/gui/projsettings.py | 2 +- tests/test_gui.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nw/gui/projsettings.py b/nw/gui/projsettings.py index 066c618f..52d82809 100644 --- a/nw/gui/projsettings.py +++ b/nw/gui/projsettings.py @@ -617,7 +617,7 @@ class GuiProjectEditReplace(QWidget): saveKey = "" % (self.listBox.topLevelItemCount() + 1) newVal = "" newItem = QTreeWidgetItem([saveKey, newVal]) - self.listBox.addTopLevelItem(newItem) + self.listBox.insertTopLevelItem(0, newItem) return True def _delEntry(self): diff --git a/tests/test_gui.py b/tests/test_gui.py index cb6aa05e..4b0d1107 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -372,8 +372,8 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): projFile = path.join(nwTempGUI, "nwProject.nwx") assert cmpFiles(projFile, path.join(nwRef, "gui", "2_nwProject.nwx"), [2, 8, 9, 10]) - nwGUI.closeMain() # qtbot.stopForInteraction() + nwGUI.closeMain() @pytest.mark.gui def testItemEditor(qtbot, nwTempGUI, nwRef, nwTemp): From cff7463a7c83b5430a5ba8b6347fbc571587c703 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:43:19 +0200 Subject: [PATCH 14/22] Make sure the correct item is selected --- nw/gui/projsettings.py | 2 +- tests/test_gui.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nw/gui/projsettings.py b/nw/gui/projsettings.py index 52d82809..066c618f 100644 --- a/nw/gui/projsettings.py +++ b/nw/gui/projsettings.py @@ -617,7 +617,7 @@ class GuiProjectEditReplace(QWidget): saveKey = "" % (self.listBox.topLevelItemCount() + 1) newVal = "" newItem = QTreeWidgetItem([saveKey, newVal]) - self.listBox.insertTopLevelItem(0, newItem) + self.listBox.addTopLevelItem(newItem) return True def _delEntry(self): diff --git a/tests/test_gui.py b/tests/test_gui.py index 4b0d1107..1f553a8c 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -337,7 +337,15 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.wait(stepDelay) projEdit.tabReplace.listBox.clearSelection() qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton) - projEdit.tabReplace.listBox.topLevelItem(0).setSelected(True) + + newIdx = -1 + for i in range(projEdit.tabReplace.listBox.topLevelItemCount()): + if projEdit.tabReplace.listBox.topLevelItem(0).text(0) == "": + newIdx = i + break + + assert newIdx >= 0 + projEdit.tabReplace.listBox.topLevelItem(newIdx).setSelected(True) for c in "Delete": qtbot.keyClick(projEdit.tabReplace.editKey, c, delay=keyDelay) for c in "This Stuff": @@ -346,7 +354,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.wait(stepDelay) projEdit.tabReplace.listBox.clearSelection() - projEdit.tabReplace.listBox.topLevelItem(0).setSelected(True) + projEdit.tabReplace.listBox.topLevelItem(newIdx).setSelected(True) qtbot.mouseClick(projEdit.tabReplace.delButton, Qt.LeftButton) qtbot.wait(stepDelay) From aef093a3e57a95bc33377e383af86caded8bc846 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:48:07 +0200 Subject: [PATCH 15/22] Try calling the function directly --- tests/test_gui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_gui.py b/tests/test_gui.py index 1f553a8c..ee2510c8 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -336,7 +336,8 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.wait(stepDelay) projEdit.tabReplace.listBox.clearSelection() - qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton) + # qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton) + projEdit.tabReplace._addEntry() newIdx = -1 for i in range(projEdit.tabReplace.listBox.topLevelItemCount()): From be0b9ef358720e8b9f8408640eca2cdf9caaeaf0 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:52:47 +0200 Subject: [PATCH 16/22] Fixed typo in test --- tests/test_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_gui.py b/tests/test_gui.py index ee2510c8..30210ecd 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -341,7 +341,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): newIdx = -1 for i in range(projEdit.tabReplace.listBox.topLevelItemCount()): - if projEdit.tabReplace.listBox.topLevelItem(0).text(0) == "": + if projEdit.tabReplace.listBox.topLevelItem(i).text(0) == "": newIdx = i break From fe15a335a94b4c73b79b17b69acfe25f25ddd9bf Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 20:59:40 +0200 Subject: [PATCH 17/22] Change item selection method --- tests/test_gui.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/test_gui.py b/tests/test_gui.py index 30210ecd..f7104308 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -336,8 +336,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): qtbot.wait(stepDelay) projEdit.tabReplace.listBox.clearSelection() - # qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton) - projEdit.tabReplace._addEntry() + qtbot.mouseClick(projEdit.tabReplace.addButton, Qt.LeftButton) newIdx = -1 for i in range(projEdit.tabReplace.listBox.topLevelItemCount()): @@ -346,16 +345,8 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp): break assert newIdx >= 0 - projEdit.tabReplace.listBox.topLevelItem(newIdx).setSelected(True) - for c in "Delete": - qtbot.keyClick(projEdit.tabReplace.editKey, c, delay=keyDelay) - for c in "This Stuff": - qtbot.keyClick(projEdit.tabReplace.editValue, c, delay=keyDelay) - qtbot.mouseClick(projEdit.tabReplace.saveButton, Qt.LeftButton) - - qtbot.wait(stepDelay) - projEdit.tabReplace.listBox.clearSelection() - projEdit.tabReplace.listBox.topLevelItem(newIdx).setSelected(True) + newItem = projEdit.tabReplace.listBox.topLevelItem(newIdx) + projEdit.tabReplace.listBox.setCurrentItem(newItem) qtbot.mouseClick(projEdit.tabReplace.delButton, Qt.LeftButton) qtbot.wait(stepDelay) From 15757a745b1cbf64a205c8f941e5f76d78138e9b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 21:07:11 +0200 Subject: [PATCH 18/22] Add codecov part tp action --- .github/workflows/pytest_cov.yml | 6 +++--- README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index 8a5ceff9..7f829bc6 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -1,8 +1,6 @@ name: PyTest + Coverage on: - push: - branches: [ main, dev ] pull_request: branches: [ main, dev ] @@ -16,7 +14,7 @@ jobs: python-version: 3.8 architecture: x64 - name: Install Packages - run: sudo apt install xvfb libenchant-dev qt5-default # python3-pyqt5 python3-pyqt5.qtsvg python3-lxml + run: sudo apt install xvfb libenchant-dev qt5-default - name: Checkout Source uses: actions/checkout@v2 - name: Install Dependencies @@ -30,3 +28,5 @@ jobs: pip install codecov - name: Run Tests run: xvfb-run pytest -v --cov=nw + - name: Upload to Codecov + uses: codecov/codecov-action@v1 diff --git a/README.md b/README.md index 3c60e951..7adc676f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # novelWriter -[![Build Status](https://travis-ci.com/vkbo/novelWriter.svg?branch=main)](https://travis-ci.com/vkbo/novelWriter) +[![PyTest + Coverage](https://github.com/vkbo/novelWriter/workflows/PyTest%20+%20Coverage/badge.svg?branch=main)](https://github.com/vkbo/novelWriter/actions) [![codecov](https://codecov.io/gh/vkbo/novelWriter/branch/main/graph/badge.svg)](https://codecov.io/gh/vkbo/novelWriter) [![Documentation Status](https://readthedocs.org/projects/novelwriter/badge/?version=latest)](https://novelwriter.readthedocs.io/en/latest/?badge=latest) [![Flake8 Checks](https://github.com/vkbo/novelWriter/workflows/Flake8%20Checks/badge.svg)](https://github.com/vkbo/novelWriter/actions) From 3fa21688aa421ea615a5e38b082bb632a77d7aa8 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 21:14:39 +0200 Subject: [PATCH 19/22] Added second job step with other python versions --- .github/workflows/pytest_cov.yml | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index 7f829bc6..535c8012 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -1,11 +1,11 @@ -name: PyTest + Coverage +name: PyTest (3.8) + Coverage on: pull_request: branches: [ main, dev ] jobs: - pyTest: + pyTestCov: runs-on: ubuntu-latest steps: - name: Python Setup @@ -30,3 +30,27 @@ jobs: run: xvfb-run pytest -v --cov=nw - name: Upload to Codecov uses: codecov/codecov-action@v1 + pyTest: + strategy: + matrix: + python-version: [3.5, 3.6, 3.7] + runs-on: ubuntu-latest + steps: + - name: Python Setup + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 + - name: Install Packages + run: sudo apt install xvfb libenchant-dev qt5-default + - name: Checkout Source + uses: actions/checkout@v2 + - name: Install Dependencies + run: | + pip install --upgrade pip + pip install -r requirements.txt + pip install PyVirtualDisplay + pip install pytest-xvfb + pip install pytest-qt + - name: Run Tests + run: xvfb-run pytest -v From c3da3e3cce6704d5fa1db3ce133cf911491a8b1a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 21:18:43 +0200 Subject: [PATCH 20/22] Added test dependencies and dropped Python 3.5 --- .github/workflows/pytest_cov.yml | 7 +++++-- .github/workflows/syntax.yml | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index 535c8012..bc997074 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -1,4 +1,4 @@ -name: PyTest (3.8) + Coverage +name: PyTest + Coverage on: pull_request: @@ -6,6 +6,7 @@ on: jobs: pyTestCov: + needs: checkSyntax runs-on: ubuntu-latest steps: - name: Python Setup @@ -30,10 +31,12 @@ jobs: run: xvfb-run pytest -v --cov=nw - name: Upload to Codecov uses: codecov/codecov-action@v1 + pyTest: + needs: pyTestCov strategy: matrix: - python-version: [3.5, 3.6, 3.7] + python-version: [3.6, 3.7] runs-on: ubuntu-latest steps: - name: Python Setup diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index 20736e91..51aae813 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -23,6 +23,20 @@ jobs: run: | flake8 nw --count --select=E9,F63,F7,F82 --show-source --statistics flake8 tests --count --select=E9,F63,F7,F82 --show-source --statistics + + checkStyle: + needs: checkSyntax + runs-on: ubuntu-latest + steps: + - name: Python Setup + uses: actions/setup-python@v1 + with: + python-version: 3.7 + architecture: x64 + - name: Checkout Source + uses: actions/checkout@v2 + - name: Install flake8 + run: pip install flake8 - name: Coding Style Violations run: | flake8 nw --count --max-line-length=99 --ignore E203,E221,E226,E241,E251,E261,E266,E302,E305 --show-source --statistics From 305e5cdf55f68e599be2f006ccd1829bed9be76d Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 21:21:00 +0200 Subject: [PATCH 21/22] That didn't work ... trying something else --- .github/workflows/pytest_cov.yml | 1 - .github/workflows/syntax.yml | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index bc997074..593a1a79 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -6,7 +6,6 @@ on: jobs: pyTestCov: - needs: checkSyntax runs-on: ubuntu-latest steps: - name: Python Setup diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index 51aae813..20736e91 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -23,20 +23,6 @@ jobs: run: | flake8 nw --count --select=E9,F63,F7,F82 --show-source --statistics flake8 tests --count --select=E9,F63,F7,F82 --show-source --statistics - - checkStyle: - needs: checkSyntax - runs-on: ubuntu-latest - steps: - - name: Python Setup - uses: actions/setup-python@v1 - with: - python-version: 3.7 - architecture: x64 - - name: Checkout Source - uses: actions/checkout@v2 - - name: Install flake8 - run: pip install flake8 - name: Coding Style Violations run: | flake8 nw --count --max-line-length=99 --ignore E203,E221,E226,E241,E251,E261,E266,E302,E305 --show-source --statistics From b3da2b70296e4c580406ea5f4a0bdf367f6f582b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Aug 2020 21:24:35 +0200 Subject: [PATCH 22/22] Final version of pytest workflow --- .github/workflows/pytest_cov.yml | 2 +- .travis.txt | 57 -------------------------------- 2 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 .travis.txt diff --git a/.github/workflows/pytest_cov.yml b/.github/workflows/pytest_cov.yml index 593a1a79..8e60f72b 100644 --- a/.github/workflows/pytest_cov.yml +++ b/.github/workflows/pytest_cov.yml @@ -1,4 +1,4 @@ -name: PyTest + Coverage +name: PyTest on: pull_request: diff --git a/.travis.txt b/.travis.txt deleted file mode 100644 index b0b45ee9..00000000 --- a/.travis.txt +++ /dev/null @@ -1,57 +0,0 @@ -os: linux -dist: focal -services: - - xvfb -language: python -cache: - - bundler - -addons: - apt: - packages: - - libenchant-dev - - python3-pyqt5 - - python3-pyqt5.qtsvg - - python3-lxml - -install: -# - pip install --upgrade pip - - pip install -r requirements.txt - - pip install PyVirtualDisplay - - pip install pytest-cov - - pip install pytest-xvfb - - pip install pytest-qt - - pip install codecov - -stages: - - name: Main - - name: Supported -# - name: Future -# if: branch = main - -jobs: - include: - - stage: Main - python: 3.8 - script: - - python -m pytest --cov=nw -v - after_success: - - codecov - after_failure: - - cat /sys/fs/cgroup/memory/memory.max_usage_in_bytes - - - stage: Supported - python: 3.6 - script: - - python -m pytest -v - - - python: 3.7 - script: - - python -m pytest -v - -# - stage: -# - Future -# python: -# - 3.9-dev -# script: -# - python -m pytest -v