[GRASS-dev] GSoC idea: Testing framework

Hi all,

I would like to apply to GSoC this year with the idea of testing framework for GRASS. I probably don’t have to explain the need for it.

Sören suggested that he would be my mentor in case my application is successful. I hope also that I will get the feedback from all developers, now or in the future, because it is crucial that GRASS developers will actually use this framework.

I described the idea shortly on Trac GSoC 2014 wiki page. I plan to include more notes on separate page in next weeks but the basic idea should be clear. Some discussion is also in #2105. Perhaps, the most innovative idea is that different types of tests should be supported (e.g. Python doctest and shell scripts), although it would be always driven form Python. For example, it seems that doctest is very convenient for modules which has standard input and output (see recent doctest for r.category module).

Best regards,
Vaclav

http://trac.osgeo.org/grass/wiki/GSoC/2014#TestingframeworkforGRASSGIS

http://trac.osgeo.org/grass/ticket/2105

http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.category/test_rcategory_doctest.txt

Hi Vaclav,

I would be interested to help for the imagery modules,

Good luck !
Yann

···

On 31 January 2014 09:23, Vaclav Petras <wenzeslaus@gmail.com> wrote:

Hi all,

I would like to apply to GSoC this year with the idea of testing framework for GRASS. I probably don’t have to explain the need for it.

Sören suggested that he would be my mentor in case my application is successful. I hope also that I will get the feedback from all developers, now or in the future, because it is crucial that GRASS developers will actually use this framework.

I described the idea shortly on Trac GSoC 2014 wiki page. I plan to include more notes on separate page in next weeks but the basic idea should be clear. Some discussion is also in #2105. Perhaps, the most innovative idea is that different types of tests should be supported (e.g. Python doctest and shell scripts), although it would be always driven form Python. For example, it seems that doctest is very convenient for modules which has standard input and output (see recent doctest for r.category module).

Best regards,
Vaclav

http://trac.osgeo.org/grass/wiki/GSoC/2014#TestingframeworkforGRASSGIS

http://trac.osgeo.org/grass/ticket/2105

http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.category/test_rcategory_doctest.txt


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Hi Vaclav,

It might be interesting to look at CTest and dashboard from cmake project

http://www.cmake.org/cmake/help/v2.8.8/ctest.html

http://www.cdash.org/

···

On Fri, Jan 31, 2014 at 7:05 AM, Yann Chemin <ychemin@gmail.com> wrote:

Hi Vaclav,

I would be interested to help for the imagery modules,

Good luck !
Yann


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Regards,
Rashad

On 31 January 2014 09:23, Vaclav Petras <wenzeslaus@gmail.com> wrote:

Hi all,

I would like to apply to GSoC this year with the idea of testing framework for GRASS. I probably don’t have to explain the need for it.

Sören suggested that he would be my mentor in case my application is successful. I hope also that I will get the feedback from all developers, now or in the future, because it is crucial that GRASS developers will actually use this framework.

I described the idea shortly on Trac GSoC 2014 wiki page. I plan to include more notes on separate page in next weeks but the basic idea should be clear. Some discussion is also in #2105. Perhaps, the most innovative idea is that different types of tests should be supported (e.g. Python doctest and shell scripts), although it would be always driven form Python. For example, it seems that doctest is very convenient for modules which has standard input and output (see recent doctest for r.category module).

Best regards,
Vaclav

http://trac.osgeo.org/grass/wiki/GSoC/2014#TestingframeworkforGRASSGIS

http://trac.osgeo.org/grass/ticket/2105

http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.category/test_rcategory_doctest.txt


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Hi Vaclav,

On Fri, Jan 31, 2014 at 3:53 AM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

Sören suggested that he would be my mentor in case my application is
successful.

If possible, I would like to help on this task too.

I've used doctest to cover some of the pygrass' functions and modules,
but I don't like too much, at the moment to test the pygrass' doctest
you have to be inside the NorthCarolina/user1 location/mapset, that is
not always practical.
Would be nice to have something that run independently from the
location/mapset. 'm studying the unittest framework and in a short
time I would like to start to write some unittest for the pygrass
library.
Therefore I'm definitely interested on this topic.

