diff options
author | Walter Dörwald <walter@livinglogic.de> | 2009-04-26 21:39:21 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2009-04-26 21:39:21 (GMT) |
commit | b525e18500885731f958bd4a0114f26cea336500 (patch) | |
tree | f7ac3daec3d7e870dac64abe27c9166269a124c7 /Lib/test/test_xmlrpc.py | |
parent | 4af362905cb1e8cb56e26a51021de855798227ea (diff) | |
download | cpython-b525e18500885731f958bd4a0114f26cea336500.zip cpython-b525e18500885731f958bd4a0114f26cea336500.tar.gz cpython-b525e18500885731f958bd4a0114f26cea336500.tar.bz2 |
Merged revisions 71984 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r71984 | walter.doerwald | 2009-04-26 22:51:44 +0200 (So, 26 Apr 2009) | 2 lines
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
........
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() |