__author__ = 'dev'

import unittest
import subprocess
from utility.subprocess_dict import SubprocessDict

class TestSubprocessDict(unittest.TestCase):

    def setUp(self):
        self.__process_args = ["mplayer", "http://stream.laut.fm/skaworld"]
        self.__process_fail_args = ["mplyer", "http://stream.laut.fm/skaworld"]
        self.__subprocess_dict = SubprocessDict()

    def tearDown(self):
        self.__subprocess_dict.clear_dict()

    def test_add_process_one(self):
        self.__subprocess_dict.add_process(self.__process_args)
        tmp_dict = self.__subprocess_dict.get_process_dict()
        self.assertIsNotNone(tmp_dict)
        self.assertNotEquals(tmp_dict, {})
        self.assertIs(len(tmp_dict), 1)
        for process in tmp_dict.values():
            self.assertTrue(isinstance(process, subprocess.Popen))

    def test_add_process_three(self):
        self.__subprocess_dict.add_process(self.__process_args)
        self.__subprocess_dict.add_process(self.__process_args)
        self.__subprocess_dict.add_process(self.__process_args)
        tmp_dict = self.__subprocess_dict.get_process_dict()
        self.assertIsNotNone(tmp_dict)
        self.assertNotEquals(tmp_dict, {})
        self.assertIs(len(tmp_dict), 3)
        for process in tmp_dict.values():
            self.assertTrue(isinstance(process, subprocess.Popen))

    def test_add_process_fail_args(self):
        self.assertRaises(FileNotFoundError, self.__subprocess_dict.add_process, self.__process_fail_args)

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