[Python-checkins] r85953 - python/branches/py3k/Lib/test/test_httpservers.py

brett.cannon python-checkins at python.org
Sat Oct 30 01:43:42 CEST 2010


Author: brett.cannon
Date: Sat Oct 30 01:43:42 2010
New Revision: 85953

Log:
Move test_httpservers over to file context managers.

Modified:
   python/branches/py3k/Lib/test/test_httpservers.py

Modified: python/branches/py3k/Lib/test/test_httpservers.py
==============================================================================
--- python/branches/py3k/Lib/test/test_httpservers.py	(original)
+++ python/branches/py3k/Lib/test/test_httpservers.py	Sat Oct 30 01:43:42 2010
@@ -206,9 +206,8 @@
         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 @@
         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(


More information about the Python-checkins mailing list