コード例 #1
0
ファイル: test_util.py プロジェクト: pombredanne/heyu
    def test_alt_workdir(self, mock_open, mock_getpid, mock_close, mock_dup2,
                         mock_os_open, mock_setsid, mock_exit, mock_fork,
                         mock_umask, mock_chdir):
        util.daemonize(workdir='/work/dir')

        mock_chdir.assert_called_once_with('/work/dir')
        mock_umask.assert_called_once_with(0)
        mock_fork.assert_has_calls([mock.call(), mock.call()])
        self.assertFalse(mock_exit.called)
        mock_setsid.assert_called_once_with()
        mock_os_open.assert_called_once_with(os.devnull, os.O_RDWR)
        mock_dup2.assert_has_calls([
            mock.call(3, 0),
            mock.call(3, 1),
            mock.call(3, 2),
        ])
        mock_close.assert_called_once_with(3)
        self.assertFalse(mock_getpid.called)
        self.assertFalse(mock_open.called)
コード例 #2
0
ファイル: test_util.py プロジェクト: pombredanne/heyu
    def test_with_pidfile(self, mock_open, mock_getpid, mock_close, mock_dup2,
                          mock_os_open, mock_setsid, mock_exit, mock_fork,
                          mock_umask, mock_chdir):
        util.daemonize(pidfile='/some/file.pid')

        mock_chdir.assert_called_once_with('/')
        mock_umask.assert_called_once_with(0)
        mock_fork.assert_has_calls([mock.call(), mock.call()])
        self.assertFalse(mock_exit.called)
        mock_setsid.assert_called_once_with()
        mock_os_open.assert_called_once_with(os.devnull, os.O_RDWR)
        mock_dup2.assert_has_calls([
            mock.call(3, 0),
            mock.call(3, 1),
            mock.call(3, 2),
        ])
        mock_close.assert_called_once_with(3)
        mock_getpid.assert_called_once_with()
        mock_open.assert_called_once_with('/some/file.pid', 'w')
        self.assertEqual(mock_open.return_value.contents, '1234\n')
コード例 #3
0
ファイル: hub.py プロジェクト: klmitch/heyu
def _normalize_args(args):
    """
    Pre-process arguments before calling ``start_hub()``.  This
    ensures the arguments are normalized.

    :params args: The values of the command line arguments for
                  normalization.
    """

    # If no endpoints have been set up, set up the defaults
    if not args.endpoints:
        args.endpoints = [('', util.HEYU_PORT)]
        if socket.has_ipv6:
            args.endpoints.append(('::', util.HEYU_PORT))
    else:
        # Resolve the endpoints
        args.endpoints = [util.parse_hub(endpoint)
                          for endpoint in args.endpoints]

    # Go into the background if requested, and not in debug mode
    if args.daemon and not args.debug:
        util.daemonize(pidfile=args.pid_file)