-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Qt model tester #63
Conversation
cc @bgr |
Thanks @The-Compiler, I will take a look and probably start working on it tomorrow. |
Hi @The-Compiler, only today I could take a look at the code, sorry about that. I like the work so far, I think it would be a nice addition to pytest-qt, thanks for the initiative and having this so far down the road already! A few comments the points you raised:
|
9ff298d
to
a20165a
Compare
Regarding pytest integration, there's another big issue in my view: The tests should be re-run automatically if the model changes, as there are also some tests checking if that happens properly. So I should be able to set a model (which will run the tests), and then for example insert some items into the model and the tests should re-run to see the inserting worked well. |
Hmm I see. But shouldn't that be part of the standard tests? I mean, we could add a new standard test which automatically changes the model (adding new items) and re-runs the tests. Of course it should be generic as to work with any model. Aside from the issue above, I have thought about how to integrate this better in pytest and thought the following: Create a a base class which contains all the tests, which will depend on an undeclared fixture, say qmodel: class BaseModelTestCollection:
def test_basic(self, qmodel):
def test_column_count(self, qmodel):
def test_has_index(self, qmodel):
def test_index(self, qmodel):
def test_data(self, qmodel): Because of how the class is named, it won't get collected by pytest. To test a specific implementation, a user has to subclass it and implement the fixture in the class: class TestMyModel(BaseModelTestCollection):
@pytest.fixture
def qmodel(self):
return MyModelImplementation(...) I think the advantage here is that one can easily add new test methods if they are specific to their class, other fixtures can be used if needed when implementing the What do you think? |
Any more input here @The-Compiler? 😄 |
Whoops, sorry for the delay!
I'll have to think more about that - I think there could be many models which don't support inserting data from the outside. Models are basically just the data behind some kind of view. Imagine you'd want to test a QFileSystemModel - you can't insert/remove items as part of the test, but you might want to set a different file filter with the tester "attached" and see if the model removes/adds items correctly. As for the pytest integration - that sounds good, but probably won't work because of the "changing model" issue. |
# Conflicts: # pytestqt/plugin.py # pytestqt/qt_compat.py
@The-Compiler did a little more work on it:
After taking a closer look at the code, I decided against moving forward with my previous idea of having a base class with tests and using a fixture to provide a model, because 1) this would change the code quite a bit, and would make it harder to port changes or fixes from the original code and 2) I just realized that So I'm planning to release something closer to what it was originally. We can try to come up with a solution for the "model modification" problem later, but I suspect now the user can simply call What do you think? |
Nice, thank you! I'd leave it as-is, i.e. with the automatic rechecking when the model changes. I don't know the exact reason why the original source did it that way, but I'm guessing there was some reason for it 😉 So what's left to do here? I think it definitely needs some more tests (I'll try to work on that this week, but no promises - I need to fix some qutebrowser bugs and release a new version). Other than that there's some Thanks for all your work on this! |
I was thinking of testing some (all?) Qt's builtin model classes... do you have something else in mind?
I will take care of the missing |
These will all pass, hopefully - I'm thinking of having some custom
Those were added by me as I was unsure what to do with the While you're at it: Could you also add a link to the original implementation somewhere as a comment? http://code.qt.io/cgit/qt/qtbase.git/tree/tests/auto/other/modeltest/modeltest.cpp |
Model Tester | ||
============ | ||
|
||
.. versionadded:: 1.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.0
now 😄
LGTM, do you feel this is ready for merging? I will later (just woke up 😆) work on making the lazy API and wait Until, but this needs to be merged first because it will conflict a lot with the lazy API work. |
Two things are still open in my view:
|
Oh yeah, sorry:
I agree, let's leave it as it is for now.
Agree with you, don't really seem that much useful. And we can decide to add this later anyway. I just cancelled a lot of the piled up builds on AppVeyor, let's see how this goes. 😁 |
That seems contradicting itself - currently we only display the output with
Though if we want |
Oh sorry, I read that wrong and thought we were already displaying the debug output regardless of verbose. Let's go with your gut feeling then, since you have been working on this lately. |
Long time since I wrote that and didn't remember exactly what the proposal was in the first place. My initial thought was that I don't know, perhaps I'm overthinking this and just |
The output will only be shown on errors anyways, and it's very useful if there's a problem.
I pushed a commit removing the
That's what I think currently, yeah. As long as things are documented that way, I think it's fine. |
Restarted AppVeyor build because it failed to download PyQt5 installer from source forge... 😓 We probably should use |
Not sure if AppVeyor or sourceforge is worse 😆 |
Heh! 😆 |
After this passes do you think we can merge it? |
[ci skip]
setRootPath doesn't actually change the data represented by the model, i.e. the test will still end up iterating over the root filesystem. Due to symlinks (?) or other funny stuff this could take a long time or do other funny things, so let's get rid of it.
I took a quick look and noticed the filesystem model test actually runs over the root filesystem (not just I ended up just removing it. After the checks pass, I think this can finally be merged! |
🎉 💥 |
Yay! ✨ |
There we go, a very much work-in-progress version of the model tester.
The basic tests work for PyQt5, but probably not for anything else. Some issues to look at:
PyQt4/PySide compatibility ✅
sip.cast
equivalent (so we can access private methods) in PySide?QVariant
API changed, the tests using that need to be adjusted to work with PyQt5/PySide.pytest integration
qDebug()
code? Some can probably be removed because of the assert introspection, but for some of it it might make sense to useprint
so we get that output on a failure? Or maybe introduce a new output "category" like the Qt warning messages for modeltester messages?Other
assert self._model.data(index, QtCore.Qt.DisplayRole).isValid()
test) as arguments and/or attributes.Tests