Skip to content

Commit fcbf634

Browse files
Merge pull request #5 from source-foundry/models-updates
Update models based on qtmodeltester tests
2 parents 4ce7651 + 0b94c92 commit fcbf634

File tree

6 files changed

+50
-17
lines changed

6 files changed

+50
-17
lines changed

.github/workflows/python-ci.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ jobs:
77
runs-on: ${{ matrix.os }}
88
strategy:
99
matrix:
10-
os: [ubuntu-latest, macos-latest, windows-latest]
10+
os: [ubuntu-latest]
1111
python-version: [3.9]
12+
env:
13+
DISPLAY: ":99.0"
1214

1315
steps:
1416
- uses: actions/checkout@v2
@@ -20,7 +22,3 @@ jobs:
2022
run: |
2123
python -c "import sys; print(sys.version)"
2224
python -c "import struct; print(struct.calcsize('P') * 8)"
23-
- name: Install testing dependencies
24-
run: python -m pip install --upgrade pip setuptools wheel tox tox-gh-actions pytest pytest-qt
25-
- name: Run tox tests
26-
run: python -m tox

dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ tox
55
black
66
flake8
77
isort
8-

src/slice/models.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ def setData(self, index, value, role):
3636
return False
3737

3838
def rowCount(self, index):
39-
return len(self._data)
39+
# the index validity check approach addresses the qabstractitemmodel.cpp check:
40+
# QtWarningMsg: FAIL! model->hasChildren(topIndex) () returned FALSE (qabstractitemmodeltester.cpp:366)
41+
# See https://stackoverflow.com/a/50988188/2848172
42+
if index.isValid():
43+
return 0
44+
else:
45+
return len(self._data)
4046

4147
def columnCount(self, index):
42-
return len(self._data[0])
48+
# the index validity check approach addresses the qabstractitemmodel.cpp check:
49+
# QtWarningMsg: FAIL! model->hasChildren(topIndex) () returned FALSE (qabstractitemmodeltester.cpp:366)
50+
# See https://stackoverflow.com/a/50988188/2848172
51+
if index.isValid():
52+
return 0
53+
else:
54+
return len(self._data[0])
4355

4456
def get_data(self):
4557
return self._data
@@ -193,13 +205,18 @@ def headerData(self, section, orientation, role):
193205
return self._h_header[section]
194206

195207
def flags(self, index):
208+
# Note: index validity checks in this block address qabstractitemmodeltester error:
209+
# QtWarningMsg: FAIL! flags == Qt::ItemIsDropEnabled || flags == 0 () returned FALSE (qabstractitemmodeltester.cpp:329)
210+
196211
# column 0 (axis value range and default) is set
197212
# to non-editable
198-
if index.column() == 0:
213+
if index.isValid() and index.column() == 0:
199214
return super().flags(index) | Qt.ItemIsSelectable
200215
# column 1 (instance value) is set to editable
201-
else:
216+
elif index.isValid() and index.column() == 1:
202217
return super().flags(index) | Qt.ItemIsEditable
218+
else:
219+
return super().flags(index)
203220

204221
def load_font(self, font_model):
205222
ttfont = TTFont(font_model.fontpath)

tests/test_models.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from PyQt5.QtWidgets import QTableView
2+
3+
from slice.models import DesignAxisModel, FontModel, FontBitFlagModel, FontNameModel
4+
5+
6+
def test_font_model():
7+
fm = FontModel("testpath")
8+
assert fm.fontpath == "testpath"
9+
10+
11+
def test_designaxis_model_default(qtbot, qtmodeltester):
12+
tableview = QTableView()
13+
model = DesignAxisModel()
14+
tableview.setModel(model)
15+
qtbot.addWidget(tableview)
16+
# check model with default instantiation
17+
qtmodeltester.check(model)
18+
19+
20+
def test_designaxis_model_filled(qtbot, qtmodeltester):
21+
pass

tests/test_widgets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import pytest
2-
3-
from PyQt5.QtWidgets import QWidget
1+
from PyQt5.QtWidgets import QWidget, QApplication
42
from PyQt5.QtTest import QTest
53

64
from slice.ui.widgets import DragDropLineEdit
75

86

9-
def test_drag_drop_line_edit():
7+
def test_drag_drop_line_edit(qtbot):
108
widget1 = QWidget()
119
widget2 = DragDropLineEdit(widget1)
10+
qtbot.addWidget(widget1)
11+
qtbot.addWidget(widget2)
1212
# placeholder text
1313
assert (
1414
widget2.placeholderText() == "Drop a variable font here or click the Open button"

tox.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ envlist = py38,py39
55
commands =
66
pytest {posargs}
77
deps =
8-
-rrequirements.txt
9-
pytest
10-
pytest-qt
8+
-rdev-requirements.txt
119

1210
[gh-actions]
1311
python =

0 commit comments

Comments
 (0)