-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add basic tests #15
Comments
Some thoughts about this. A good starting point could be to design test cases by creating a However there is a pitfall to avoid with this approach. The PDF format is not reproducible, notably because it contains a timestamp of creation as well as various things that are supposed to change every time: https://tex.stackexchange.com/questions/229605/reproducible-latex-builds-compile-to-a-file-which-always-hashes-to-the-same-va And indeed, if I run the demo two times, the the PNG and MD files stay the same but the PDF files change:
Nevertheless, the approach could work quite well by checking the hash of all MD and PNG files and at least the existence of all PDF files between the expected output directory and the test-generated output directory. The PDF-specific code would have to be tested differently, but everything else would get a lot of test coverage in an easy way. Such a test harness could quickly catch a lot of things while being easy to setup initially: a good starting point would be to use the files from the demo as a first test case and enrich the tests from there. Adding test cases would be as easy as creating documents on our remarkable tablets, copy them in the test directory, then convert them using a known good version of remarks. Assuming we follow this approach, one open question is whether to use a Python testing framework (which I'm personally not familiar with) or plainly use a bash / makefile script that just call remarks from the outside and make the appropriate checks externally. I've no opinion on this. What do you think of all that @lucasrla ? |
Thanks for the write-up! To kick things off, I plan to write a few basic tests using pytest and the Regarding your point about how to "assert" PDFs, I am not sure what approaches are available. I will have a look at what OCRmyPDF does and see if I can get some inspiration. PS: If you want to read well-written guides on anything Python, try RealPython's. On tests, see, for instance: Getting Started With Testing in Python, Effective Python Testing With Pytest, etc. |
Personally I think in the short and medium term having everything else under test is more than enough. If both the PNGs and MDs files are byte-for-byte identical to what is expected, it is very likely that the PDF files are too for most possible type of regressions. Especially if the existence of the PDF files is checked. In the long term, one approach could be to convert each PDF to an image and check those images as being pixel-for-pixel identical to the expected output. Another approach could be to study the PDF format a bit and explore what parts of the file are supposed to be changing and what parts are not.
Thanks for that! I'll keep those in mind if I have to do more serious Python work in the future. |
For what it's worth, I added an extremely simple testing set-up. It doesn't even look at the contents of the files, it just asserts that there are no errors. This is better than having no tests. I'm using this tool with many different notebooks, and I already found two fairly basic errors which are now prevented from being regressed by testing in this manner. |
Originally posted by @clement-elbaz in #12 (comment)
remarks
started a few months ago as a set of hacks/scripts that I wrote for my own use. Now that it has grown to a project that dozens use, we must level up.Going forward, having a set of basic tests would be very helpful.
The text was updated successfully, but these errors were encountered: