Skip to content

Commit

Permalink
Fix failing test_wsgi_compliance on Python 3
Browse files Browse the repository at this point in the history
The list of warnings had one ResourceWarning about an unclosed socket
object.

Fixes #11.
  • Loading branch information
mgedmin committed Oct 19, 2018
1 parent 2b00482 commit 1f3a92d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
32 changes: 16 additions & 16 deletions src/zope/server/http/tests/test_wsgiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import sys
import unittest
import warnings
from contextlib import contextmanager
from contextlib import contextmanager, closing
from io import BytesIO, StringIO

import paste.lint
Expand Down Expand Up @@ -197,22 +197,22 @@ def application(environ, start_response):

def invokeRequest(self, path='/',
return_response=False):
h = HTTPConnection(self.LOCALHOST, self.port)
h.putrequest('GET', path)
h.putheader('Accept', 'text/plain')
h.endheaders()
response = h.getresponse()
if return_response:
return response
length = int(response.getheader('Content-Length', '0'))
if length:
response_body = response.read(length)
else:
response_body = b''
with closing(HTTPConnection(self.LOCALHOST, self.port)) as h:
h.putrequest('GET', path)
h.putheader('Accept', 'text/plain')
h.endheaders()
response = h.getresponse()
if return_response:
return response
length = int(response.getheader('Content-Length', '0'))
if length:
response_body = response.read(length)
else:
response_body = b''

self.assertEqual(length, len(response_body))
self.assertEqual(length, len(response_body))

return response.status, response_body
return response.status, response_body


def testDeeperPath(self):
Expand Down Expand Up @@ -461,7 +461,7 @@ def test_wsgi_compliance(self):

with warnings.catch_warnings(record=True) as w:
self.invokeRequest("/foo")
self.assertTrue(len(w) == 0, w)
self.assertEqual(len(w), 0, [str(m) for m in w])
self.server.application = orig_app

class TestWSGIHttpServer(unittest.TestCase):
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ envlist =
coverage

[testenv]
deps =
.[test]
extras = test
commands =
zope-testrunner --test-path=src {posargs:-pvc}

[testenv:coverage]
usedevelop = true
basepython = python3.6
deps =
{[testenv]deps}
coverage
commands =
coverage run -m zope.testrunner --test-path=src {posargs:-pvc}
Expand Down

0 comments on commit 1f3a92d

Please sign in to comment.