For example, it seems that doctest is very convenient for modules which has
standard input and output (see recent doctest for r.category module).

I really like it, and they can also help users to move they bash
scripts to python.

All the best.

Pietro

On Fri, Jan 31, 2014 at 2:32 AM, Rashad M <mohammedrashadkm@gmail.com>wrote:

Hi Vaclav,

It might be interesting to look at CTest and dashboard from cmake project

http://www.cmake.org/cmake/help/v2.8.8/ctest.html
http://www.cdash.org/

Thanks, I haven't noted this there but yes, some server-side running of

tests must be considered and my idea so far is that the framework will not
try to solve this, it will just be ready to be used there.

On Fri, Jan 31, 2014 at 7:05 AM, Yann Chemin <ychemin@gmail.com> wrote:

Hi Vaclav,

I would be interested to help for the imagery modules,

Good luck !
Yann

On 31 January 2014 09:23, Vaclav Petras <wenzeslaus@gmail.com> wrote:

Hi all,

I would like to apply to GSoC this year with the idea of testing
framework for GRASS. I probably don't have to explain the need for it.

Sören suggested that he would be my mentor in case my application is
successful. I hope also that I will get the feedback from all developers,
now or in the future, because it is crucial that GRASS developers will
actually use this framework.

I described the idea shortly on Trac GSoC 2014 wiki page. I plan to
include more notes on separate page in next weeks but the basic idea should
be clear. Some discussion is also in #2105. Perhaps, the most innovative
idea is that different types of tests should be supported (e.g. Python
doctest and shell scripts), although it would be always driven form Python.
For example, it seems that doctest is very convenient for modules which has
standard input and output (see recent doctest for r.category module).

Best regards,
Vaclav

http://trac.osgeo.org/grass/wiki/GSoC/2014#TestingframeworkforGRASSGIS
http://trac.osgeo.org/grass/ticket/2105

http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.category/test_rcategory_doctest.txt

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

--
----

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

--
Regards,
   Rashad

On Fri, Jan 31, 2014 at 4:41 AM, Pietro <peter.zamb@gmail.com> wrote:

Hi Vaclav,

On Fri, Jan 31, 2014 at 3:53 AM, Vaclav Petras <wenzeslaus@gmail.com>
wrote:
> Sören suggested that he would be my mentor in case my application is
> successful.

If possible, I would like to help on this task too.

I've used doctest to cover some of the pygrass' functions and modules,
but I don't like too much, at the moment to test the pygrass' doctest
you have to be inside the NorthCarolina/user1 location/mapset, that is
not always practical.

On the other hand, my impression from writing tests was that sometimes it
would be advantageous
to have some prepared location with everything, so I would like to go in
the way of supporting different locations rather then requiring all tests
to use only data their generate in the preparation phase.

Would be nice to have something that run independently from the

location/mapset. 'm studying the unittest framework and in a short
time I would like to start to write some unittest for the pygrass
library.

unittest test which does not rely on location/mapset is probably the
default and preferred way, so I'm looking forward to see this.

Therefore I'm definitely interested on this topic.

> For example, it seems that doctest is very convenient for modules which
has
> standard input and output (see recent doctest for r.category module).

I really like it, and they can also help users to move they bash
scripts to python.

I used doctest in this way for the first time but it seems that it is as

easy as writing bash script and you get doctest functionality and Python
functionality to examine your results. The testing framework (perhaps
unittest class inside some script) would run the doctest file in the right
environment (location) or in several environments if desired.

All the best.

Pietro

On Fri, Jan 31, 2014 at 3:53 PM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

I've used doctest to cover some of the pygrass' functions and modules,
but I don't like too much, at the moment to test the pygrass' doctest
you have to be inside the NorthCarolina/user1 location/mapset, that is
not always practical.

On the other hand, my impression from writing tests was that sometimes it
would be advantageous
to have some prepared location with everything, so I would like to go in the
way of supporting different locations rather then requiring all tests to use
only data their generate in the preparation phase.

