add text parameter to config.from_file

This commit is contained in:
AntoineMath 2023-02-22 14:40:49 +01:00 committed by David Lord
parent 4c288bc97e
commit b10b6d4af1
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
4 changed files with 23 additions and 5 deletions

2
tests/static/config.toml Normal file
View file

@ -0,0 +1,2 @@
TEST_KEY="foo"
SECRET_KEY="config"

View file

@ -6,7 +6,6 @@ import pytest
import flask
# config keys used for the TestConfig
TEST_KEY = "foo"
SECRET_KEY = "config"
@ -30,13 +29,23 @@ def test_config_from_object():
common_object_test(app)
def test_config_from_file():
def test_config_from_file_json():
app = flask.Flask(__name__)
current_dir = os.path.dirname(os.path.abspath(__file__))
app.config.from_file(os.path.join(current_dir, "static", "config.json"), json.load)
common_object_test(app)
def test_config_from_file_toml():
tomllib = pytest.importorskip("tomllib", reason="tomllib added in 3.11")
app = flask.Flask(__name__)
current_dir = os.path.dirname(os.path.abspath(__file__))
app.config.from_file(
os.path.join(current_dir, "static", "config.toml"), tomllib.load, text=False
)
common_object_test(app)
def test_from_prefixed_env(monkeypatch):
monkeypatch.setenv("FLASK_STRING", "value")
monkeypatch.setenv("FLASK_BOOL", "true")