summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2010-10-29 23:43:42 (GMT)
committerBrett Cannon <bcannon@gmail.com>2010-10-29 23:43:42 (GMT)
commit105df5d75b2e8e07acc7f52477a50b2fcaa82a3c (patch)
tree7f29239283d27b5edfca79acab765f5acfebc2a6 /Lib
parentd2eca37cc5fb13ec7b1f38938296abf8f7802834 (diff)
downloadcpython-105df5d75b2e8e07acc7f52477a50b2fcaa82a3c.zip
cpython-105df5d75b2e8e07acc7f52477a50b2fcaa82a3c.tar.gz
cpython-105df5d75b2e8e07acc7f52477a50b2fcaa82a3c.tar.bz2
Move test_httpservers over to file context managers.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_httpservers.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index fa1fc59..ddb50dc 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -206,9 +206,8 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self.data = b'We are the knights who say Ni!'
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
self.tempdir_name = os.path.basename(self.tempdir)
- temp = open(os.path.join(self.tempdir, 'test'), 'wb')
- temp.write(self.data)
- temp.close()
+ with open(os.path.join(self.tempdir, 'test'), 'wb') as temp:
+ temp.write(self.data)
def tearDown(self):
try:
@@ -240,15 +239,15 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self.check_status_and_reason(response, 404)
response = self.request('/' + 'ThisDoesNotExist' + '/')
self.check_status_and_reason(response, 404)
- f = open(os.path.join(self.tempdir_name, 'index.html'), 'w')
- response = self.request('/' + self.tempdir_name + '/')
- self.check_status_and_reason(response, 200)
- if os.name == 'posix':
- # chmod won't work as expected on Windows platforms
- os.chmod(self.tempdir, 0)
- response = self.request(self.tempdir_name + '/')
- self.check_status_and_reason(response, 404)
- os.chmod(self.tempdir, 0o755)
+ with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as f:
+ response = self.request('/' + self.tempdir_name + '/')
+ self.check_status_and_reason(response, 200)
+ if os.name == 'posix':
+ # chmod won't work as expected on Windows platforms
+ os.chmod(self.tempdir, 0)
+ response = self.request(self.tempdir_name + '/')
+ self.check_status_and_reason(response, 404)
+ os.chmod(self.tempdir, 0o755)
def test_head(self):
response = self.request(