I agree, perhaps we can use the demolocation in the trunk for this purpose?
May be when we run the tests, the testing framework could set
everything to run on the demolocation, run the test and then restore
the previous configuration?

Would be nice to have something that run independently from the
location/mapset. 'm studying the unittest framework and in a short
time I would like to start to write some unittest for the pygrass
library.

unittest test which does not rely on location/mapset is probably the default
and preferred way, so I'm looking forward to see this.

I mean, would be nice to insert this on the GRASS testing framework,
but I will not work on this.

I really like it, and they can also help users to move they bash
scripts to python.

I used doctest in this way for the first time but it seems that it is as
easy as writing bash script and you get doctest functionality and Python
functionality to examine your results. The testing framework (perhaps
unittest class inside some script) would run the doctest file in the right
environment (location) or in several environments if desired.

yes, may be not only for the doctest but for everything?

On Fri, Jan 31, 2014 at 11:53 AM, Pietro <peter.zamb@gmail.com> wrote:

On Fri, Jan 31, 2014 at 3:53 PM, Vaclav Petras <wenzeslaus@gmail.com>
wrote:
>> I've used doctest to cover some of the pygrass' functions and modules,
>> but I don't like too much, at the moment to test the pygrass' doctest
>> you have to be inside the NorthCarolina/user1 location/mapset, that is
>> not always practical.
>
>
> On the other hand, my impression from writing tests was that sometimes it
> would be advantageous
> to have some prepared location with everything, so I would like to go in
the
> way of supporting different locations rather then requiring all tests to
use
> only data their generate in the preparation phase.

I agree, perhaps we can use the demolocation in the trunk for this purpose?
May be when we run the tests, the testing framework could set
everything to run on the demolocation, run the test and then restore
the previous configuration?

For sure. This is how the compilation works or at least is supposed to

work. But also, I would like test itself to specify in which location(s) it
can run and then run it in these locations.

If you would like to use this now, my very limited knowledge of Makefiles
tells me that you can try to use `run_grass` in Makefile. I've never tried
but according to gui/wxpython/Makefile it should work. Try it outside grass
session. You Makefile should contain something like this

default: $(DSTFILES)
...
-$(MAKE) mytest
mytest:
$(call run_grass,$(PYTHON) myscript.py params)

`make` or `make test` should then run `python myscript.py params` in
demolocation. But as I said it is probably just a theory...

>> Would be nice to have something that run independently from the
>> location/mapset. 'm studying the unittest framework and in a short
>> time I would like to start to write some unittest for the pygrass
>> library.
>
>
> unittest test which does not rely on location/mapset is probably the
default
> and preferred way, so I'm looking forward to see this.

I mean, would be nice to insert this on the GRASS testing framework,
but I will not work on this.

Do what ever you think is advantageous to you, I will then consider how to

integrate it.

>> I really like it, and they can also help users to move they bash
>> scripts to python.
>
> I used doctest in this way for the first time but it seems that it is as
> easy as writing bash script and you get doctest functionality and Python
> functionality to examine your results. The testing framework (perhaps
> unittest class inside some script) would run the doctest file in the
right
> environment (location) or in several environments if desired.

yes, may be not only for the doctest but for everything?

If I inferred correctly what you mean the answer is yes. I will explain
this idea further in next days or weeks.

Hi,

2014-01-31 Vaclav Petras <wenzeslaus@gmail.com>:

Hi all,

I would like to apply to GSoC this year with the idea of testing framework
for GRASS. I probably don't have to explain the need for it.

This is really great. IMHO we desperately need it!

Sören suggested that he would be my mentor in case my application is
successful. I hope also that I will get the feedback from all developers,
now or in the future, because it is crucial that GRASS developers will
actually use this framework.

I would be happy to be your mentor for this project.

I described the idea shortly on Trac GSoC 2014 wiki page. I plan to include
more notes on separate page in next weeks but the basic idea should be
clear. Some discussion is also in #2105. Perhaps, the most innovative idea
is that different types of tests should be supported (e.g. Python doctest
and shell scripts), although it would be always driven form Python. For
example, it seems that doctest is very convenient for modules which has
standard input and output (see recent doctest for r.category module).

