Ticket #7993: wsgi-python3-7993-6.3.patch

File wsgi-python3-7993-6.3.patch, 10.7 KB (added by Gavin Panella, 4 years ago)

Third incremental patch to the wsgi-py3-7993-6 branch; apply after wsgi-python3-7993-6.2.patch.

  • twisted/web/test/test_wsgi.py

    diff --git a/twisted/web/test/test_wsgi.py b/twisted/web/test/test_wsgi.py
    index 0ee17ab..46af048 100644
    a b from twisted.python.log import addObserver, removeObserver, err 
    1919from twisted.python.failure import Failure
    2020from twisted.python.threadable import getThreadID
    2121from twisted.python.threadpool import ThreadPool
    22 from twisted.internet.defer import Deferred, gatherResults, inlineCallbacks
     22from twisted.internet.defer import Deferred, gatherResults
    2323from twisted.internet import reactor
    2424from twisted.internet.error import ConnectionLost
    2525from twisted.trial.unittest import TestCase, SkipTest
    class EnvironTests(WSGITestsMixin, TestCase): 
    323323        return gatherResults([get, post])
    324324
    325325
    326     @inlineCallbacks
    327326    def test_requestMethodIsNativeString(self):
    328327        """
    329328        The C{'REQUEST_METHOD'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    333332            request, result = self.prepareRequest()
    334333            request.requestReceived(method)
    335334            result.addCallback(self.environKeyEqual('REQUEST_METHOD', 'GET'))
    336             self.assertIsInstance((yield result), str)
     335            self.assertIsInstance(self.successResultOf(result), str)
    337336
    338337
    339338    def test_scriptName(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    368367                root, emptyChild, leaf, container, internal, unencoded])
    369368
    370369
    371     @inlineCallbacks
    372370    def test_scriptNameIsNativeString(self):
    373371        """
    374372        The C{'SCRIPT_NAME'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    377375        request, result = self.prepareRequest()
    378376        request.requestReceived(path=b"/res")
    379377        result.addCallback(self.environKeyEqual('SCRIPT_NAME', '/res'))
    380         self.assertIsInstance((yield result), str)
     378        self.assertIsInstance(self.successResultOf(result), str)
    381379
    382380        if _PY3:
    383381            # Native strings are rejected by Request.requestReceived() before
    class EnvironTests(WSGITestsMixin, TestCase): 
    388386            request, result = self.prepareRequest()
    389387            request.requestReceived(path=u"/res")
    390388            result.addCallback(self.environKeyEqual('SCRIPT_NAME', '/res'))
    391             self.assertIsInstance((yield result), str)
     389            self.assertIsInstance(self.successResultOf(result), str)
    392390
    393391
    394392    def test_pathInfo(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    427425                internalContainer, unencoded])
    428426
    429427
    430     @inlineCallbacks
    431428    def test_pathInfoIsNativeString(self):
    432429        """
    433430        The C{'PATH_INFO'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    436433        request, result = self.prepareRequest()
    437434        request.requestReceived(path=b"/res/foo/bar")
    438435        result.addCallback(self.environKeyEqual('PATH_INFO', '/foo/bar'))
    439         self.assertIsInstance((yield result), str)
     436        self.assertIsInstance(self.successResultOf(result), str)
    440437
    441438        if _PY3:
    442439            # Native strings are rejected by Request.requestReceived() before
    class EnvironTests(WSGITestsMixin, TestCase): 
    448445            request, result = self.prepareRequest()
    449446            request.requestReceived(path=u"/res/foo/bar")
    450447            result.addCallback(self.environKeyEqual('PATH_INFO', '/foo/bar'))
    451             self.assertIsInstance((yield result), str)
     448            self.assertIsInstance(self.successResultOf(result), str)
    452449
    453450
    454451    def test_queryString(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    481478            missing, empty, present, unencoded, doubleQuestion])
    482479
    483480
    484     @inlineCallbacks
    485481    def test_queryStringIsNativeString(self):
    486482        """
    487483        The C{'QUERY_STRING'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    490486        request, result = self.prepareRequest()
    491487        request.requestReceived(path=b"/res?foo=bar")
    492488        result.addCallback(self.environKeyEqual('QUERY_STRING', 'foo=bar'))
    493         self.assertIsInstance((yield result), str)
     489        self.assertIsInstance(self.successResultOf(result), str)
    494490
    495491        if _PY3:
    496492            # Native strings are rejected by Request.requestReceived() before
    class EnvironTests(WSGITestsMixin, TestCase): 
    502498            request, result = self.prepareRequest()
    503499            request.requestReceived(path=u"/res?foo=bar")
    504500            result.addCallback(self.environKeyEqual('QUERY_STRING', 'foo=bar'))
    505             self.assertIsInstance((yield result), str)
     501            self.assertIsInstance(self.successResultOf(result), str)
    506502
    507503
    508504    def test_contentType(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    521517        return gatherResults([missing, present])
    522518
    523519
    524     @inlineCallbacks
    525520    def test_contentTypeIsNativeString(self):
    526521        """
    527522        The C{'CONTENT_TYPE'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    532527            request.requestHeaders.addRawHeader(b"Content-Type", contentType)
    533528            request.requestReceived()
    534529            result.addCallback(self.environKeyEqual('CONTENT_TYPE', 'x-foo/bar'))
    535             self.assertIsInstance((yield result), str)
     530            self.assertIsInstance(self.successResultOf(result), str)
    536531
    537532
    538533    def test_contentLength(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    551546        return gatherResults([missing, present])
    552547
    553548
    554     @inlineCallbacks
    555549    def test_contentLengthIsNativeString(self):
    556550        """
    557551        The C{'CONTENT_LENGTH'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    562556            request.requestHeaders.addRawHeader(b"Content-Length", contentLength)
    563557            request.requestReceived()
    564558            result.addCallback(self.environKeyEqual('CONTENT_LENGTH', '1234'))
    565             self.assertIsInstance((yield result), str)
     559            self.assertIsInstance(self.successResultOf(result), str)
    566560
    567561
    568562    def test_serverName(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    585579        return gatherResults([missing, present])
    586580
    587581
    588     @inlineCallbacks
    589582    def test_serverNameIsNativeString(self):
    590583        """
    591584        The C{'SERVER_NAME'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    599592            request.getRequestHostname = lambda: serverName
    600593            request.requestReceived()
    601594            result.addCallback(self.environKeyEqual('SERVER_NAME', 'host.example.com'))
    602             self.assertIsInstance((yield result), str)
     595            self.assertIsInstance(self.successResultOf(result), str)
    603596
    604597
    605598    def test_serverPort(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    621614        return d
    622615
    623616
    624     @inlineCallbacks
    625617    def test_serverPortIsNativeString(self):
    626618        """
    627619        The C{'SERVER_PORT'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    630622        request, result = self.prepareRequest()
    631623        request.requestReceived()
    632624        result.addCallback(self.environKeyEqual('SERVER_PORT', '80'))
    633         self.assertIsInstance((yield result), str)
     625        self.assertIsInstance(self.successResultOf(result), str)
    634626
    635627
    636628    def test_serverProtocol(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    648640        return gatherResults([old, new])
    649641
    650642
    651     @inlineCallbacks
    652643    def test_serverProtocolIsNativeString(self):
    653644        """
    654645        The C{'SERVER_PROTOCOL'} key of the C{environ} C{dict} passed to the
    class EnvironTests(WSGITestsMixin, TestCase): 
    662653            request.write = lambda data: None
    663654            request.requestReceived(version=b"1.1")
    664655            result.addCallback(self.environKeyEqual('SERVER_PROTOCOL', '1.1'))
    665             self.assertIsInstance((yield result), str)
     656            self.assertIsInstance(self.successResultOf(result), str)
    666657
    667658
    668659    def test_remoteAddr(self):
    class EnvironTests(WSGITestsMixin, TestCase): 
    797788        return errors
    798789
    799790
    800     @inlineCallbacks
    801791    def test_wsgiErrorsExpectsOnlyNativeStringsInPython2(self):
    802792        """
    803793        The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
    class EnvironTests(WSGITestsMixin, TestCase): 
    810800
    811801        request, result = self.prepareRequest()
    812802        request.requestReceived()
    813         environ, _ = yield result
     803        environ, _ = self.successResultOf(result)
    814804        errors = environ["wsgi.errors"]
    815805
    816806        with warnings.catch_warnings(record=True) as caught:
    class EnvironTests(WSGITestsMixin, TestCase): 
    822812            str(caught[0].message))
    823813
    824814
    825     @inlineCallbacks
    826815    def test_wsgiErrorsAcceptsOnlyNativeStringsInPython3(self):
    827816        """
    828817        The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
    class EnvironTests(WSGITestsMixin, TestCase): 
    834823
    835824        request, result = self.prepareRequest()
    836825        request.requestReceived()
    837         environ, _ = yield result
     826        environ, _ = self.successResultOf(result)
    838827        errors = environ["wsgi.errors"]
    839828
    840829        error = self.assertRaises(TypeError, errors.write, b"fred")
    class StartResponseTests(WSGITestsMixin, TestCase): 
    13271316        return self.assertFailure(result, TypeError).addCallback(checkMessage)
    13281317
    13291318
    1330     @inlineCallbacks
    13311319    def test_headersShouldBePlainList(self):
    13321320        """
    13331321        According to PEP-3333, the headers passed to the I{start_response}
    class StartResponseTests(WSGITestsMixin, TestCase): 
    13481336
    13491337        with warnings.catch_warnings(record=True) as caught:
    13501338            request.requestReceived()
    1351             yield result
     1339            result = self.successResultOf(result)
    13521340        self.assertEqual(1, len(caught))
    13531341        self.assertEqual(RuntimeWarning, caught[0].category)
    13541342        self.assertEqual(
    class StartResponseTests(WSGITestsMixin, TestCase): 
    13781366        return self.assertFailure(result, TypeError).addCallback(checkMessage)
    13791367
    13801368
    1381     @inlineCallbacks
    13821369    def test_headersShouldEachBeTuple(self):
    13831370        """
    13841371        According to PEP-3333, each header passed to the I{start_response}
    class StartResponseTests(WSGITestsMixin, TestCase): 
    13991386
    14001387        with warnings.catch_warnings(record=True) as caught:
    14011388            request.requestReceived()
    1402             yield result
     1389            result = self.successResultOf(result)
    14031390        self.assertEqual(1, len(caught))
    14041391        self.assertEqual(RuntimeWarning, caught[0].category)
    14051392        self.assertEqual(