Esempio n. 1
0
    def test_main_foreground_command(self):
        conf = {'PID_FILE': '/tmp/pid'}

        with patch('kobo.worker.main.main_loop') as main_loop_mock:
            with patch.object(main.kobo.process, 'daemonize') as daemonize_mock:
                with patch.object(main.os, 'kill') as kill_mock:
                    with patch.object(main.sys, 'exit') as exit_mock:
                        main.main(conf, argv=['--foreground'])

                        exit_mock.assert_not_called()
                        kill_mock.assert_not_called()
                        daemonize_mock.assert_not_called()
                        main_loop_mock.assert_called_once_with(conf, foreground=True)
Esempio n. 2
0
    def test_main_pid_file_command(self):
        with patch.object(main.kobo.process, 'daemonize') as daemonize_mock:
            with patch.object(main.os, 'kill') as kill_mock:
                with patch.object(main.sys, 'exit') as exit_mock:
                    main.main({}, argv=['--pid-file', '/tmp/pid'])

                    exit_mock.assert_not_called()
                    kill_mock.assert_not_called()
                    daemonize_mock.assert_called_once_with(
                        main.main_loop,
                        conf={},
                        daemon_pid_file='/tmp/pid',
                        foreground=False,
                    )
Esempio n. 3
0
    def test_main_kill_command(self):
        with tempfile.NamedTemporaryFile('r+') as temp_file:
            temp_file.write('999')
            temp_file.flush()

            with patch.object(main.kobo.process, 'daemonize') as daemonize_mock:
                with patch.object(main.os, 'kill') as kill_mock:
                    with patch.object(main.sys, 'exit') as exit_mock:
                        main.main({}, argv=['--pid-file', temp_file.name, '--kill'])

                        exit_mock.assert_called_once_with(0)
                        kill_mock.assert_called_once_with(999, 15)
                        # since exit is mocked and don't exits the program daemonize will be called.
                        daemonize_mock.assert_called_once()
Esempio n. 4
0
    def test_main_pid_file_command(self):
        with patch.object(main.kobo.process, 'daemonize') as daemonize_mock:
            with patch.object(main.os, 'kill') as kill_mock:
                with patch.object(main.sys, 'exit') as exit_mock:
                    main.main({}, argv=['--pid-file', '/tmp/pid'])

                    exit_mock.assert_not_called()
                    kill_mock.assert_not_called()
                    daemonize_mock.assert_called_once_with(
                        main.main_loop,
                        conf={},
                        daemon_pid_file='/tmp/pid',
                        foreground=False,
                    )
Esempio n. 5
0
    def test_main_kill_command(self):
        with tempfile.NamedTemporaryFile('r+') as temp_file:
            temp_file.write('999')
            temp_file.flush()

            with patch.object(main.kobo.process, 'daemonize') as daemonize_mock:
                with patch.object(main.os, 'kill') as kill_mock:
                    with patch.object(main.sys, 'exit') as exit_mock:
                        main.main({}, argv=['--pid-file', temp_file.name, '--kill'])

                        exit_mock.assert_called_once_with(0)
                        kill_mock.assert_called_once_with(999, 15)
                        # since exit is mocked and don't exits the program daemonize will be called.
                        daemonize_mock.assert_called_once()
Esempio n. 6
0
    def test_main_foreground_command(self):
        conf = {'PID_FILE': '/tmp/pid'}

        with patch('kobo.worker.main.main_loop') as main_loop_mock:
            with patch.object(main.kobo.process,
                              'daemonize') as daemonize_mock:
                with patch.object(main.os, 'kill') as kill_mock:
                    with patch.object(main.sys, 'exit') as exit_mock:
                        main.main(conf, argv=['--foreground'])

                        exit_mock.assert_not_called()
                        kill_mock.assert_not_called()
                        daemonize_mock.assert_not_called()
                        main_loop_mock.assert_called_once_with(conf,
                                                               foreground=True)
Esempio n. 7
0
    def test_main_with_no_commands(self):
        conf = {'PID_FILE': '/tmp/pid'}

        with patch.object(main.kobo.process, 'daemonize') as daemonize_mock:
            with patch.object(main.os, 'kill') as kill_mock:
                with patch.object(main.sys, 'exit') as exit_mock:
                    main.main(conf, argv=[])

                    exit_mock.assert_not_called()
                    kill_mock.assert_not_called()
                    daemonize_mock.assert_called_once_with(
                        main.main_loop,
                        conf=conf,
                        daemon_pid_file='/tmp/pid',
                        foreground=False,
                    )
Esempio n. 8
0
    def test_main_with_no_commands(self):
        conf = {'PID_FILE': '/tmp/pid'}

        with patch.object(main.kobo.process, 'daemonize') as daemonize_mock:
            with patch.object(main.os, 'kill') as kill_mock:
                with patch.object(main.sys, 'exit') as exit_mock:
                    main.main(conf, argv=[])

                    exit_mock.assert_not_called()
                    kill_mock.assert_not_called()
                    daemonize_mock.assert_called_once_with(
                        main.main_loop,
                        conf=conf,
                        daemon_pid_file='/tmp/pid',
                        foreground=False,
                    )