Esempio n. 1
0
    def test_expected_string_returned_when_process_is_already_running(self):
        ProcessControl(PIDFILE).create_process(["python", TESTSCRIPT])
        returnedValue = ProcessControl(PIDFILE).create_process(
            ["python", TESTSCRIPT])
        expectedValue = "Process already running"

        self.assertEqual(returnedValue, expectedValue)
Esempio n. 2
0
 def setUp(self):
     self.pidData = {
         "pid": 1111,
         "creationTime": 1520718076.0,
         "cid": "01bb03aef04386e980c57466d2f0b013"
     }
     ProcessControl(PIDFILE).__write_pid_file__(self.pidData)
Esempio n. 3
0
def process_status(args):
    running = ProcessControl(PIDFILE).process_is_running()

    if running:
        sys.stdout.write("Hermercury process is running\n")
    elif running is False:
        sys.stdout.write("No hermercury process running\n")
Esempio n. 4
0
    def test_file_is_written_as_expected(self):
        ProcessControl(PIDFILE).__write_pid_file__(self.pidData)

        with open(PIDFILE, "r") as fileObj:
            pidData = json.load(fileObj)
            fileObj.close()

        self.assertEqual(self.pidData, pidData)
Esempio n. 5
0
def start_background_process(args):
    frequency = str(args.frequency)
    pythonExePath = helper_functions.find_python_executable()
    userMessage = ProcessControl(PIDFILE).create_process([
        pythonExePath,
        os.path.abspath(__file__), "start", "-f", frequency, "--foreground"
    ])
    sys.stdout.write("{}\n".format(userMessage))
Esempio n. 6
0
class TestCreatePidData(unittest.TestCase):
    def setUp(self):
        self.instance = ProcessControl(PIDFILE)
        self.instance.create_process(["python", TESTSCRIPT])
        self.pidData = self.instance.__read_pid_file__()

    def tearDown(self):
        self.instance.stop_process()

    def test_dictionary_is_returned(self):

        self.assertIsInstance(self.pidData, dict)

    def value_are_expected_data_types(self):
        pid = self.pidData["pid"]
        creationTime = self.pidData["creationTime"]
        cid = self.pidData["cid"]

        self.assertIsInstance(pid, int)
        self.assertIsInstance(creationTime, float)
        self.assertIsInstance(cid, str)
Esempio n. 7
0
    def test_process_is_terminated(self):
        instance = ProcessControl(PIDFILE)
        instance.stop_process()
        isRunning = instance.process_is_running()

        self.assertFalse(isRunning)
Esempio n. 8
0
 def setUp(self):
     ProcessControl(PIDFILE).stop_process()
     ProcessControl(PIDFILE).create_process(["python", TESTSCRIPT])
Esempio n. 9
0
    def test_expected_string_returned_when_process_is_created(self):
        returnedValue = ProcessControl(PIDFILE).create_process(
            ["python", TESTSCRIPT])
        expectedValue = "Process started"

        self.assertEqual(returnedValue, expectedValue)
Esempio n. 10
0
    def test_proccess_is_created(self):
        instance = ProcessControl(PIDFILE)
        instance.create_process(["python", TESTSCRIPT])
        isRunning = instance.process_is_running()

        self.assertTrue(isRunning)
Esempio n. 11
0
 def tearDown(self):
     os.remove(PIDFILE)
     ProcessControl(PIDFILE).stop_process()
Esempio n. 12
0
def stop_background_process(args):
    userMessage = ProcessControl(PIDFILE).stop_process()
    sys.stdout.write("{}\n".format(userMessage))
Esempio n. 13
0
 def setUp(self):
     self.instance = ProcessControl(PIDFILE)
     self.instance.create_process(["python", TESTSCRIPT])
     self.pidData = self.instance.__read_pid_file__()
Esempio n. 14
0
class TestProcessIsRunning(unittest.TestCase):
    def setUp(self):
        self.instance = ProcessControl(PIDFILE)
        self.instance.create_process(["python", TESTSCRIPT])
        self.pidData = self.instance.__read_pid_file__()

    def test_true_is_returned_when_process_is_running(self):
        returnedValue = self.instance.process_is_running()

        self.assertTrue(returnedValue)

    def test_false_is_returned_when_pid_isnt_running(self):
        self.instance.stop_process()
        returnedValue = self.instance.process_is_running()

        self.assertFalse(returnedValue)

    def test_false_is_returned_when_pid_is_running_but_cid_dont_match(self):
        self.pidData["cid"] = "01"
        self.instance.__write_pid_file__(self.pidData)

        returnedValue = self.instance.process_is_running()

        self.assertFalse(returnedValue)

    def test_false_is_returned_when_pid_file_doesnt_exist(self):
        self.instance.stop_process()
        os.remove(PIDFILE)
        returnedValue = self.instance.process_is_running()

        self.assertFalse(returnedValue)
Esempio n. 15
0
    def test_expected_string_returned_when_process_is_terminated(self):
        returnedValue = ProcessControl(PIDFILE).stop_process()
        expectedValue = "Process terminated"

        self.assertEqual(returnedValue, expectedValue)
Esempio n. 16
0
    def test_expected_string_returned_when_process_is_not_running(self):
        ProcessControl(PIDFILE).stop_process()
        returnedValue = ProcessControl(PIDFILE).stop_process()
        expectedValue = "Process not running"

        self.assertEqual(returnedValue, expectedValue)
Esempio n. 17
0
    def test_file_is_successfully_read(self):
        pidData = ProcessControl(PIDFILE).__read_pid_file__()

        self.assertEqual(self.pidData, pidData)