File: test_v_db_join.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 (84 lines) | stat: -rw-r--r-- 2,727 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
"""
TEST:      test_v_db_join.py

AUTHOR(S): Stefan Blumentrath

PURPOSE:   Test for v.db.join

COPYRIGHT: (C) 2024 Stefan Blumentrath, and 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.
"""

from grass.gunittest.case import TestCase
from grass.gunittest.main import test
from grass.gunittest.gmodules import SimpleModule


class TestVDbJoin(TestCase):
    """Test v.db.join script"""

    @classmethod
    def setUpClass(cls):
        """Copy vector."""
        firestation_sql = """CREATE TABLE firestation_test_table (
        CITY text,
        some_number int,
        some_text text,
        some_double double precision,
        some_float real
        );
        INSERT INTO firestation_test VALUES
        ('Cary', 1, 'short', 1.1233445366756784345,),
        ('Apex', 2, 'longer', -111.1220390953406936354,),
        ('Garner', 3, 'short', 4.20529509802443234245,),
        ('Relaigh', 4, 'even longer than before', 32.913873948295837592,);
        """
        firestation_existing_sql = """CREATE TABLE firestation_test_table_update (
        CITY text,
        others int
        );
        INSERT INTO firestation_test_table_update VALUES
        ('Cary', 1),
        ('Apex', 2),
        ('Garner', 3),
        ('Relaigh', 4);
        """
        cls.runModule("g.copy", vector=["firestations", "test_firestations"])
        cls.runModule("db.execute", sql=firestation_sql)
        cls.runModule("db.execute", sql=firestation_existing_sql)

    @classmethod
    def tearDownClass(cls):
        """Remove copied vector data and created tables"""
        cls.runModule("g.remove", type="vector", name="test_firestations", flags="f")
        cls.runModule("db.execute", sql="DROP TABLE firestation_test_table;")
        cls.runModule("db.execute", sql="DROP TABLE firestation_test_table_update;")

    def test_join_firestations_table(self):
        """Join firestations table with new different columns"""
        module = SimpleModule(
            "v.db.join",
            map="test_firestations",
            column="CITY",
            other_table="firestation_test_table",
            other_column="CITY",
        )
        self.assertModule(module)

    def test_join_firestations_table_existing(self):
        """Join firestations table with only existing columns"""
        module = SimpleModule(
            "v.db.join",
            map="test_firestations",
            column="CITY",
            other_table="firestation_test_table_update",
            other_column="CITY",
        )
        self.assertModule(module)


if __name__ == "__main__":
    test()