Since I went through the effort of publishing my rxpy3-examples
repository on GitHub, I thought it’s time to add tests.
I had already taken a look at the test-suite for the rxpy
-library, thinking that I might get some inspiration from that. But looking at their code I quickly found that it is way too complicated to be helpful to a rxpy-beginner like myself. They have created their own DSL for test, which is fine if you work a project over long period of time. But if you want to learn how to use the library as a beginner – like myself – then that is an additional barrier to entry.
That’s why I decided that my tests should be very, very easy to understand.
Basically, the idea is this: All my examples will generate some output, so I want to write my tests in such a way that it’s trivial to see what the expected output is. The assertion should look something like asssert output == expected_output
.
The actual implementation now looks like this:
|
|
exptected_output
is what the name implies: the expected output. I am using a multi-line string because it makes copying and pasting the output very easy, even though it looks uglycapture_stdout_as_list
is a context manager that captures the sys.stdout and provides ato_string()
method that joins the list using the system’s line-separator
Of course there is room for improvement, but it’s a start. You can find my rxpy3-examples repository on GitHub.
If you liked this post, please, do share it:
Thanks, for reading (and sharing)! 🥳