Closed sadielbartholomew closed 3 years ago
(Comments above were discussed offline. We decided the examples should be removed.)
(Force pushed to sort out the merge conflicts locally where they are much easier to manage in emacs. Tests pass locally, now re-triggering the CI via open-close.)
Thanks @kinow: doctest
is great! :tada: Here it has picked up on a number of deprecated examples and some missing quote marks and the like! cfunits
is a small library so it wasn't time consuming to get all examples passing with doctest
, but I'll do another of our libraries, cfdm
, next by incremental process since there are many, many more docstrings, a lot of which need some logic to set up objects they refer to.
(Merging as checks have all passed locally and on the CI.)
It is really great! I have an old Java project with javadocs that contain examples too. Recently found several were broken/outdated, and wished there was something as good as doctest for Java. Thanks Sadie!!!
Quick PR to setup doctest for cfunits and make appropriate amendments to any code examples as raised by corresponding test failures.
With much thanks to @kinow who provided demonstrated how to do this with cf-python (see NCAS-CMS/cf-python#57) and whose code was largely lifted and shifted here. I thought I'd start with cfunits as a much smaller library to set this up as a POC so that we know how doctest works and any quirks it has, so that can gradually chip away at the docstrings in cfdm and then cf-python to make sure they each set themselves up appropriately (as in NCAS-CMS/cf-python#61) and can therefore be doctested too.
Raising as a draft initially since there are still two doctest failure cases, both relating to
AttributeError
s when trying to setunits
on aUnits
object. I imagine that is deprecated functionality but I just want to check before amending those docstrings.