def test_load_config(self):
     filepath = '/test/'
     with mock.patch('__builtin__.execfile', side_effect=execfile_fake):
         config = load_config_from_pyfile(filepath)
         self.assertEqual(config_test['SLEEP'], config.SLEEP)
         self.assertEqual(config_test['HTTP_TIMEOUT'], config.HTTP_TIMEOUT)
         self.assertEqual(config_test['MAX_REDIRECTS'], config.MAX_REDIRECTS)
 def test_load_configfile_fail(self):
     variables = {
         'port': '8080',
         'host': 'localhost'
     }
     with patch('lib.utils.my_execfile', Mock(return_value=variables)):
         cfg = utils.load_config_from_pyfile("somepath")
     self.assertFalse(cfg == True)
Beispiel #3
0
 def test_load_configfile_successful(self):
     variables = {'PORT': '8080', 'HOST': 'localhost'}
     with patch('lib.utils.my_execfile', Mock(return_value=variables)):
         cfg = utils.load_config_from_pyfile("somepath")
     real_config = utils.Config()
     real_config.PORT = variables['PORT']
     real_config.HOST = variables['HOST']
     self.assertEqual(cfg.PORT, real_config.PORT)
     self.assertEqual(cfg.HOST, real_config.HOST)
Beispiel #4
0
 def test_load_config_from_pyfile(self):
     result = utils.load_config_from_pyfile('source/tests/test_config.py')
     self.assertEqual(result.CONF_KEY, 1)
     self.assertEqual(result.CONF_KEY_1, 'value')
     self.assertFalse(hasattr(result, 'Conf_Key_2'))
     self.assertEqual(result.CONF_KEY_THREE, {
         'value_key_1': 'value_1',
         'value_key_2': 'value_2'
     })
 def test_load_configfile_successful(self):
     variables = {
         'PORT': '8080',
         'HOST': 'localhost'
     }
     with patch('lib.utils.my_execfile', Mock(return_value=variables)):
         cfg = utils.load_config_from_pyfile("somepath")
     real_config = utils.Config()
     real_config.PORT = variables['PORT']
     real_config.HOST = variables['HOST']
     self.assertEqual(cfg.PORT, real_config.PORT)
     self.assertEqual(cfg.HOST, real_config.HOST)
Beispiel #6
0
def main(argv):
    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)))
    dictConfig(config.LOGGING)
    main_loop(config)

    return config.EXIT_CODE
def main(argv):
    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))
    )
    dictConfig(config.LOGGING)
    main_loop(config)

    return config.EXIT_CODE
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_application:
        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)
    else:
        logger.info('Stop application loop in main.')

    return exit_code
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_application:
        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)
    else:
        logger.info('Stop application loop in main.')

    return exit_code
Beispiel #10
0
 def test_load_configfile_fail(self):
     variables = {'port': '8080', 'host': 'localhost'}
     with patch('lib.utils.my_execfile', Mock(return_value=variables)):
         cfg = utils.load_config_from_pyfile("somepath")
     self.assertFalse(cfg == True)
def _load_config(args):
    return load_config_from_pyfile(
        os.path.realpath(os.path.expanduser(args.config)))
def _load_config(args):
    return load_config_from_pyfile(
        os.path.realpath(os.path.expanduser(args.config))
    )