-
Notifications
You must be signed in to change notification settings - Fork 47
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
Unit tests for all methods in ControlInterface #91
Unit tests for all methods in ControlInterface #91
Conversation
Hi @scrool
It might still not be the complete vision of being able to use the same file for both unit testing that the code has not changed, and for testing that the same code works for new devices. But I actually got it further in this direction than I had expected. Hopefully it is sufficient. In either way, it is a significantly increased coverage compared to the previous tests of control.py (which only tested set/get_mode). |
@Anders-Holst I've tried to generate my own test data by removing all tests, setting Immediate diference seems to be that yours yaml files are formatted differently. Have you reformatted them since vcr recorded them? I'm running this on:
Secondly,
I guess you haven't been working with factory-reset device but you have uploaded some movie(s) before this? Similarly:
Finally, I have skipped tests that are switching my network to AP: |
One more note - with saved recordings I'm able to reproduce tests. 👍 I'll still need to review the code itself though. |
@scrool wrote:
No, I have not edited them after recording.
Appears I have no vcrpy-unittest, which might explain the difference. I suppose we can use your recorded cassettes instead of mine then. Both formats appear to work though.
Hmm, odd. It is right that it is not factory reset, but the test does a
The test_playlist error is most likely a consequential error: If there are no movies uploaded there is no playlist, and no playlist entry with the requested number.
Yes, I know. In my original "manual tests" I had omitted them too, but then I though "Damn it Anders, you need to be thorough, even if it takes more effort", so I added them. Once recorded though, they are unproblematic to run, so the "unit test" aspect of these is still valuable. We can use my cassettes for those cases. (Do you think I should manually edit the cassettes to remove details from my network environment? Are these things sensitive?) Or we can leave them out entirely. |
re I'd prefer to commit cassettes that are closer to what others would be able to generate - especially to be able to compare them in the future. If you would like to look into that, feel free to commit those if you manage to get some different yamls. E.g. on my end it looks like this:
This turned out to be my bad. I set number of bytes to 4 event though I was testing this against a device which uses only RGB. It passes now.
Exactly. There was no playlist, a script uploaded just one playlist but then requested playlist with number 1 whereas playlists are numbered from 0. Simple change of Snip of original communication and responses:
Right. That works. I ended up skipping more than needed.
From what I can tell the issue with
I don't think your private IP addresses needs to be redacted. On my end I don't prefer to publish MAC addresses, HW IDs, serial numbers of my devices. I know that they are being sent through MQTT and in the past it was possible to control them by others. |
Ok, I will make new recordings with vcrpy-unittest installed. My mistake to miss it. And at the same time maybe I will carefully edit out at least MAC and HW numbers from the device and network data. I think it is wise to be a little paranoid about these things. It is a relief that test_movie_newif works - I started to fear that the protocol had changed again or that I had failed to make it sufficiently device independent. By the way, I think that set_playlist_current should work now with 1 too, once test_movie_newif works. There are two uploaded movies in the playlist, and the index is the movie index within the playlist, so the last movie will have index 1. And when starting the playlist it always starts at movie 0, so unless we change it to something else we can not tell for sure that the call has any effect. Regarding recordings, I again realize I do things differently - I have not figured out how to run all tests automatically at once. Instead I manually call setUp, then the specific test I want to run, and finally tearDown. Then there is no problem to, in between the tests disconnect from the wifi and connect to the Twinkly AP, and after that test connect back again. But of course, if you run through them automatically while recording, then it will be a problem. So I am not sure what you want to do with this. One attitude is that the primary purpose after all is unit testing, not testing additional devices, although that is a nice extra. I can record the station and ap cassettes again, and then it will work in the testing phase. Maybe it is acceptable that recording requires some extra and manual work. Another attitude is to say that perfect coverage is difficult to achieve anyway - then every single option for every call has to be tested, and it is not the case for now. So the easiest is to skip those two tests entirely, without much loss. But suddenly it dawns on me that the obvious solution, which gives up neither rigidity nor convenience while recording, is of course to break these two tests out to separate classes ! Then each can be run in turn, and network connections changed in between. I'm already on to it! |
Hi @scrool |
This version looks great! Split into separate modules was great idea - I was easily able to skip those, that I wasn't interested in. I have squashed them and merged all those changes. Thanks! 🥳 |
They are obsoleted by much more thoroughfull tests now since #91.
They are obsoleted by much more thoroughfull tests now since #91.
And if you are interested, there are now unit tests for all the methods of ControlInterface (except firmware update. And except the realitime stuff already tested separately of course). I managed to convert my "manual tests" into these.
Again successfully tested, flaked and blacked (although, really, I am not convinced that black always makes the code more readable...)
I actually suggest removing the existing test file tests/test_control.py including its cassettes, since they are now covered by this new test file. And maybe rename the new file to test_control.py instead. I can add such a commit if you like.