TestPlumdMain   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 28
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B test_main_normal() 0 26 3
1
import sys
2
import time
3
import signal
4
import os.path
5
import unittest
6
import subprocess
7
8
MAX_DIFF = 8192
9
FILE_PATH = os.path.realpath(__file__)
10
PATH = os.path.dirname(FILE_PATH)
11
BIN_PATH = os.path.realpath(os.path.join(PATH, "../../../../"))
12
sys.path.insert(0, BIN_PATH)
13
from plumd.config import Conf
14
15
16
class TestPlumdMain(unittest.TestCase):
17
18
    def test_main_normal(self):
19
        """ensure system starts up, runs reader/writer plugins"""
20
        pybin = sys.executable if sys.executable else "python"
21
        pdbin = os.path.join(BIN_PATH, "plumd", "plumd", "__main__.py")
22
        cdir = os.path.join(PATH, "dat")
23
        pdir = os.path.join(PATH, "dat", "plugins")
24
        cfile = os.path.join(cdir, "main.yaml")
25
        config = Conf(cfile)
26
        config.set_conf("config.plugins", pdir, overwrite=True)
27
        config.write()
28
        args = [pybin, pdbin, "--config", cfile]
29
        dnull = open("/dev/null", 'w')
30
        #dnull = sys.stdout
31
        proc = subprocess.Popen(args, bufsize=0, executable=None, stdin=None,
32
                                stdout=dnull, stderr=dnull, preexec_fn=None,
33
                                close_fds=False, shell=False, cwd=None,
34
                                env=None, universal_newlines=False,
35
                                startupinfo=None, creationflags=0)
36
        time.sleep(0.5)
37
        os.kill(proc.pid, signal.SIGTERM)
38
        time.sleep(0.5)
39
        ret = proc.poll()
40
        while ret is None:
41
            os.kill(proc.pid, signal.SIGKILL)
42
            time.sleep(0.5)
43
        self.assertEquals(ret, 0)
44
45
46
if __name__ == '__main__':
47
    unittest.main()
48