Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt model tester #63

Merged
merged 63 commits into from Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
507929b
WIP Qt model tester.
The-Compiler Jul 17, 2015
9f37d1d
Fix compatibility for PySide and PyQt4
nicoddemus Jul 22, 2015
c218dc8
Adding new qt_compat functions when building docs in rtd
nicoddemus Jul 22, 2015
b948ead
Rename methods slightly to ensure a thin public API for ModelTester f…
nicoddemus Sep 1, 2015
f8ed6be
Merge remote-tracking branch 'origin/master' into modeltest
nicoddemus Sep 1, 2015
d1f1b53
Add debug() function which uses pytest's verbose config
nicoddemus Sep 1, 2015
25c5785
Fix index in test_modeltest.py.
The-Compiler Sep 1, 2015
4533fc9
Merge branch 'master' into modeltest
nicoddemus Sep 7, 2015
7447a22
Add more tests for qtmodeltester
nicoddemus Sep 8, 2015
768209c
Add docs for qtmodeltester and CHANGELOG
nicoddemus Sep 8, 2015
7882122
Pass USER and USERNAME in tox, required by pytest's master
nicoddemus Sep 8, 2015
c633016
Increase tolerance for timeout checking in test_wait_signal
nicoddemus Sep 8, 2015
9c7c22f
Change models after calling check() to improve coverage
nicoddemus Sep 8, 2015
52e6477
Add `` around method names in modeltester's documentation
nicoddemus Sep 8, 2015
19c3411
Add `test_broken_roles` as suggested by @The-Compiler
nicoddemus Sep 8, 2015
b180176
Refactor some common PyQt4 and PyQt5 imports
nicoddemus Sep 8, 2015
f60fbf9
Add check that data() doesn't return QVariant, unless the user explic…
nicoddemus Sep 9, 2015
803f228
Test qvariant related functions from qt_compat across all Qt bindings
nicoddemus Sep 9, 2015
f6b44bc
Add model test for Alignment role in data() method
nicoddemus Sep 9, 2015
38fa79c
Implement workarounds for private model methods in PySide
nicoddemus Sep 10, 2015
7620b84
Refactor custom model tests to use inline models instead of `testdir`…
nicoddemus Sep 10, 2015
77a9cf2
Small code coverage adjustments
nicoddemus Sep 10, 2015
c10ce04
Replace data_may_return_qvariant by data_display_may_return_none
nicoddemus Sep 10, 2015
b4b8764
Cover header changes in models
nicoddemus Sep 10, 2015
4f96e18
Run dos2unix over all files
The-Compiler Jun 28, 2016
d3adbab
Merge branch 'master' into modeltest-old
The-Compiler Jun 28, 2016
24008bb
Remove unnecessary imports
The-Compiler Jun 28, 2016
a860d4a
Add comment for _cleanup
The-Compiler Jun 25, 2016
777a158
Cherry-pick tests from modeltest branch
The-Compiler Jun 25, 2016
062e3e3
Re-add None-check in ModelTester._cleanup
The-Compiler Jun 28, 2016
5561cc4
Remove casting of models
The-Compiler Jun 28, 2016
3881b51
Fix test_fetch_more
The-Compiler Jun 28, 2016
b8b3599
Fix parent handling in _on_rows_removed/inserted
The-Compiler Jun 28, 2016
5d36a9d
Fix on_layout_changed for Python 2
The-Compiler Jun 28, 2016
2654425
Fix super call for Python 2
The-Compiler Jun 28, 2016
a830c7a
Fix qt_compat.make_variant with pyqt4v2
The-Compiler Jun 28, 2016
08c2177
Revert "Fix parent handling in _on_rows_removed/inserted"
The-Compiler Jun 29, 2016
874dccb
Improve handling of verbose
The-Compiler Jun 29, 2016
e74be4e
Improve debugging output
The-Compiler Jun 29, 2016
ee0a450
Turn on verbose in test_modeltest
The-Compiler Jun 29, 2016
ffd985c
Show message without verbose
The-Compiler Jun 29, 2016
1518ce5
Revert "Revert "Fix parent handling in _on_rows_removed/inserted""
The-Compiler Jun 29, 2016
8f6e8cf
Improve data logging for QVariant
The-Compiler Jun 29, 2016
7f27cb1
Disable make_variant on Python 2 as well
The-Compiler Jun 29, 2016
b7095ae
Fix extract_from_variant calls
The-Compiler Jun 29, 2016
95ef07d
Skip modeltest parent checks on Qt4
The-Compiler Jun 29, 2016
bd5b3c7
Make version checks work with PySide
The-Compiler Jun 29, 2016
b7604ef
Version fixup
The-Compiler Jun 29, 2016
5375847
Spelling fix
The-Compiler Jun 29, 2016
5eae373
Add debugging output for rowsRemoved
The-Compiler Jun 29, 2016
e05bb2b
pep8-ify some identifiers
The-Compiler Jun 29, 2016
0590fba
Improve test coverage
The-Compiler Jun 29, 2016
ecc34f9
Fix off-by-one error
The-Compiler Jun 29, 2016
1c31124
Fix checking for alignment roles
The-Compiler Jun 29, 2016
5e158da
Add a test for a model returning an invalid parent
The-Compiler Jun 29, 2016
161c9f0
Fix indentation
The-Compiler Jun 29, 2016
3e5669e
Remove some commented-out code
The-Compiler Jun 29, 2016
8a3466b
Comment/docstring style fixes
The-Compiler Jun 29, 2016
2537651
Clean up handling of fetchMore
The-Compiler Jun 29, 2016
3404351
Adjust versionadded
The-Compiler Jun 29, 2016
5c758c5
Get rid of 'verbose' argument
The-Compiler Jun 29, 2016
0f3ce42
Fix typos in docs
The-Compiler Jun 29, 2016
444c958
Remove test_file_system_model
The-Compiler Jun 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -6,7 +6,12 @@ New

