Bläddra i källkod

Restore ScriptError value attribute and add relative tests, see https://trac.osgeo.org/grass/ticket/2410

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61959 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 10 år sedan
förälder
incheckning
d1672a606d
2 ändrade filer med 33 tillägg och 1 borttagningar
  1. 13 1
      lib/python/exceptions/__init__.py
  2. 20 0
      lib/python/exceptions/testsuite/test_ScriptError.py

+ 13 - 1
lib/python/exceptions/__init__.py

@@ -32,7 +32,19 @@ class ParameterError(Exception):
 
 
 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):

+ 20 - 0
lib/python/exceptions/testsuite/test_ScriptError.py

@@ -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()