/usr/lib/python3/dist-packages/twisted/web/test
NameSizeModeActions
__pycache__/-0755rm
injectionhelpers.py56270644editdlrm
requesthelper.py134060644editdlrm
test_agent.py1178050644editdlrm
test_cgi.py137610644editdlrm
test_client.py13720644editdlrm
test_distrib.py182880644editdlrm
test_domhelpers.py111030644editdlrm
test_error.py162100644editdlrm
test_flatten.py182590644editdlrm
test_html.py12640644editdlrm
test_http.py1365660644editdlrm
test_http2.py1099830644editdlrm
test_httpauth.py241280644editdlrm
test_http_headers.py203860644editdlrm
test_newclient.py1087510644editdlrm
test_proxy.py200920644editdlrm
test_resource.py82140644editdlrm
test_script.py37840644editdlrm
test_stan.py56670644editdlrm
test_static.py678580644editdlrm
test_tap.py109470644editdlrm
test_template.py259770644editdlrm
test_util.py139000644editdlrm
test_vhost.py79170644editdlrm
test_web.py659960644editdlrm
test_webclient.py596150644editdlrm
test_web__responses.py8770644editdlrm
test_wsgi.py782100644editdlrm
test_xml.py423570644editdlrm
test_xmlrpc.py303020644editdlrm
_util.py25680644editdlrm
__init__.py1080644editdlrm
Edit: /usr/lib/python3/dist-packages/twisted/web/test/_util.py (2568B)
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ General helpers for L{twisted.web} unit tests. """ from __future__ import division, absolute_import from twisted.internet.defer import succeed from twisted.web import server from twisted.trial.unittest import TestCase from twisted.python.failure import Failure from twisted.web._flatten import flattenString from twisted.web.error import FlattenerError 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("Unexpected return value: %r" % (result,)) class FlattenTestCase(TestCase): """ A test case that assists with testing L{twisted.web._flatten}. """ def assertFlattensTo(self, root, target): """ Assert that a root element, when flattened, is equal to a string. """ d = flattenString(None, root) d.addCallback(lambda s: self.assertEqual(s, target)) return d def assertFlattensImmediately(self, root, target): """ 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} """ results = [] it = self.assertFlattensTo(root, target) it.addBoth(results.append) # Do our best to clean it up if something goes wrong. self.addCleanup(it.cancel) if not results: self.fail("Rendering did not complete immediately.") result = results[0] if isinstance(result, Failure): result.raiseException() return results[0] def assertFlatteningRaises(self, root, exn): """ Assert flattening a root element raises a particular exception. """ d = self.assertFailure(self.assertFlattensTo(root, b''), FlattenerError) d.addCallback(lambda exc: self.assertIsInstance(exc._exception, exn)) return d __all__ = ["_render", "FlattenTestCase"]