diff options
Diffstat (limited to 'Lib/test/test_xmlrpc.py')
-rw-r--r-- | Lib/test/test_xmlrpc.py | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 624793d..3734750 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -571,25 +571,25 @@ class CGIHandlerTestCase(unittest.TestCase): self.cgi = None def test_cgi_get(self): - os.environ['REQUEST_METHOD'] = 'GET' - # if the method is GET and no request_text is given, it runs handle_get - # get sysout output - tmp = sys.stdout - sys.stdout = open(support.TESTFN, "w") - self.cgi.handle_request() - sys.stdout.close() - sys.stdout = tmp + with support.EnvironmentVarGuard() as env: + env.set('REQUEST_METHOD', 'GET') + # if the method is GET and no request_text is given, it runs handle_get + # get sysout output + tmp = sys.stdout + sys.stdout = open(support.TESTFN, "w") + self.cgi.handle_request() + sys.stdout.close() + sys.stdout = tmp - # parse Status header - handle = open(support.TESTFN, "r").read() - status = handle.split()[1] - message = ' '.join(handle.split()[2:4]) + # parse Status header + handle = open(support.TESTFN, "r").read() + status = handle.split()[1] + message = ' '.join(handle.split()[2:4]) - self.assertEqual(status, '400') - self.assertEqual(message, 'Bad Request') + self.assertEqual(status, '400') + self.assertEqual(message, 'Bad Request') - os.remove(support.TESTFN) - os.environ['REQUEST_METHOD'] = '' + os.remove(support.TESTFN) def test_cgi_xmlrpc_response(self): data = """<?xml version='1.0'?> @@ -612,11 +612,9 @@ class CGIHandlerTestCase(unittest.TestCase): sys.stdin = open("xmldata.txt", "r") sys.stdout = open(support.TESTFN, "w") - os.environ['CONTENT_LENGTH'] = str(len(data)) - try: + with support.EnvironmentVarGuard() as env: + env.set('CONTENT_LENGTH', str(len(data))) self.cgi.handle_request() - finally: - del os.environ['CONTENT_LENGTH'] sys.stdin.close() sys.stdout.close() |