summaryrefslogtreecommitdiff
path: root/tests/test_runner.py
blob: 5ed26cd9e0714ec5cab9af4b959020264be3ebe9 (plain)
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
#!/usr/bin/python

import os
import sys
import StringIO
import unittest
from mic.utils import runner

def suite():
    return unittest.makeSuite(RunnerTest)

class RunnerTest(unittest.TestCase):

    def setUp(self):
        self.stdout = sys.stdout
        self.stderr = sys.stderr
        sys.stdout = StringIO.StringIO()
        sys.stderr = StringIO.StringIO()

    def tearDown(self):
        sys.stdout = self.stdout
        sys.stderr = self.stderr

    def testRuntoolCatch0(self):
        (rc, out) = runner.runtool("echo hello", catch=0)
        self.assertEqual(0, rc)
        self.assertEqual('', out)
        (rc, out) = runner.runtool("echo hello >&2", catch=0)
        self.assertEqual(0, rc)
        self.assertEqual('', out)

    def testRuntoolCatch1(self):
        (rc, out) = runner.runtool("echo hello", catch=1)
        self.assertEqual(0, rc)
        self.assertEqual("hello\n", out)

    def testRuntoolCatch2(self):
        (rc, out) = runner.runtool("echo hello >&2", catch=2)
        self.assertEqual(0, rc)
        self.assertEqual("hello\n", out)

    def testRuntoolCatch3(self):
        (rc, out) = runner.runtool("echo hello", catch=3)
        self.assertEqual(0, rc)
        self.assertEqual("hello\n", out)
        (rc, out) = runner.runtool("echo hello >&2", catch=2)
        self.assertEqual(0, rc)
        self.assertEqual("hello\n", out)

if __name__ == "__main__":
    unittest.main()