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()
|