AIFDR/inasafe — pull request #214 by ingenieroariel (2012-08-04 19:42:17+00:00)
Title: Safe refactor

This pull requests deals with moving the core modules to a new 'safe' module, at the same level of the 'gui' module. This is needed for being able to bundle the core functionality in a python module and use it independently of qgis.

When working on this task, three additional changes were made to help during the refactor process, they are can be summarized in: 1. 'better handling of import errors', 2. 'quicker tests', 3. 'Adding version information when running the tests programatically'

1. Use of __import__ instead of exec for loading plugins. This leads to easier to debug import problems, and avoids silently ignoring plugins with errors.

2. Mechanism to quickly run the fast tests and optionally ignore the slow ones (currently it runs 115 tests in 10 seconds with 71% code coverage), as opposed to (142 tests in 487 seconds with 82% code coverage), the tradeoff is 50x faster for 11% less code coverage. (References #199):

```
# all tests from command line
nosetests safe

#only fast tests from command line
nosetests safe -A 'not slow'

# fast tests programatically
import safe
safe.test()

# all tests programatically, in verbose mode
import safe
safe.test(label='full', verbose=2)
```

#3. Adding version info when running tests programatically, in this case it says the last change was done jn 2012-08-04 at 19:24:32.

```
~/work/inasafe > python
Python 2.7 (r27:82500, Nov 19 2010, 13:33:38)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import safe
>>> safe.test()
Running unit tests for safe
safe version 0.5.dev20120804192432
NumPy version 1.5.1
NumPy is installed in /usr/local/Cellar/python/2.7/lib/python2.7/site-packages/numpy
Python version 2.7 (r27:82500, Nov 19 2010, 13:33:38) [GCC 4.2.1 (Apple Inc. build 5664)]
nose version 1.1.2
...................................................................SS..S...........................S..................

-----------------------------------------------------------------------------------------------------
TOTAL 3044 903 70%
-----------------------------------------------------------------------------------------------------
Ran 118 tests in 10.031s

OK (SKIP=4)

```

Results of these tests running on OSX can be found here:

https://gist.github.com/3259404

Ole, could you look at the code and see if it is what you had in mind?

Tim, I made fixes in the gui code for calling safe.api instead of safe_api and adding safe when importing 'impact_functions' but it would be great if you can run the tests for that branch in your local environment.

Thanks all, looking forward to seeing this work come to master.