瀏覽代碼

temporal modules: Better error handling in register function (trunk, https://trac.osgeo.org/grass/changeset/66525)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@66532 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 9 年之前
父節點
當前提交
2071e66993
共有 2 個文件被更改,包括 52 次插入0 次删除
  1. 18 0
      lib/python/temporal/register.py
  2. 34 0
      lib/python/temporal/testsuite/test_register_function.py

+ 18 - 0
lib/python/temporal/register.py

@@ -79,6 +79,16 @@ def register_maps_in_space_time_dataset(
         msgr.fatal(_("%s= and %s= are mutually exclusive") % ("end",
                                                               "increment"))
 
+    if end and interval:
+        msgr.fatal(_("%s= and the %s flag are mutually exclusive") % ("end",
+                                                                      "interval"))
+
+    if increment and not start:
+        msgr.fatal(_("The increment option requires the start option"))
+
+    if interval and not start:
+        msgr.fatal(_("The interval flag requires the start option"))
+
     if end and not start:
         msgr.fatal(_("Please specify %s= and %s=") % ("start_time",
                                                       "end_time"))
@@ -154,6 +164,14 @@ def register_maps_in_space_time_dataset(
 
             maplist.append(row)
 
+        if start_time_in_file is True and increment:
+            increment = None
+            msgr.warning(_("The increment option will be ignored because of time stamps in input file"))
+
+        if start_time_in_file is True and interval:
+            increment = None
+            msgr.warning(_("The interval flag will be ignored because of time stamps in input file"))
+
     num_maps = len(maplist)
     map_object_list = []
     statement = ""

+ 34 - 0
lib/python/temporal/testsuite/test_register_function.py

@@ -300,5 +300,39 @@ class TestRegisterFunctions(grass.gunittest.TestCase):
         self.assertEqual(end, 2000000)
         self.assertEqual(unit, "seconds")
 
+
+class TestRegisterFails(TestCase):
+
+    def test_error_handling_1(self):
+        # start option is missing
+        self.assertModuleFail("t.register", input="test", end='2001-01-01', maps=("a", "b"))
+
+    def test_error_handling_2(self):
+        # No input definition
+        self.assertModuleFail("t.register", input="test", start='2001-01-01')
+
+    def test_error_handling_3(self):
+        # File and maps are mutually exclusive
+        self.assertModuleFail("t.register", input="test", start='2001-01-01', maps=("a", "b"), file="maps.txt")
+
+    def test_error_handling_4(self):
+        # Increment needs start
+        self.assertModuleFail("t.register", input="test", increment="1 day", maps=("a", "b"))
+
+    def test_error_handling_5(self):
+        # Interval needs start
+        self.assertModuleFail("t.register", flags="i", input="test", maps=("a", "b"))
+
+    def test_error_handling_6(self):
+        # Increment and end are mutually exclusive
+        self.assertModuleFail("t.register", input="test", start='2001-01-01', end='2001-01-01',
+                              increment="1 day", maps=("a", "b"))
+
+    def test_error_handling_7(self):
+        # Interval and end are mutually exclusive
+        self.assertModuleFail("t.register", flags="i", input="test", start='2001-01-01', end='2001-01-01',
+                              maps=("a", "b"))
+
+
 if __name__ == '__main__':
     grass.gunittest.test()