本文整理匯總了Python中config_package_app.app.config方法的典型用法代碼示例。如果您正苦於以下問題:Python app.config方法的具體用法?Python app.config怎麽用?Python app.config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類config_package_app.app
的用法示例。
在下文中一共展示了app.config方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_config_from_envvar
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_envvar(self):
env = os.environ
try:
os.environ = {}
app = flask.Flask(__name__)
try:
app.config.from_envvar('FOO_SETTINGS')
except RuntimeError as e:
self.assert_true("'FOO_SETTINGS' is not set" in str(e))
else:
self.assert_true(0, 'expected exception')
self.assert_false(app.config.from_envvar('FOO_SETTINGS', silent=True))
os.environ = {'FOO_SETTINGS': __file__.rsplit('.', 1)[0] + '.py'}
self.assert_true(app.config.from_envvar('FOO_SETTINGS'))
self.common_object_test(app)
finally:
os.environ = env
示例2: test_config_from_envvar_missing
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_envvar_missing(self):
env = os.environ
try:
os.environ = {'FOO_SETTINGS': 'missing.cfg'}
try:
app = flask.Flask(__name__)
app.config.from_envvar('FOO_SETTINGS')
except IOError as e:
msg = str(e)
self.assert_true(msg.startswith('[Errno 2] Unable to load configuration '
'file (No such file or directory):'))
self.assert_true(msg.endswith("missing.cfg'"))
else:
self.fail('expected IOError')
self.assertFalse(app.config.from_envvar('FOO_SETTINGS', silent=True))
finally:
os.environ = env
示例3: common_object_test
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def common_object_test(self, app):
self.assert_equal(app.secret_key, 'devkey')
self.assert_equal(app.config['TEST_KEY'], 'foo')
self.assert_not_in('ConfigTestCase', app.config)
示例4: test_config_from_file
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_file(self):
app = flask.Flask(__name__)
app.config.from_pyfile(__file__.rsplit('.', 1)[0] + '.py')
self.common_object_test(app)
示例5: test_config_from_object
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_object(self):
app = flask.Flask(__name__)
app.config.from_object(__name__)
self.common_object_test(app)
示例6: test_config_from_class
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_class(self):
class Base(object):
TEST_KEY = 'foo'
class Test(Base):
SECRET_KEY = 'devkey'
app = flask.Flask(__name__)
app.config.from_object(Test)
self.common_object_test(app)
示例7: test_config_missing
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_missing(self):
app = flask.Flask(__name__)
try:
app.config.from_pyfile('missing.cfg')
except IOError as e:
msg = str(e)
self.assert_true(msg.startswith('[Errno 2] Unable to load configuration '
'file (No such file or directory):'))
self.assert_true(msg.endswith("missing.cfg'"))
else:
self.assert_true(0, 'expected config')
self.assert_false(app.config.from_pyfile('missing.cfg', silent=True))
示例8: test_session_lifetime
# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_session_lifetime(self):
app = flask.Flask(__name__)
app.config['PERMANENT_SESSION_LIFETIME'] = 42
self.assert_equal(app.permanent_session_lifetime.seconds, 42)