File: test_module_assertions.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 (81 lines) | stat: -rw-r--r-- 3,177 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
# -*- coding: utf-8 -*-

import copy
import subprocess

from grass.pygrass.modules import Module
from grass.gunittest.gmodules import SimpleModule

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


class TestModuleAssertions(TestCase):
    """Test assertions using PyGRASS Module"""
    # pylint: disable=R0904

    def setUp(self):
        """Create two Module instances one correct and one with wrong map"""
        self.rinfo = Module('r.info', map='elevation', flags='g',
                            stdout_=subprocess.PIPE, run_=False, finish_=True)
        self.rinfo_wrong = copy.deepcopy(self.rinfo)
        self.wrong_map = 'does_not_exists'
        self.rinfo_wrong.inputs['map'].value = self.wrong_map

    def test_runModule(self):
        """Correct and incorrect Module used in runModule()"""
        self.runModule(self.rinfo)
        self.assertTrue(self.rinfo.outputs['stdout'].value)
        self.assertRaises(CalledModuleError, self.runModule, self.rinfo_wrong)

    def test_assertModule(self):
        """Correct and incorrect Module used in assertModule()"""
        self.assertModule(self.rinfo)
        self.assertTrue(self.rinfo.outputs['stdout'].value)
        self.assertRaises(self.failureException, self.assertModule, self.rinfo_wrong)

    def test_assertModuleFail(self):
        """Correct and incorrect Module used in assertModuleFail()"""
        self.assertModuleFail(self.rinfo_wrong)
        stderr = self.rinfo_wrong.outputs['stderr'].value
        self.assertTrue(stderr)
        self.assertIn(self.wrong_map, stderr)
        self.assertRaises(self.failureException, self.assertModuleFail, self.rinfo)


class TestSimpleModuleAssertions(TestCase):
    """Test assertions using SimpleModule"""
    # pylint: disable=R0904

    def setUp(self):
        """Create two SimpleModule instances one correct and one with wrong map
        """
        self.rinfo = SimpleModule('r.info', map='elevation', flags='g')
        self.rinfo_wrong = copy.deepcopy(self.rinfo)
        self.wrong_map = 'does_not_exists'
        self.rinfo_wrong.inputs['map'].value = self.wrong_map

    def test_runModule(self):
        """Correct and incorrect SimpleModule used in runModule()"""
        self.runModule(self.rinfo)
        self.assertTrue(self.rinfo.outputs['stdout'].value)
        self.assertRaises(CalledModuleError, self.runModule, self.rinfo_wrong)

    def test_assertModule(self):
        """Correct and incorrect SimpleModule used in assertModule()"""
        self.assertModule(self.rinfo)
        self.assertTrue(self.rinfo.outputs['stdout'].value)
        self.assertRaises(self.failureException, self.assertModule, self.rinfo_wrong)

    def test_assertModuleFail(self):
        """Correct and incorrect SimpleModule used in assertModuleFail()"""
        self.assertModuleFail(self.rinfo_wrong)
        stderr = self.rinfo_wrong.outputs['stderr'].value
        self.assertTrue(stderr)
        self.assertIn(self.wrong_map, stderr)
        self.assertRaises(self.failureException, self.assertModuleFail, self.rinfo)


if __name__ == '__main__':
    test()