MCPcopy
hub / github.com/pallets/werkzeug / test_app

Function test_app

src/werkzeug/testapp.py:116–176  ·  view source on GitHub ↗

Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app)

(req: Request)

Source from the content-addressed store, hash-verified

114
115@Request.application
116def test_app(req: Request) -> Response:
117 """Simple test application that dumps the environment. You can use
118 it to check if Werkzeug is working properly:
119
120 .. sourcecode:: pycon
121
122 >>> from werkzeug.serving import run_simple
123 >>> from werkzeug.testapp import test_app
124 >>> run_simple('localhost', 3000, test_app)
125 * Running on http://localhost:3000/
126
127 The application displays important information from the WSGI environment,
128 the Python interpreter and the installed libraries.
129 """
130 try:
131 import pkg_resources
132 except ImportError:
133 eggs: t.Iterable[t.Any] = ()
134 else:
135 eggs = sorted(
136 pkg_resources.working_set,
137 key=lambda x: x.project_name.lower(),
138 )
139 python_eggs = []
140 for egg in eggs:
141 try:
142 version = egg.version
143 except (ValueError, AttributeError):
144 version = "unknown"
145 python_eggs.append(
146 f"<li>{escape(egg.project_name)} <small>[{escape(version)}]</small>"
147 )
148
149 wsgi_env = []
150 sorted_environ = sorted(req.environ.items(), key=lambda x: repr(x[0]).lower())
151 for key, value in sorted_environ:
152 value = "".join(wrap(str(escape(repr(value)))))
153 wsgi_env.append(f"<tr><th>{escape(key)}<td><code>{value}</code>")
154
155 sys_path = []
156 for item, virtual, expanded in iter_sys_path():
157 css = []
158 if virtual:
159 css.append("virtual")
160 if expanded:
161 css.append("exp")
162 class_str = f' class="{" ".join(css)}"' if css else ""
163 sys_path.append(f"<li{class_str}>{escape(item)}")
164
165 context = {
166 "python_version": "<br>".join(escape(sys.version).splitlines()),
167 "platform": escape(sys.platform),
168 "os": escape(os.name),
169 "api_version": sys.api_version,
170 "byteorder": sys.byteorder,
171 "werkzeug_version": _get_werkzeug_version(),
172 "python_eggs": "\n".join(python_eggs),
173 "wsgi_env": "\n".join(wsgi_env),

Callers

nothing calls this directly

Calls 6

wrapFunction · 0.85
iter_sys_pathFunction · 0.85
_get_werkzeug_versionFunction · 0.85
appendMethod · 0.80
ResponseClass · 0.50
itemsMethod · 0.45

Tested by

no test coverage detected