File: test_gmodules.py

package info (click to toggle)
grass 7.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 135,976 kB
  • ctags: 44,148
  • sloc: ansic: 410,300; python: 166,939; cpp: 34,819; sh: 9,358; makefile: 6,618; xml: 3,551; sql: 769; lex: 519; yacc: 450; asm: 387; perl: 282; sed: 17; objc: 7
file content (94 lines) | stat: -rw-r--r-- 3,365 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-

import subprocess

from grass.gunittest.case import TestCase
from grass.gunittest.main import test
from grass.gunittest.gmodules import (call_module, CalledModuleError)

G_REGION_OUTPUT = """...
n=...
s=...
w=...
e=...
nsres=...
ewres=...
rows=...
cols=...
cells=...
"""


class TestCallModuleFunction(TestCase):

    def test_output(self):
        output = call_module('g.region', flags='pg')
        self.assertLooksLike(output, G_REGION_OUTPUT)

    def test_input_output(self):
        output = call_module('m.proj', flags='i', input='-', stdin="50.0 41.5")
        self.assertLooksLike(output, '...|...\n')

    def test_no_output(self):
        output = call_module('m.proj', flags='i', input='-', stdin="50.0 41.5",
                             capture_stdout=False)
        self.assertIsNone(output)

    def test_merge_stderr(self):
        output = call_module('m.proj', flags='i', input='-', stdin="50.0 41.5",
                             verbose=True,
                             merge_stderr=True)
        self.assertLooksLike(output, '...+proj=longlat +datum=WGS84...')
        self.assertLooksLike(output, '...|...\n')

    def test_merge_stderr_with_wrong_stdin_stderr(self):
        self.assertRaises(ValueError,
                          call_module,
                          'm.proj', flags='i', input='-', stdin="50.0 41.5",
                          verbose=True,
                          merge_stderr=True, capture_stdout=False)
        self.assertRaises(ValueError,
                          call_module,
                          'm.proj', flags='i', input='-', stdin="50.0 41.5",
                          verbose=True,
                          merge_stderr=True, capture_stderr=False)
        self.assertRaises(ValueError,
                          call_module,
                          'm.proj', flags='i', input='-', stdin="50.0 41.5",
                          verbose=True,
                          merge_stderr=True,
                          capture_stdout=False, capture_stderr=False)

    def test_wrong_module_params(self):
        self.assertRaises(CalledModuleError,
                          call_module,
                          'g.region', aabbbccc='notexist')

    def test_module_input_param_wrong(self):
        self.assertRaises(ValueError,
                          call_module,
                          'm.proj', flags='i', input='does_not_exist',
                          stdin="50.0 41.5")

    def test_missing_stdin_with_input_param(self):
        self.assertRaises(ValueError,
                          call_module,
                          'm.proj', flags='i', input='-')

    def test_wrong_usage_of_popen_like_interface(self):
        self.assertRaises(ValueError,
                          call_module,
                          'm.proj', flags='i', input='-',
                          stdin=subprocess.PIPE)
        self.assertRaises(TypeError,
                          call_module,
                          'm.proj', flags='i', input='-', stdin="50.0 41.5",
                          stdout='any_value_or_type_here')
        self.assertRaises(TypeError,
                          call_module,
                          'm.proj', flags='i', input='-', stdin="50.0 41.5",
                          stderr='any_value_or_type_here')


if __name__ == '__main__':
    test()