Skip to content
Myr

Allow mode='rt' on open_resource() helper

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by icreatedanaccount · committed by David Lord · parent 05a4e15 · Browse files · 2 files+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−0 removed

  • tests:+25 added−0 removed
  • other:+2 added−0 removed

2 files+27 added−0 removed

modified:flask/helpers.py+2 added
1053 unmodified lines
1054 :param resource: the name of the resource. To access resources within1055 subfolders use forward slashes as separator.1056 :param mode: resource file opening mode, default is 'rb'.1057 """1058 if mode == 'rt':1059 mode = 'r'1060 if mode not in ("r", "rb"):1061 raise ValueError("Resources can only be opened for reading")1062 return open(os.path.join(self.root_path, resource), mode)1063
40 unmodified lines
modified:tests/test_helpers.py+25 added
1012 unmodified lines
1013 with pytest.raises(NotFound):1014 print(flask.safe_join(*args))1015101610171018class TestHelpers(object):1019 @pytest.mark.parametrize(1020 "debug, expected_flag, expected_default_flag",1021 [
38 unmodified lines
1060 rv = flask.helpers.make_response("Hello")1061 assert rv.status_code == 2001062 assert rv.data == b"Hello"1063 assert rv.mimetype == "text/html"10641065 @pytest.mark.parametrize('mode', [1066 'r',1067 'rb',1068 'rt'1069 ])1070 def test_open_resource(self, mode):1071 app = flask.Flask(__name__)1072 with app.open_resource('static/index.html', mode) as f:1073 assert '<h1>Hello World!</h1>' in str(f.read())10741075 @pytest.mark.parametrize('mode', [1076 'w',1077 'x',1078 'a',1079 'b',1080 't',1081 '+'1082 ])1083 def test_open_resource_exceptions(self, mode):1084 app = flask.Flask(__name__)1085 with pytest.raises(ValueError):1086 app.open_resource('static/index.html', mode)1087