File: test_support_strds.py

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (119 lines) | stat: -rw-r--r-- 3,885 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""Test t.support

(C) 2015 by 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.

:authors: Soeren Gebbert
"""

import os
import grass.pygrass.modules as pymod
import grass.temporal as tgis
from grass.gunittest.case import TestCase
from grass.gunittest.gmodules import SimpleModule


class TestSupportAbsoluteSTRDS(TestCase):
    @classmethod
    def setUpClass(cls):
        """Initiate the temporal GIS and set the region"""
        os.putenv("GRASS_OVERWRITE", "1")
        tgis.init()
        cls.use_temp_region()
        cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10)
        cls.runModule("r.mapcalc", expression="a1 = 100", overwrite=True)
        cls.runModule("r.mapcalc", expression="a2 = 200", overwrite=True)
        cls.runModule("r.mapcalc", expression="a3 = 300", overwrite=True)
        cls.runModule("r.mapcalc", expression="a4 = 400", overwrite=True)

        cls.runModule(
            "t.create",
            type="strds",
            temporaltype="absolute",
            output="A",
            title="A test",
            description="A test",
            overwrite=True,
        )

        cls.runModule(
            "t.register",
            flags="i",
            type="raster",
            input="A",
            maps="a1,a2,a3,a4",
            start="2001-01-15 12:05:45",
            increment="14 days",
            overwrite=True,
        )

    @classmethod
    def tearDownClass(cls):
        """Remove the temporary region"""
        cls.del_temp_region()
        cls.runModule("t.remove", flags="df", type="strds", inputs="A")

    def test_1_metadata(self):
        """Set title, description and aggregation"""

        title = "A new title"
        descr = "A new description"
        aggr_type = "average"
        semantic = "sum"

        self.assertModule(
            "t.support",
            input="A",
            title=title,
            description=descr,
            semantictype=semantic,
            aggr_type=aggr_type,
        )

        A = tgis.open_old_stds("A", type="strds")
        A.select()
        self.assertEqual(A.metadata.get_title(), title)
        self.assertEqual(A.metadata.get_description(), descr)
        self.assertEqual(A.metadata.get_aggregation_type(), aggr_type)
        self.assertEqual(A.base.get_semantic_type(), semantic)

    def test_2_update(self):
        """Set title, description and aggregation"""

        self.runModule("r.mapcalc", expression="a1 = 10", overwrite=True)
        self.runModule("r.mapcalc", expression="a2 = 20", overwrite=True)
        self.runModule("r.mapcalc", expression="a3 = 30", overwrite=True)
        self.runModule("r.mapcalc", expression="a4 = 40", overwrite=True)

        self.assertModule("t.support", input="A", flags="m")

        A = tgis.open_old_stds("A", type="strds")
        A.select()
        self.assertEqual(A.metadata.get_min_min(), 10)
        self.assertEqual(A.metadata.get_min_max(), 40)
        self.assertEqual(A.metadata.get_max_min(), 10)
        self.assertEqual(A.metadata.get_max_max(), 40)
        self.assertEqual(A.metadata.get_number_of_maps(), 4)

    def test_3_update(self):
        """Set title, description and aggregation"""

        self.runModule("g.remove", type="raster", name="a4", flags="f")

        self.assertModule("t.support", input="A", flags="m")

        A = tgis.open_old_stds("A", type="strds")
        A.select()
        self.assertEqual(A.metadata.get_min_min(), 10)
        self.assertEqual(A.metadata.get_min_max(), 30)
        self.assertEqual(A.metadata.get_max_min(), 10)
        self.assertEqual(A.metadata.get_max_max(), 30)
        self.assertEqual(A.metadata.get_number_of_maps(), 3)


if __name__ == "__main__":
    from grass.gunittest.main import test

    test()