* From this version onward, ``pytest-qt`` is licensed under the MIT license (`#134`_).

* New ``qtmodeltester`` fixture to test ``QAbstractItemModel`` subclasses.
Thanks `@The-Compiler`_ for the initiative and port of the original C++ code
for ModelTester (`#63`_).

.. _#134: https://github.com/pytest-dev/pytest-qt/issues/134
.. _#63: https://github.com/pytest-dev/pytest-qt/pull/63


Breaking changes
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -21,6 +21,7 @@ pytest-qt
logging
signals
virtual_methods
modeltester
app_exit
reference
changelog
Expand Down
55 changes: 55 additions & 0 deletions docs/modeltester.rst
@@ -0,0 +1,55 @@
Model Tester
============

.. versionadded:: 2.0

``pytest-qt`` includes a fixture that helps testing
`QAbstractItemModel`_ implementations. The implementation is copied
from the C++ code as described on the `Qt Wiki <http://wiki.qt.io/Model_Test>`_,
and it continuously checks a model as it changes, helping to verify the state
and catching many common errors the moment they show up.

Some of the conditions caught include:

* Verifying X number of rows have been inserted in the correct place after the signal ``rowsAboutToBeInserted()`` says X rows will be inserted.
* The parent of the first index of the first row is a ``QModelIndex()``
* Calling ``index()`` twice in a row with the same values will return the same ``QModelIndex``
* If ``rowCount()`` says there are X number of rows, model test will verify that is true.
* Many possible off by one bugs
* ``hasChildren()`` returns true if ``rowCount()`` is greater then zero.
* and many more...

To use it, create an instance of your model implementation, fill it with some
items and call ``qtmodeltester.check``:

.. code-block:: python

def test_standard_item_model(qtmodeltester):
model = QStandardItemModel()
items = [QStandardItem(str(i)) for i in range(4)]
model.setItem(0, 0, items[0])
model.setItem(0, 1, items[1])
model.setItem(1, 0, items[2])
model.setItem(1, 1, items[3])
qtmodeltester.check(model)

If the tester finds a problem the test will fail with an assert pinpointing
the issue.

The following attribute may influence the outcome of the check depending
on your model implementation:

* ``data_display_may_return_none`` (default: ``False``): While you can
technically return ``None`` (or an invalid ``QVariant``) from ``data()``
for ``QtCore.Qt.DisplayRole``, this usually is a sign of
a bug in your implementation. Set this variable to ``True`` if this really
is OK in your model.

The source code was ported from `modeltest.cpp`_ by `Florian Bruhin`_, many
thanks!

.. _modeltest.cpp: http://code.qt.io/cgit/qt/qtbase.git/tree/tests/auto/other/modeltest/modeltest.cpp

.. _Florian Bruhin: https://github.com/The-Compiler

.. _QAbstractItemModel: http://doc.qt.io/qt-5/qabstractitemmodel.html