From 26ebcd496d9b7fef51b64c7fc9ab65f815d704d8 Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Thu, 1 Oct 2020 20:34:48 +0200
Subject: [PATCH] Improve itemEditor test, and refactor actions
---
.github/workflows/syntax.yml | 2 +-
.../{pytest_3_6.yml => test_linux_3.6.yml} | 12 +++----
.../{pytest_3_7.yml => test_linux_3.7.yml} | 12 +++----
...{pytest_3_8_cov.yml => test_linux_3.8.yml} | 12 +++----
.../{pytest_mac_3_8.yml => test_mac.yml} | 6 +++-
.github/workflows/test_win.yml | 32 +++++++++++++++++++
nw/gui/docmerge.py | 2 +-
nw/gui/docsplit.py | 4 +--
nw/gui/projtree.py | 4 +--
nw/guimain.py | 15 ++++-----
tests/reference/gui/3_nwProject.nwx | 4 +--
tests/test_dialogs.py | 24 +++++++++++---
tests/test_gui.py | 2 ++
13 files changed, 91 insertions(+), 40 deletions(-)
rename .github/workflows/{pytest_3_6.yml => test_linux_3.6.yml} (75%)
rename .github/workflows/{pytest_3_7.yml => test_linux_3.7.yml} (75%)
rename .github/workflows/{pytest_3_8_cov.yml => test_linux_3.8.yml} (77%)
rename .github/workflows/{pytest_mac_3_8.yml => test_mac.yml} (83%)
create mode 100644 .github/workflows/test_win.yml
diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml
index f697c4ec..038480f7 100644
--- a/.github/workflows/syntax.yml
+++ b/.github/workflows/syntax.yml
@@ -13,7 +13,7 @@ jobs:
- name: Python Setup
uses: actions/setup-python@v1
with:
- python-version: 3.7
+ python-version: 3
architecture: x64
- name: Checkout Source
uses: actions/checkout@v2
diff --git a/.github/workflows/pytest_3_6.yml b/.github/workflows/test_linux_3.6.yml
similarity index 75%
rename from .github/workflows/pytest_3_6.yml
rename to .github/workflows/test_linux_3.6.yml
index 058a1281..20398b22 100644
--- a/.github/workflows/pytest_3_6.yml
+++ b/.github/workflows/test_linux_3.6.yml
@@ -1,4 +1,4 @@
-name: python 3.6
+name: Linux (3.6)
on:
push:
@@ -7,7 +7,7 @@ on:
branches: [ main, dev ]
jobs:
- pyTest36:
+ testLinux36:
runs-on: ubuntu-latest
steps:
- name: Python Setup
@@ -18,16 +18,16 @@ jobs:
- name: Install Packages
run: |
sudo apt update
- sudo apt install xvfb libenchant-dev qt5-default
+ sudo apt install 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-timeout
- pip install pytest-xvfb
pip install pytest-qt
- name: Run Tests
- run: xvfb-run pytest -v --timeout=60
+ run: |
+ export QT_QPA_PLATFORM=offscreen
+ pytest -v --timeout=60
diff --git a/.github/workflows/pytest_3_7.yml b/.github/workflows/test_linux_3.7.yml
similarity index 75%
rename from .github/workflows/pytest_3_7.yml
rename to .github/workflows/test_linux_3.7.yml
index 4de6d2aa..5652a626 100644
--- a/.github/workflows/pytest_3_7.yml
+++ b/.github/workflows/test_linux_3.7.yml
@@ -1,4 +1,4 @@
-name: python 3.7
+name: Linux (3.7)
on:
push:
@@ -7,7 +7,7 @@ on:
branches: [ main, dev ]
jobs:
- pyTest37:
+ testLinux37:
runs-on: ubuntu-latest
steps:
- name: Python Setup
@@ -18,16 +18,16 @@ jobs:
- name: Install Packages
run: |
sudo apt update
- sudo apt install xvfb libenchant-dev qt5-default
+ sudo apt install 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-timeout
- pip install pytest-xvfb
pip install pytest-qt
- name: Run Tests
- run: xvfb-run pytest -v --timeout=60
+ run: |
+ export QT_QPA_PLATFORM=offscreen
+ pytest -v --timeout=60
diff --git a/.github/workflows/pytest_3_8_cov.yml b/.github/workflows/test_linux_3.8.yml
similarity index 77%
rename from .github/workflows/pytest_3_8_cov.yml
rename to .github/workflows/test_linux_3.8.yml
index 547c6938..502de464 100644
--- a/.github/workflows/pytest_3_8_cov.yml
+++ b/.github/workflows/test_linux_3.8.yml
@@ -1,4 +1,4 @@
-name: python 3.8
+name: Linux (3.8)
on:
push:
@@ -7,7 +7,7 @@ on:
branches: [ main, dev ]
jobs:
- pyTest38Cov:
+ testLinux38:
runs-on: ubuntu-latest
steps:
- name: Python Setup
@@ -18,20 +18,20 @@ jobs:
- name: Install Packages
run: |
sudo apt update
- sudo apt install xvfb libenchant-dev qt5-default
+ sudo apt install 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-timeout
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 --timeout=60
+ run: |
+ export QT_QPA_PLATFORM=offscreen
+ pytest -v --timeout=60
- name: Upload to Codecov
uses: codecov/codecov-action@v1
diff --git a/.github/workflows/pytest_mac_3_8.yml b/.github/workflows/test_mac.yml
similarity index 83%
rename from .github/workflows/pytest_mac_3_8.yml
rename to .github/workflows/test_mac.yml
index 41ac19ac..0478bf71 100644
--- a/.github/workflows/pytest_mac_3_8.yml
+++ b/.github/workflows/test_mac.yml
@@ -7,7 +7,7 @@ on:
branches: [ main, dev ]
jobs:
- pyTestMac38:
+ testMac38:
runs-on: macos-latest
steps:
- name: Python Setup
@@ -25,8 +25,12 @@ jobs:
pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-timeout
+ pip install pytest-cov
pip install pytest-qt
+ pip install codecov
- name: Run Tests
run: |
export QT_QPA_PLATFORM=offscreen
pytest -v --timeout=60
+ - name: Upload to Codecov
+ uses: codecov/codecov-action@v1
diff --git a/.github/workflows/test_win.yml b/.github/workflows/test_win.yml
new file mode 100644
index 00000000..aa9ef284
--- /dev/null
+++ b/.github/workflows/test_win.yml
@@ -0,0 +1,32 @@
+name: Windows (3.8)
+
+on:
+ push:
+ branches: [ main, dev ]
+ pull_request:
+ branches: [ main, dev ]
+
+jobs:
+ testWin38:
+ runs-on: windows-latest
+ steps:
+ - name: Python Setup
+ uses: actions/setup-python@v1
+ with:
+ python-version: 3.8
+ architecture: x64
+ - name: Checkout Source
+ uses: actions/checkout@v2
+ - name: Install Dependencies
+ run: |
+ pip install --upgrade pip
+ pip install -r requirements.txt
+ pip install pytest-timeout
+ pip install pytest-cov
+ pip install pytest-qt
+ pip install codecov
+ - name: Run Tests
+ run: |
+ pytest -v --timeout=60
+ - name: Upload to Codecov
+ uses: codecov/codecov-action@v1
diff --git a/nw/gui/docmerge.py b/nw/gui/docmerge.py
index 786eb429..2418a161 100644
--- a/nw/gui/docmerge.py
+++ b/nw/gui/docmerge.py
@@ -133,7 +133,7 @@ class GuiDocMerge(QDialog):
theDoc.openDocument(nHandle, False)
theDoc.saveDocument(theText)
- self.theParent.treeView.revealTreeItem(nHandle)
+ self.theParent.treeView.revealNewTreeItem(nHandle)
self.theParent.openDocument(nHandle, doScroll=True)
self._doClose()
diff --git a/nw/gui/docsplit.py b/nw/gui/docsplit.py
index 836fd5cb..3f497c18 100644
--- a/nw/gui/docsplit.py
+++ b/nw/gui/docsplit.py
@@ -178,7 +178,7 @@ class GuiDocSplit(QDialog):
fHandle = self.theProject.newFolder(
srcItem.itemName, srcItem.itemClass, srcItem.parHandle
)
- self.theParent.treeView.revealTreeItem(fHandle)
+ self.theParent.treeView.revealNewTreeItem(fHandle)
logger.verbose("Creating folder %s" % fHandle)
# Loop through, and create the files
@@ -213,7 +213,7 @@ class GuiDocSplit(QDialog):
theDoc.openDocument(nHandle, False)
theDoc.saveDocument(theText)
theDoc.clearDocument()
- self.theParent.treeView.revealTreeItem(nHandle)
+ self.theParent.treeView.revealNewTreeItem(nHandle)
self._doClose()
diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py
index 65c4bb1f..dfada052 100644
--- a/nw/gui/projtree.py
+++ b/nw/gui/projtree.py
@@ -240,12 +240,12 @@ class GuiProjectTree(QTreeWidget):
# Add the new item to the tree
if tHandle is not None:
- self.revealTreeItem(tHandle, nHandle)
+ self.revealNewTreeItem(tHandle, nHandle)
self.theParent.editItem(tHandle)
return True
- def revealTreeItem(self, tHandle, nHandle=None):
+ def revealNewTreeItem(self, tHandle, nHandle=None):
"""Reveal a newly added project item in the project tree.
"""
nwItem = self.theProject.projTree[tHandle]
diff --git a/nw/guimain.py b/nw/guimain.py
index bfb02bd5..5f237bb7 100644
--- a/nw/guimain.py
+++ b/nw/guimain.py
@@ -659,14 +659,13 @@ class GuiMain(QMainWindow):
return
logger.verbose("Requesting change to item %s" % tHandle)
- if self.mainConf.showGUI:
- dlgProj = GuiItemEditor(self, self.theProject, tHandle)
- dlgProj.exec_()
- if dlgProj.result() == QDialog.Accepted:
- self.treeView.setTreeItemValues(tHandle)
- self.treeMeta.updateViewBox(tHandle)
- self.docEditor.updateDocInfo(tHandle)
- self.docViewer.updateDocInfo(tHandle)
+ dlgProj = GuiItemEditor(self, self.theProject, tHandle)
+ dlgProj.exec_()
+ if dlgProj.result() == QDialog.Accepted:
+ self.treeView.setTreeItemValues(tHandle)
+ self.treeMeta.updateViewBox(tHandle)
+ self.docEditor.updateDocInfo(tHandle)
+ self.docViewer.updateDocInfo(tHandle)
return
diff --git a/tests/reference/gui/3_nwProject.nwx b/tests/reference/gui/3_nwProject.nwx
index cb018a6a..7bcf7553 100644
--- a/tests/reference/gui/3_nwProject.nwx
+++ b/tests/reference/gui/3_nwProject.nwx
@@ -44,7 +44,7 @@
ROOT
NOVEL
New
- False
+ True
-
Title Page
@@ -63,7 +63,7 @@
FOLDER
NOVEL
New
- False
+ True
-
New Chapter
diff --git a/tests/test_dialogs.py b/tests/test_dialogs.py
index f5e7da10..a71653ee 100644
--- a/tests/test_dialogs.py
+++ b/tests/test_dialogs.py
@@ -139,7 +139,7 @@ def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, nwR
nwGUI.closeMain()
@pytest.mark.gui
-def testItemEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
+def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -150,8 +150,16 @@ def testItemEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI.theProject.projTree.setSeed(42)
assert nwGUI.newProject({"projPath": nwFuncTemp})
assert nwGUI.openDocument("0e17daca5f3e1")
+ assert nwGUI.treeView.setSelectedHandle("0e17daca5f3e1", doScroll=True)
+
+ monkeypatch.setattr(GuiItemEditor, "exec_", lambda *args: None)
+ nwGUI.mainMenu.aEditItem.activate(QAction.Trigger)
+ qtbot.waitUntil(lambda: getGuiItem("GuiItemEditor") is not None, timeout=1000)
+
+ itemEdit = getGuiItem("GuiItemEditor")
+ assert isinstance(itemEdit, GuiItemEditor)
+ itemEdit.show()
- itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "0e17daca5f3e1")
qtbot.addWidget(itemEdit)
assert itemEdit.editName.text() == "New Scene"
@@ -168,7 +176,13 @@ def testItemEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
assert not itemEdit.editExport.isChecked()
itemEdit._doSave()
- itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "0e17daca5f3e1")
+ nwGUI.mainMenu.aEditItem.activate(QAction.Trigger)
+ qtbot.waitUntil(lambda: getGuiItem("GuiItemEditor") is not None, timeout=1000)
+
+ itemEdit = getGuiItem("GuiItemEditor")
+ assert isinstance(itemEdit, GuiItemEditor)
+ itemEdit.show()
+
qtbot.addWidget(itemEdit)
assert itemEdit.editName.text() == "Just a Page"
assert itemEdit.editStatus.currentData() == "Note"
@@ -194,8 +208,8 @@ def testItemEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
copyfile(projFile, testFile)
assert cmpFiles(testFile, refFile, [2, 6, 7, 8])
- nwGUI.closeMain()
# qtbot.stopForInteraction()
+ nwGUI.closeMain()
@pytest.mark.gui
def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTemp):
@@ -857,7 +871,7 @@ def testNewProjectWizard(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp):
# Final Page
finalPage = nwWiz.currentPage()
assert isinstance(finalPage, ProjWizardFinalPage)
- assert nwWiz.button(QWizard.FinishButton).isEnabled()
+ assert nwWiz.button(QWizard.FinishButton).isEnabled() # But we don't click it
# Check Data
projData = nwGUI._assembleProjectWizardData(nwWiz)
diff --git a/tests/test_gui.py b/tests/test_gui.py
index 0cd9dd87..3c9221e8 100644
--- a/tests/test_gui.py
+++ b/tests/test_gui.py
@@ -64,6 +64,8 @@ def testLaunch(qtbot, nwFuncTemp, nwTemp):
["--testmode", "--logfile=%s" % logFile, "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
)
assert os.path.isfile(logFile)
+ nwGUI.closeMain()
+ nwGUI.close()
nwGUI = nw.main(
["--testmode", "--logfile=%s" % logFile, "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]