[GRASS-SVN] r61959 - in grass/trunk/lib/python/exceptions: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 14 22:06:12 PDT 2014
Author: zarch
Date: 2014-09-14 22:06:12 -0700 (Sun, 14 Sep 2014)
New Revision: 61959
Added:
grass/trunk/lib/python/exceptions/testsuite/
grass/trunk/lib/python/exceptions/testsuite/test_ScriptError.py
Modified:
grass/trunk/lib/python/exceptions/__init__.py
Log:
Restore ScriptError value attribute and add relative tests, see #2410
Modified: grass/trunk/lib/python/exceptions/__init__.py
===================================================================
--- grass/trunk/lib/python/exceptions/__init__.py 2014-09-15 03:34:14 UTC (rev 61958)
+++ grass/trunk/lib/python/exceptions/__init__.py 2014-09-15 05:06:12 UTC (rev 61959)
@@ -32,9 +32,21 @@
class ScriptError(Exception):
- pass
+ """Raised during script execution. ::
+ >>> error = ScriptError('My error message!')
+ >>> error.value
+ 'My error message!'
+ >>> print(error)
+ My error message!
+ """
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return str(self.value)
+
+
class Usage(Exception):
pass
Added: grass/trunk/lib/python/exceptions/testsuite/test_ScriptError.py
===================================================================
--- grass/trunk/lib/python/exceptions/testsuite/test_ScriptError.py (rev 0)
+++ grass/trunk/lib/python/exceptions/testsuite/test_ScriptError.py 2014-09-15 05:06:12 UTC (rev 61959)
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from grass.gunittest import TestCase, test
+from grass.exceptions import ScriptError
+
+
+class TestTextAssertions(TestCase):
+
+ def test_get_value(self):
+ error = ScriptError('error')
+ self.assertEqual('error', error.value)
+
+ def test_str(self):
+ error = ScriptError('error')
+ self.assertEqual('error', str(error))
+ error = ScriptError(12)
+ self.assertEqual('12', str(error))
+
+
+if __name__ == '__main__':
+ test()
More information about the grass-commit
mailing list