[GRASS-dev] failing doctest when delete temporal dataset

Hi devs,

I added (patch provided as attachment) a doctest in list_maps_of_stds
temporal function. I get the following error, but if I run the python
code of the test I get not error. Do you have any idea how to solve
it?

File "list_stds.py", line 181, in list_stds.list_maps_of_stds
Failed example:
    check = sp.delete()
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest list_stds.list_maps_of_stds[17]>", line 1, in <module>
        check = sp.delete()
      File "/home/lucadelu/compilati/grass_trunk/dist.x86_64-pc-linux-gnu/etc/python/grass/temporal/abstract_space_time_dataset.py",
line 1943, in delete
        self.msgr.verbose(_("Delete space time %s dataset <%s> from temporal "
    TypeError: 'int' object is not callable

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

(attachments)

list_stds.diff (2.99 KB)

On Thu, Feb 18, 2016 at 5:49 AM, Luca Delucchi <lucadeluge@gmail.com> wrote:

I get the following error, but if I run the python
code of the test I get not error. Do you have any idea how to solve
it?

        self.msgr.verbose(_("Delete space time %s dataset <%s> from
temporal "
    TypeError: 'int' object is not callable

This happens when the tested method uses translatable stings (usually for
message or in case of error - which might be part of testing).

The reason is that underscore is used in interactive interpreter for the
"last result" and this is inherited by doctest and at the same time, GRASS
is using _ for translation and setting is as buildin. There is a ticked
proposing imports instead of buildin [1]. I already implemented this for
wxGUI few years back (for GUI you now have to explicitly import _ function
[2]). To my understanding, this should avoid the clash of two different
underscores (when implemented everywhere).

The workaround for now is to do some additional definitions of underscore.
There is a function in gunittest which will do it for you [3]. You need to
explicitly call it before you execute the doctest which is exactly what the
dedicated test files in testsuites are doing, e.g. the one for script
package [4].

[1] https://trac.osgeo.org/grass/ticket/2425
[2] https://trac.osgeo.org/grass/changeset/67687
[3]
https://trac.osgeo.org/grass/browser/grass/trunk/lib/python/gunittest/utils.py#L35
[4]
https://trac.osgeo.org/grass/browser/grass/trunk/lib/python/script/testsuite/test_doctests.py