mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Move test_httpservers over to file context managers.
This commit is contained in:
parent
d2eca37cc5
commit
105df5d75b
1 changed files with 11 additions and 12 deletions
|
@ -206,9 +206,8 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
self.data = b'We are the knights who say Ni!'
|
self.data = b'We are the knights who say Ni!'
|
||||||
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
|
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
|
||||||
self.tempdir_name = os.path.basename(self.tempdir)
|
self.tempdir_name = os.path.basename(self.tempdir)
|
||||||
temp = open(os.path.join(self.tempdir, 'test'), 'wb')
|
with open(os.path.join(self.tempdir, 'test'), 'wb') as temp:
|
||||||
temp.write(self.data)
|
temp.write(self.data)
|
||||||
temp.close()
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
|
@ -240,15 +239,15 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
self.check_status_and_reason(response, 404)
|
self.check_status_and_reason(response, 404)
|
||||||
response = self.request('/' + 'ThisDoesNotExist' + '/')
|
response = self.request('/' + 'ThisDoesNotExist' + '/')
|
||||||
self.check_status_and_reason(response, 404)
|
self.check_status_and_reason(response, 404)
|
||||||
f = open(os.path.join(self.tempdir_name, 'index.html'), 'w')
|
with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as f:
|
||||||
response = self.request('/' + self.tempdir_name + '/')
|
response = self.request('/' + self.tempdir_name + '/')
|
||||||
self.check_status_and_reason(response, 200)
|
self.check_status_and_reason(response, 200)
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
# chmod won't work as expected on Windows platforms
|
# chmod won't work as expected on Windows platforms
|
||||||
os.chmod(self.tempdir, 0)
|
os.chmod(self.tempdir, 0)
|
||||||
response = self.request(self.tempdir_name + '/')
|
response = self.request(self.tempdir_name + '/')
|
||||||
self.check_status_and_reason(response, 404)
|
self.check_status_and_reason(response, 404)
|
||||||
os.chmod(self.tempdir, 0o755)
|
os.chmod(self.tempdir, 0o755)
|
||||||
|
|
||||||
def test_head(self):
|
def test_head(self):
|
||||||
response = self.request(
|
response = self.request(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue