コード例 #1
0
 def test_create_pidfile(self):
     pid = 1
     m_open = mock.mock_open()
     with mock.patch('source.lib.utils.open', m_open, create=True):
         create_pidfile('/file/path')
     m_open.assert_called_once_with('/file/path', 'w')
     m_open().write.assert_called_once_with(str(pid))
コード例 #2
0
 def test_write_called(self):
     pid = 1
     path = '/test/file'
     open = mock_open()
     with mock.patch('source.lib.utils.open', open, create=True):
         with mock.patch('os.getpid', mock.Mock(return_value=pid)):
             utils.create_pidfile(path)
     open().write.assert_called_once_with(str(pid))
コード例 #3
0
 def test_utils_open_called(self):
     pid = 1
     path = '/test/file'
     open = mock_open()
     with mock.patch('source.lib.utils.open', open, create=True) as utils_open_mock:
         with mock.patch('os.getpid', mock.Mock(return_value=pid)):
             utils.create_pidfile(path)
     utils_open_mock.assert_called_once_with(path, 'w')
コード例 #4
0
 def test_write_called(self):
     pid = 1
     path = '/test/file'
     open = mock_open()
     with mock.patch('source.lib.utils.open', open, create=True):
         with mock.patch('os.getpid', mock.Mock(return_value=pid)):
             utils.create_pidfile(path)
     open().write.assert_called_once_with(str(pid))
コード例 #5
0
 def test_utils_open_called(self):
     pid = 1
     path = '/test/file'
     open = mock_open()
     with mock.patch('source.lib.utils.open', open,
                     create=True) as utils_open_mock:
         with mock.patch('os.getpid', mock.Mock(return_value=pid)):
             utils.create_pidfile(path)
     utils_open_mock.assert_called_once_with(path, 'w')
コード例 #6
0
    def test_create_pidfile(self):
        pid = 42
        m_open = mock.mock_open()
        with mock.patch('source.lib.utils.open', m_open, create=True):
            with mock.patch('os.getpid', mock.Mock(return_value=pid)):
                utils.create_pidfile('/file/path')

        m_open.assert_called_once_with('/file/path', 'w')
        m_open().write.assert_called_once_with(str(pid))
コード例 #7
0
 def test_create_pidfile(self):
     pid = 42
     m_open = mock.mock_open()
     test_path = 'test_path'
     with mock.patch('source.lib.utils.open', m_open, create=True):
         with mock.patch('os.getpid', mock.Mock(return_value=pid)):
             utils.create_pidfile(test_path)
     m_open.assert_called_once_with(test_path, 'w')
     m_open().write.assert_called_once_with(str(pid))
     pass
コード例 #8
0
def main(argv):
    """
    Точка входа в приложение.

    В случае возникновения ошибки в приложении, оно засыпает на config.SLEEP_ON_FAIL секунд.

    :param argv: агрументы командной строки.
    :type argv: list
    """
    args = parse_cmd_args(argv[1:])
    if args.daemon:
        daemonize()

    if args.pidfile:
        create_pidfile(args.pidfile)

    config = load_config_from_pyfile(
        os.path.realpath(os.path.expanduser(args.config))
    )

    patch_all()

    dictConfig(config.LOGGING)

    current_thread().name = 'pusher.main'

    install_signal_handlers()

    while run:
        try:
            main_loop(config)

        except Exception as exc:
            logger.error(
                'Error in main loop. Go to sleep on {} second(s).'.format(config.SLEEP_ON_FAIL)
            )
            logger.exception(exc)

            sleep(config.SLEEP_ON_FAIL)

    logger.info('Stop application loop in main.')

    return exit_code
コード例 #9
0
 def _create_pidfile(self, m_open, m_getpid):
     with patch('__builtin__.open', m_open, create=True) as mock_open, patch('os.getpid', m_getpid):
         utils.create_pidfile('/file/path')
     return mock_open
コード例 #10
0
 def test_create_pidfile_exception(self):
     m_open = mock.Mock(side_effect=IOError("file not found"))
     with mock.patch('source.lib.utils.open', m_open, create=True):
         with self.assertRaises(IOError):
             create_pidfile('/file/path')
     assert m_open.write.not_called
コード例 #11
0
 def _create_pidfile(self, m_open, m_getpid):
     with patch('__builtin__.open', m_open,
                create=True) as mock_open, patch('os.getpid', m_getpid):
         utils.create_pidfile('/file/path')
     return mock_open