Here some suggestions, reflecting some already mentioned concepts and ideas:

I would avoid to implement tests for modules using doctests and i
would not support shell script tests at all.

Why no shell script tests?

If you use shell script tests you will not have fine granular control
of how modules are called within the script and you can't switch
on/off valgrind support to call modules. The input/output validation
must be implemented in the shell scripts itself. This will lead to
huge redundant shell code, since the validation should be done by the
test framework which is written in Python. You can not determine from
outside the script what pre- and postprocess steps are or what
location should be used for testing without parsing the scripts and
define a special shell script syntax. How do you determine that the
test failed? Using return values, parsing the script output? It is
really hard to determine afterwards at what point the shell test
failed or what the reason was without reading massive amounts of
logged output. But most important: shell script tests do not work on
windows.

I will successively rewrite all of the shell script tests that i have
written (which are about 90%) to use the new test framework and Python
unittests.

Why no doctests for modules?

Unfortunately the r.category is not a good example for a module
doctest, no syntax highlighting by default in any editor. :slight_smile:
How do you define the target location? How do you define what pre- and
postprocessing steps are, so that the test breaks if the
preprocessing/setup goes wrong? In case the preprocessing/setup fails,
all following dependent tests will fail as well, which should be
avoided.

IMHO doctests are well suited to implement tests for Python library
functions and classes that do not need any specific location/data
setup. Here a good example[1], here a bad example[2] which should be
rewritten as unittests.

For all other cases i strongly suggest to use unittests. Here an
example[3] that makes use of the class and object specific setup and
teardown concepts.

How the framework should work?

It should be possible to call tests from within grass by simply
invoking "python test.py" or "python.exe test.py" in the test suite
directory of the module.
It should be possible to invoke tests using the make system outside of
grass. Hence calling '"make tests" in a module directory will perform
all tests that are located in the modules test suite directory.
Invoking "make tests" in "lib/" will perform all library tests and so
on.

The grass test framework should provide an interface to define which
location should be used for testing. In case no location was provided,
the current location will be used in case the test was invoked from
inside grass, or the demolocation in case the make system was used.
The test framework will always create a temporary mapset in which the
test will be performed. The test framework will cleanup the temporary
files at the end, but the test developer can force the test framework
to avoid this. Any existing maps that should be used for testing must
be located in the PERMANENT mapset of the target location.

When writing unittests, the target location will be set at import
time, and so the clean up:

{{{
import grass.testsuite as testsuite
testsuite.set_target_location("nc") # Short cut for the north carolina location
testsuite.set_clean_up(True) # Can set to False to investigate the
created output
}}}

The location or mapset switch will be performed while running the
unittest. Parts of such a functionality is already implemented in the
wps-grass-bridge[4]. Hence a testsuite.init() command is needed in the
unittests scripts:
{{{
if __name__ == '__main__':
    testsuite.init()
    unittest.main()
}}}

The "make system" can simply start grass using the demolocation,
invoking python to run the tests. Location and mapset switching will
done by the test framework when init() is called.

Sorry for this huge mail, i think we better should use the trac wiki
for detailed discussion. :slight_smile:

Best regards
Soeren

[1] http://trac.osgeo.org/grass/browser/grass/trunk/lib/python/temporal/temporal_extent.py#L30
[2] http://trac.osgeo.org/grass/browser/grass/trunk/lib/python/temporal/space_time_datasets.py#L21
[3] http://trac.osgeo.org/grass/browser/grass/trunk/lib/python/temporal/unittests_register.py
[4] https://code.google.com/p/wps-grass-bridge/source/browse/trunk/gms/GrassModuleStarter.py#271

Best regards,
Vaclav

http://trac.osgeo.org/grass/wiki/GSoC/2014#TestingframeworkforGRASSGIS
http://trac.osgeo.org/grass/ticket/2105
http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.category/test_rcategory_doctest.txt