[GRASS-dev] PyGRASS Module error handling

Vaclav Petras wenzeslaus at gmail.com
Mon Jun 30 08:43:20 PDT 2014


Hi,

when writing tests which involve PyGRASS Module class I found that at some
occasions the error messages are quite confusing.

First when you try to run one module twice, you get AttributeError:

>>> from grass.pygrass.modules import Module
>>> from subprocess import PIPE
>>> m = Module('r.info', map='elevation', run_=False, stdout_=PIPE)
>>> m.run()
>>> m.outputs['stdout'].value
...
>>> # running for the second time
>>> m.run()
Traceback (most recent call last)
    ...
AttributeError: 'str' object has no attribute 'fileno'

Second, when you confuse m.inputs['map'].value with m.inputs['map'] (which
is pretty easy error to do) you get "TypeError: deletions are implemented
differently for unicode":

>>> # this is OK
>>> m.inputs['map'].value = 5
Traceback (most recent call last)
    ...
TypeError: The Parameter <map>, require: raster, get: <type 'int'> instead
>>> # this is not OK
>>> # confusing parameter object and parameter value
>>> m.inputs['map'] = 'aspect'
Traceback (most recent call last)
    ...
TypeError: deletions are implemented differently for unicode

With the former it depends what is actually allowed. Than it is probably
easy to fix. With the later, no easy solutions come to my mind.

With my tests I was actually asserting m.outputs['stdout'] for true which
is always true instead of asserting m.inputs['stdout'].value. I don't know
how to avoid this mistake in general.

Does this make sense to you or do you think that I and PyGRASS users should
be just be more careful?

Vaclav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140630/2b101844/attachment.html>


More information about the grass-dev mailing list