[GRASS-SVN] r54413 - in grass-addons/grass7/raster/r.agent: . tests

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 27 05:58:51 PST 2012


Author: mic
Date: 2012-12-27 05:58:51 -0800 (Thu, 27 Dec 2012)
New Revision: 54413

Added:
   grass-addons/grass7/raster/r.agent/tests/
   grass-addons/grass7/raster/r.agent/tests/README
   grass-addons/grass7/raster/r.agent/tests/__init__.py
   grass-addons/grass7/raster/r.agent/tests/test_error.py
Modified:
   grass-addons/grass7/raster/r.agent/r.agent.tests.py
Log:
moved to unittest

Modified: grass-addons/grass7/raster/r.agent/r.agent.tests.py
===================================================================
--- grass-addons/grass7/raster/r.agent/r.agent.tests.py	2012-12-27 12:43:16 UTC (rev 54412)
+++ grass-addons/grass7/raster/r.agent/r.agent.tests.py	2012-12-27 13:58:51 UTC (rev 54413)
@@ -1,19 +1,4 @@
 #!/usr/bin/env python
-############################################################################
-#
-# MODULE:       r.agent.aco
-# AUTHOR(S):    michael lustenberger inofix.ch
-# PURPOSE:      r.agent.aco is used to organize ant-like agents in a raster
-#               based playground. As decribed by the Ant Colony Optimization
-#               algorithm, the ants wander around looking for attractors,
-#               marking their paths if they find any.
-# COPYRIGHT:    (C) 2011 by Michael Lustenberger and the GRASS Development Team
-#
-#               This program is free software under the GNU General Public
-#               License (>=v2). Read the file COPYING that comes with GRASS
-#               for details.
-#
-#############################################################################
 
 def dotest(function, argv):
     """Global wrapper for the individual test suits."""
@@ -34,13 +19,6 @@
         elif t == "abort":
             exit()
 
-def testError(expr, msg):
-    """Test suite for Class: Error"""
-    try:
-        raise error.DataError(expr, msg)
-    except error.DataError:
-        print "catched! all fine."
-
 def testPlayground():
     """Test suite for Class: Playground"""
     pg = playground.Playground()
@@ -81,9 +59,7 @@
     from libagent import agent
     from libagent import ant
 
-    alltests = {"error":[testError, ["Error Test Suite",
-                     "(this error is good)"]],
-                "playground":[testPlayground, []],
+    alltests = {"playground":[testPlayground, []],
                 "world":[testWorld, []],
                 "aco":[testACO, []],
                 "Agent":[testAgent, [1]],

Added: grass-addons/grass7/raster/r.agent/tests/README
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/README	                        (rev 0)
+++ grass-addons/grass7/raster/r.agent/tests/README	2012-12-27 13:58:51 UTC (rev 54413)
@@ -0,0 +1,16 @@
+README file for libagent's test suite
+
+This test cases are intended to contain all the tests for
+libagent and to be usable with python 2.7 and higher, resp.
+also via the separate unittest2 available as backport for python
+2.3-2.6 too. At the moment I am working on a 2.6er system but
+e.g. by adapting the respective imports I expect it to work
+on 2.7 too..
+
+To invoke e.g. the error tests only, from the topmost directory
+level (i.e. r.agent) issue
+ user at py2.6host:~/r.agent$ unit2 discover -v -p "test_error.py"
+or
+ user at py2.7host:~/r.agent$ unittest discover -v -p "test_error.py"
+respectively (consult "-h" for help).
+

Added: grass-addons/grass7/raster/r.agent/tests/__init__.py
===================================================================
Added: grass-addons/grass7/raster/r.agent/tests/test_error.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_error.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.agent/tests/test_error.py	2012-12-27 13:58:51 UTC (rev 54413)
@@ -0,0 +1,32 @@
+
+import unittest2 as unittest
+#import unittest
+
+from libagent import error
+
+class TestOurExceptions(unittest.TestCase):
+#    def setUp(self):
+
+    def raise_base(context, message):
+        raise error.Error(context, message)
+
+    def raise_env(context, message):
+        raise error.EnvError(context, message)
+
+    def raise_data(context, message):
+        raise error.DataError(context, message)
+
+    def test_error(self):
+        self.assertRaises(error.Error, self.raise_base, ("tests", "base"))
+
+    def test_enverror(self):
+        self.assertRaises(error.Error, self.raise_base, ("tests", "env"))
+        self.assertRaises(error.EnvError, self.raise_env, ("tests", "env"))
+
+    def test_dataerror(self):
+        self.assertRaises(error.Error, self.raise_base, ("tests", "data"))
+        self.assertRaises(error.DataError, self.raise_data, ("tests", "data"))
+
+#    def tearDown(self):
+
+



More information about the grass-commit mailing list