diff --git a/test/cgi/chunked_bzip2.py b/test/cgi/chunked_bzip2.py
index 0c8dfb00..3e07a174 100755
--- a/test/cgi/chunked_bzip2.py
+++ b/test/cgi/chunked_bzip2.py
@@ -2,16 +2,7 @@
import bz2, os, time
data1 = '
Two lines should be visible.
The second line.'
-
-f1 = bz2.BZ2File("/tmp/1.bz2", mode = "wb")
-f1.write(data1)
-f1.close()
-
-f = open("/tmp/1.bz2")
-cd1 = f.read()
-f.close()
-
-os.unlink("/tmp/1.bz2")
+cd1 = bz2.compress(data1)
length = len(cd1)
next_chunk = hex(length - 10)[2:]
diff --git a/test/cgi/chunked_gzip.py b/test/cgi/chunked_gzip.py
index cd20c9f8..e01f6070 100755
--- a/test/cgi/chunked_gzip.py
+++ b/test/cgi/chunked_gzip.py
@@ -1,17 +1,16 @@
#!/usr/bin/env python
-import gzip, os, time
+import gzip, os, time, StringIO
+
+output = StringIO.StringIO()
data1 = 'Two lines should be visible.
The second line.'
-f1 = gzip.GzipFile("/tmp/1.gz", mode = "wb")
+f1 = gzip.GzipFile("/tmp/1.gz", mode = "wb", fileobj=output)
f1.write(data1)
f1.close()
-f = open("/tmp/1.gz")
-cd1 = f.read()
-f.close()
-
-os.unlink("/tmp/1.gz")
+cd1 = output.getvalue()
+output.close()
length = len(cd1)
next_chunk = hex(length - 10)[2:]