/
usr
/
lib
/
python3
/
dist-packages
/
twisted
/
web
/
test
/
/usr/lib/python3/dist-packages/twisted/web/test
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
injectionhelpers.py
5593
0644
edit
dl
rm
requesthelper.py
15121
0644
edit
dl
rm
test_agent.py
121042
0644
edit
dl
rm
test_cgi.py
15119
0644
edit
dl
rm
test_client.py
1364
0644
edit
dl
rm
test_distrib.py
18036
0644
edit
dl
rm
test_domhelpers.py
11034
0644
edit
dl
rm
test_error.py
15946
0644
edit
dl
rm
test_flatten.py
22130
0644
edit
dl
rm
test_html.py
1222
0644
edit
dl
rm
test_http.py
155512
0644
edit
dl
rm
test_http2.py
107846
0644
edit
dl
rm
test_httpauth.py
23786
0644
edit
dl
rm
test_http_headers.py
23292
0644
edit
dl
rm
test_newclient.py
109366
0644
edit
dl
rm
test_proxy.py
20046
0644
edit
dl
rm
test_resource.py
9136
0644
edit
dl
rm
test_script.py
3814
0644
edit
dl
rm
test_soap.py
3134
0644
edit
dl
rm
test_stan.py
7252
0644
edit
dl
rm
test_static.py
68197
0644
edit
dl
rm
test_tap.py
11842
0644
edit
dl
rm
test_template.py
28841
0644
edit
dl
rm
test_util.py
15049
0644
edit
dl
rm
test_vhost.py
7736
0644
edit
dl
rm
test_web.py
69145
0644
edit
dl
rm
test_webclient.py
11792
0644
edit
dl
rm
test_web__responses.py
829
0644
edit
dl
rm
test_wsgi.py
76512
0644
edit
dl
rm
test_xml.py
42030
0644
edit
dl
rm
test_xmlrpc.py
30572
0644
edit
dl
rm
_util.py
3174
0644
edit
dl
rm
__init__.py
107
0644
edit
dl
rm
Edit:
/usr/lib/python3/dist-packages/twisted/web/test/_util.py
(3174B)
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ General helpers for L{twisted.web} unit tests. """ from typing import Type from twisted.internet.defer import Deferred, succeed from twisted.trial.unittest import SynchronousTestCase from twisted.web import server from twisted.web._flatten import flattenString from twisted.web.error import FlattenerError from twisted.web.template import Flattenable def _render(resource, request): result = resource.render(request) if isinstance(result, bytes): request.write(result) request.finish() return succeed(None) elif result is server.NOT_DONE_YET: if request.finished: return succeed(None) else: return request.notifyFinish() else: raise ValueError(f"Unexpected return value: {result!r}") class FlattenTestCase(SynchronousTestCase): """ A test case that assists with testing L{twisted.web._flatten}. """ def assertFlattensTo(self, root: Flattenable, target: bytes) -> Deferred[bytes]: """ Assert that a root element, when flattened, is equal to a string. """ def check(result: bytes) -> bytes: return self.assertEqual(result, target) # type: ignore[no-any-return] d: Deferred[bytes] = flattenString(None, root) d.addCallback(check) return d def assertFlattensImmediately(self, root: Flattenable, target: bytes) -> bytes: """ Assert that a root element, when flattened, is equal to a string, and performs no asynchronus Deferred anything. This version is more convenient in tests which wish to make multiple assertions about flattening, since it can be called multiple times without having to add multiple callbacks. @return: the result of rendering L{root}, which should be equivalent to L{target}. @rtype: L{bytes} """ return self.successResultOf(self.assertFlattensTo(root, target)) # type: ignore[no-any-return] def assertFlatteningRaises(self, root: Flattenable, exn: Type[Exception]) -> None: """ Assert flattening a root element raises a particular exception. """ failure = self.failureResultOf(self.assertFlattensTo(root, b""), FlattenerError) self.assertIsInstance(failure.value._exception, exn) def assertIsFilesystemTemporary(case, fileObj): """ Assert that C{fileObj} is a temporary file on the filesystem. @param case: A C{TestCase} instance to use to make the assertion. @raise: C{case.failureException} if C{fileObj} is not a temporary file on the filesystem. """ # The tempfile API used to create content returns an instance of a # different type depending on what platform we're running on. The point # here is to verify that the request body is in a file that's on the # filesystem. Having a fileno method that returns an int is a somewhat # close approximation of this. -exarkun case.assertIsInstance(fileObj.fileno(), int) __all__ = ["_render", "FlattenTestCase", "assertIsFilesystemTemporary"]
Save
cmd:
run