[QGIS-Developer] Documentation: pyqgis cookbook python code tests

Richard Duivenvoorde rdmailings at duif.net
Sat Mar 16 03:05:32 PDT 2019


Hi,

For those not aware of Arnaud's work during the Hackfest:

His work makes it relatively easy to test the python snippets in the
pyqgisbook. In this way keeping the python snippets up to date with
code/api changes of QGIS itself is much easier.

We use a Sphinx extension:
https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html

In short:
- you run the snippets from within the cookbook rst using QGIS(libs)
either from your build/install dir, OR from within a QGIS-Desktop docker
instance (same as is being used for automatic tests)
- so we (have to!) adapt the code in the pycookbook a little to make it
testable (adding testsetup:: and testcode:: directives)
- he slightly changed the way you can build the documentation (on Linux)
using one or two extra make (.mk) files.

See:
https://github.com/qgis/qgis-documentation#testing-python-snippets

I've just tested and this 1 test :-) works flawlessly if you create a
'user.mk' pointing to your QGIS_PREFIX_PATH

So: now we can make all code snippets testable!
If I am correct he was also busy to get the code examples in the
doxygen/pyqgiscook work with this too @arnaud ?)

Please try!

Regards,

Richard Duivenvoorde

PS this is Sphinx/Python only, but if somebody jumps in to make it work
in a Windows way this would be even nicer. Or we should update the paver
way again?


More information about the QGIS-Developer mailing list