def test_b_field_priority(self): '''test_b_field_priority argv > config > get_opt default > default ''' sys.argv.append('--a=3333') sys.argv.append('--newname=zzzz') sys.argv.append('--config=file://./tests/test.ini') opts.define('a.a', 'string', 'a.a', '1111') opts.define('a.b', 'string', 'a.b', '2222') opts.define('a.c', 'string', 'a.c', '5555') opts.define('a.x', 'string', 'a.x', '5555', opt_name='--newname') try: ex2 = None opts.define('a.z', 'string', 'a.x', '5555', opt_name='newname') except FeildInVaildError as ex: ex2 = ex self.assertIsInstance(ex2, FeildInVaildError, 'must except') opts.parse_opts('appname') self.assertEqual(opts.get_opt('a.a'), '3333') self.assertEqual(opts.get_opt('a.b'), '4444') self.assertEqual(opts.get_opt('a.c', '7777'), '7777') self.assertEqual(opts.get_opt('a.c'), '5555') self.assertEqual(opts.get_opt('a.x'), 'zzzz')
def main(): opts.define('{pname}.cc', 'string', 'a', '1111', help_desc='a desc') opts.define('a.a', 'string', 'a', '1111', help_desc='a desc') opts.define('a.b', 'int', 'b', 2222, help_desc='b desc') opts.define('a.c', 'int', 'c', 2222, help_desc='c desc') opts.define('d.f', 'int', 'f', 3333, help_desc='f desc') opts.parse_opts('appname') assert opts.get_opt('{pname}.cc') == '456456' assert opts.get_opt('a.a') == '1111' assert opts.get_opt('a.b') == 2222 assert opts.get_opt('a.c') == 9 assert opts.get_opt('d.f') == 22222222
def __init__(self, name): super().__init__(name) self.app_host = opts.get_opt(self.APP_HOST) self.app_port = opts.get_opt(self.APP_PORT) self.sync_timeout = opts.get_opt(self.APP_SYNC_TIMEOUT) self.res_expires = opts.get_opt(self.APP_RES_EXPIRES) self.presigned_trycount = opts.get_opt(self.APP_PRESIGNED_TRYCOUNT) self.res_maker = ResourcesMaker(self.minio_cli, self.miniio_res_bucket, self.miniio_region, self.presigned_trycount, self.res_expires, logging.getLogger('res_maker'))
def __init__(self, name): self.init_opt(name) self.broker_mode = opts.get_opt(self.BROKER_MODE) self.redis_url = opts.get_opt(self.DB_REDIS_URL) self.miniio_url = opts.get_opt(self.DB_MINIIO_URL) self.miniio_accesskey = opts.get_opt(self.DB_MINIIO_ACCESSKEY) self.miniio_secretkey = opts.get_opt(self.DB_MINIIO_SECRETKEY) self.miniio_bucket = opts.get_opt(self.DB_MINIIO_BUCKET) self.miniio_res_bucket = opts.get_opt(self.DB_MINIIO_RES_BUCKET) self.miniio_region = opts.get_opt(self.DB_MINIIO_REGION) self.redis_cli = redis.Redis.from_url(self.redis_url) self.borker = RedisBroker(self.redis_cli) if self.miniio_url.startswith('https://'): secure = True self.miniio_url = self.miniio_url[len('https://'):] else: secure = False self.miniio_url = self.miniio_url[len('http://'):] self.minio_cli = Minio( self.miniio_url, access_key=self.miniio_accesskey, secret_key=self.miniio_secretkey, # region=self.miniio_region, secure=secure, ) self.task_maker = TaskMaker(self.borker, self.minio_cli, self.miniio_bucket, self.miniio_region, logging.getLogger('taskmaker'))
def __init__(self, name): self.init_opt(name) self.zmp_in_url = opts.get_opt(self.PUSHER_ZMP_IN_URL) self.zmp_out_url = opts.get_opt(self.PUSHER_ZMP_OUT_URL)
def test_a_default_value(self): opts.define('a.a', 'string', 'a.a', '1111') opts.define('a.b', 'int', 'a.b', 2222) opts.parse_opts('appname') self.assertEqual(opts.get_opt('a.a'), '1111') self.assertEqual(opts.get_opt('a.b'), 2222)