You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the help! It would be really helpful to have one script per sensor, which tests all its methods, with all possible arguments. Like this, but for sensors.
Starting with the SPIKE sensors would be a good start. Perhaps mounted side by side. With one motor (itself not the subject in these tests) waving something (colored) in front of the sensors to verify that they give the expected values. Simpler is better, so that the test itself does not fail mechanically at least.
Let's continue this conversation in the coverage repo.
Some additional background about this repository until this is documented in any shape or form:
The most important folder is /scripts, containing all the Pybricks 3.0 scripts to be tested. There's only one for now.
The /ev3 folder contains an EV3 project for a robot that can operate all the buttons and the USB cable on a SPIKE Prime Hub. This is to facilitate automated testing of firmware installation, and turning the SPIKE Prime hub on and off. The design of this EV3 robot is not documented yet.
The /mailbox folder contains some tools to communicate with the EV3 brick.
The /main.py is a script on the PC that talks to the EV3 as well as the SPIKE Prime Hub, to sequentially run everything in /scripts.
It would also be good to test everything with and without keyword arguments. Sometimes we document the wrong name.
Would be nice to have the documentation verified by tests.
I intend to do: default, and all possible values if possible or otherwise only low' and high` limits and something in-between.
Is raise BaseException a valid signal of this test fails?
Right, and feel free to test out of bounds values as well. For example, in the display I tested negative pixel indexes.
Depending on what it is, it may pass or raise an exception, but either one is a good test to prove that it does not crash.
Is raise BaseException a valid signal of this test fails?
It's still early days, so if you intend to work on this, chances are you will be defining the standards :) So yeah, feel free to investigate and see what you find practical.
I've been thinking about how to write these tests and added a few here. After some considerations, these are the guidelines I used. Input is welcome.
Succeed silently, fail loudly
This can be done with assert. For example:
distance=ultrasonic_sensor.distance()
assertdistance>100, "Expected > 100 mm, got {0}.".format(distance)
This explains what failed, and also gives the line number. I've found this to be more helpful than testing for expected output mismatch like the tests MicroPython has. Then you still have 1) find the expected output and 2) manually search where it failed.
If we should get an error as part of a test, we can just catch it, and assert that it has the expected type.
try:
a=1/0raiseValueErrorexceptExceptionase:
expected=ZeroDivisionErrorasserttype(e) ==expected, "Expected {0} but got {1}".format(expected, type(e))
Keep things simple
Avoid auxiliary functions when they are there just to make test output "nice" or "efficient".
If we find that some functions are really helpful, we could add them to the firmware so you could import them from pybricks.util or something.
Keep things short
Keep tests very short and to the point. We can automate the process of running a bunch of small scripts with pybricksdev.
No numbering schemes
Names like t03_color_surface_False, t04_color_surface_WRONG can be somewhat hard to keep updated and expand.
If order is important, then those two tests should be one test. Each test does its own initialization, if any. When running tests automatically, we can make sure to run previously failed tests first.
Then on to the actual tests. I've been thinking we could build small modules on which we can run several tests. Here's "Hardware Module 1" used in the tests I linked to above:
There may also be a single large test that combines all modules, but smaller modules make it easier for people to try this out themselves. Ideally, all of them can be built simultaneously from a limited number of sets.
Avoid auxiliary functions when they are there just to make test output "nice" or "efficient".
If we find that some functions are really helpful, we could add them to the firmware so you could import them from pybricks.util or something.
Keep things short
Keep tests very short and to the point. We can automate the process of running a bunch of small scripts with pybricksdev.
Hard for me to not enhance but I agree.
No numbering schemes
Names like t03_color_surface_False, t04_color_surface_WRONG can be somewhat hard to keep updated and expand.
If order is important, then those two tests should be one test. Each test does its own initialization, if any. When running tests automatically, we can make sure to run previously failed tests first.
No need for numbering if the tests themselves are short.
There may also be a single large test that combines all modules, but smaller modules make it easier for people to try this out themselves. Ideally, all of them can be built simultaneously from a limited number of sets.
Agreed, many small tests are easily automated to be all run,
and the small tests are easily run, debugged, and updated separately by "hand".
@BertLindeman, does this make sense? I'd be curious if this could work for your tests as well, after some adaptation.
As you've seen, we we'll probably keep tests in the main repo instead of here.
Will take a look at your examples, so much better than my coding.
I had a hardware module with a ring of all expected colors, but I did not get a constant and solid result on them. Probably also environmental light involved, although I also tried it in a completely dark room.
(See that it's hard for me not to enhance 😁 )
A bit related: is there a possibility to automate testing the examples in the doc, so there is no need to build tests for that?
I wonder: would you want to see what firmware version a test has been run with?
I think we'd mainly just try to run all tests whenever we prepare a beta or full release. Then if everything passes, we press the button to release it.
I think we'd mainly just try to run all tests whenever we prepare a beta or full release. Then if everything passes, we press the button to release it.
By taking the examples out of the doc by hand? I hope not.
Although it's not a huge number of examples...
Not sure what you mean. We'd leave the examples in the docs.
I just meant that we don't need each test to create a report with a version number, etc.
The tests either pass or they don't. We can open issues for things that are broken, and go ahead with a release if we are happy enough with the results.
Not sure what you mean. We'd leave the examples in the docs.
The examples go as python source into a hub to verify the syntax and if they work.
Are the examples in Github separate files? I just don't know.
just meant that we don't need each test to create a report with a version number, etc.
The tests either pass or they don't. We can open issues for things that are broken, and go ahead with a release if we are happy enough with the results.
@laurens from the photo above I can almost build "Hardware Module 1"
Just the fixture onto the motor I miss.
Do you have a building instruction laying around? Or a 3D model I can use?
No real problem if not, I'll do trial and error 😄
@laurensvalk Got hardware machine #1 built. Have mounted the hub onto the machine for stability.
The test setup is on a pile of books next to my chair for comfortability.
Activity
laurensvalk commentedon Jan 20, 2021
Some additional background about this repository until this is documented in any shape or form:
/scripts, containing all the Pybricks 3.0 scripts to be tested. There's only one for now./ev3folder contains an EV3 project for a robot that can operate all the buttons and the USB cable on a SPIKE Prime Hub. This is to facilitate automated testing of firmware installation, and turning the SPIKE Prime hub on and off. The design of this EV3 robot is not documented yet./mailboxfolder contains some tools to communicate with the EV3 brick./main.pyis a script on the PC that talks to the EV3 as well as the SPIKE Prime Hub, to sequentially run everything in/scripts.BertLindeman commentedon Jan 20, 2021
Fun stuff, thanks.
(I used to be QA on mainframe security, so some background is available)
My idea at the moment is to add in
/scriptsaspike_color_sensor.pyprogram to "do" all documented functions and parameters.Starting without verification of the results.
So just a syntax check first.
Adding result check after an initial script has been accepted.
Was hoping to verify the hub light color in this script also, but the reported HSV values are too much off.
laurensvalk commentedon Jan 20, 2021
That sounds like a good plan. We could probably order the tests somehow so that these type of tests always run first.
laurensvalk commentedon Jan 20, 2021
Yeah, these need to be calibrated better, especially the read method for external lights.
laurensvalk commentedon Jan 20, 2021
It would also be good to test everything with and without keyword arguments. Sometimes we document the wrong name.
BertLindeman commentedon Jan 20, 2021
Would be nice to have the documentation verified by tests.
I intend to do:
default, and all possible values if possible or otherwise onlylow' andhigh` limits and something in-between.Is
raise BaseExceptiona valid signal ofthis test fails?Well, let me get started....
laurensvalk commentedon Jan 20, 2021
Right, and feel free to test out of bounds values as well. For example, in the display I tested negative pixel indexes.
Depending on what it is, it may pass or raise an exception, but either one is a good test to prove that it does not crash.
It's still early days, so if you intend to work on this, chances are you will be defining the standards :) So yeah, feel free to investigate and see what you find practical.
BertLindeman commentedon Jan 20, 2021
That is a nice positive response.
So out of bounds tests are in ;-)
Add spike_colorsensor.py with basic syntax checks
BertLindeman commentedon Jan 26, 2021
Maybe stupid idea, but . . .
Would it be doable (useful?) to generate tests from docstrings that document the syntax and arguments for devices?
I am thinking of tests to verify that the doc is compatible with the firmware, vice versa.
Add spike_colorsensor.py with basic syntax checks (#2)
scripts: add color sensor with basic syntax checks
laurensvalk commentedon Mar 31, 2021
Some updates:
I've been thinking about how to write these tests and added a few here. After some considerations, these are the guidelines I used. Input is welcome.
Succeed silently, fail loudly
This can be done with
assert. For example:This explains what failed, and also gives the line number. I've found this to be more helpful than testing for expected output mismatch like the tests MicroPython has. Then you still have 1) find the expected output and 2) manually search where it failed.
If we should get an error as part of a test, we can just catch it, and assert that it has the expected type.
Keep things simple
Avoid auxiliary functions when they are there just to make test output "nice" or "efficient".
If we find that some functions are really helpful, we could add them to the firmware so you could import them from
pybricks.utilor something.Keep things short
Keep tests very short and to the point. We can automate the process of running a bunch of small scripts with
pybricksdev.No numbering schemes
Names like
t03_color_surface_False,t04_color_surface_WRONGcan be somewhat hard to keep updated and expand.If order is important, then those two tests should be one test. Each test does its own initialization, if any. When running tests automatically, we can make sure to run previously failed tests first.
laurensvalk commentedon Mar 31, 2021
Then on to the actual tests. I've been thinking we could build small modules on which we can run several tests. Here's "Hardware Module 1" used in the tests I linked to above:
There may also be a single large test that combines all modules, but smaller modules make it easier for people to try this out themselves. Ideally, all of them can be built simultaneously from a limited number of sets.
laurensvalk commentedon Mar 31, 2021
@BertLindeman, does this make sense? I'd be curious if this could work for your tests as well, after some adaptation.
As you've seen, we we'll probably keep tests in the main repo instead of here.
BertLindeman commentedon Mar 31, 2021
Sure, less output if all OKE. Less clutter.
Hard for me to not enhance but I agree.
No need for numbering if the tests themselves are short.
Agreed, many small tests are easily automated to be all run,
and the small tests are easily run, debugged, and updated separately by "hand".
Makes good sense, @laurensvalk.
Will take a look at your examples, so much better than my coding.
I had a hardware module with a ring of all expected colors, but I did not get a constant and solid result on them. Probably also environmental light involved, although I also tried it in a completely dark room.
(See that it's hard for me not to enhance 😁 )
A bit related: is there a possibility to automate testing the examples in the doc, so there is no need to build tests for that?
laurensvalk commentedon Mar 31, 2021
I've been wondering about that too.
We'd probably need to revise the examples to make sure they could run on the test setups. This could be worth the effort though.
BertLindeman commentedon Mar 31, 2021
I think so. The first problem a new user encounters is an example not working.
Important to prevent that.
I wonder: would you want to see what firmware version a test has been run with?
laurensvalk commentedon Mar 31, 2021
I think we'd mainly just try to run all tests whenever we prepare a beta or full release. Then if everything passes, we press the button to release it.
BertLindeman commentedon Mar 31, 2021
By taking the examples out of the doc by hand? I hope not.
Although it's not a huge number of examples...
laurensvalk commentedon Mar 31, 2021
Not sure what you mean. We'd leave the examples in the docs.
I just meant that we don't need each test to create a report with a version number, etc.
The tests either pass or they don't. We can open issues for things that are broken, and go ahead with a release if we are happy enough with the results.
BertLindeman commentedon Mar 31, 2021
The examples go as python source into a hub to verify the syntax and if they work.
Are the examples in Github separate files? I just don't know.
Oke.
laurensvalk commentedon Mar 31, 2021
Yes.
BertLindeman commentedon Mar 31, 2021
Oke, Laurens. Thanks.
BertLindeman commentedon Apr 9, 2021
@laurens from the photo above I can almost build "Hardware Module 1"
Just the fixture onto the motor I miss.
Do you have a building instruction laying around? Or a 3D model I can use?
No real problem if not, I'll do trial and error 😄
laurensvalk commentedon Apr 9, 2021
Cat not included.
BertLindeman commentedon Apr 9, 2021
Thank you @laurensvalk
I saw the text before the photo's, hilarious.
laurensvalk commentedon Apr 10, 2021
FYI, the ports were changed in pybricks/pybricks-micropython@b4b450d
BertLindeman commentedon Apr 10, 2021
Indeed a nice change. I was using a technic hub to test with, as it was close at hand.
Thanks for the heads-up.
BertLindeman commentedon Apr 11, 2021
@laurensvalk Got

hardware machine #1built. Have mounted the hub onto the machine for stability.The test setup is on a pile of books next to my chair for comfortability.