summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2012-01-10 23:27:51 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2012-01-10 23:27:51 +0000
commit6b76e11fbdc9752b4a59968e2ca63978b82f990c (patch)
tree28790a8853bc17a52d6d4343bf4e066ac07b66fe /test
parent8f4af20170faf525487c69d233ef7cf065da695a (diff)
downloadpysendfile-6b76e11fbdc9752b4a59968e2ca63978b82f990c.tar.gz
reindent + little refactoring
Diffstat (limited to 'test')
-rw-r--r--test/test_sendfile.py33
1 files changed, 16 insertions, 17 deletions
diff --git a/test/test_sendfile.py b/test/test_sendfile.py
index a379c4c..65c5d33 100644
--- a/test/test_sendfile.py
+++ b/test/test_sendfile.py
@@ -47,6 +47,20 @@ def safe_remove(file):
except OSError:
pass
+def has_large_file_support():
+ # taken from Python's Lib/test/test_largefile.py
+ with open(TESTFN, 'wb', buffering=0) as f:
+ try:
+ f.seek(BIGFILE_SIZE)
+ # seeking is not enough of a test: you must write and flush too
+ f.write(_bytes('x'))
+ f.flush()
+ except (IOError, OverflowError):
+ return False
+ else:
+ return True
+
+
class Handler(asynchat.async_chat):
ac_in_buffer_size = BUFFER_LEN
ac_out_buffer_size = BUFFER_LEN
@@ -197,6 +211,7 @@ class TestSendfile(unittest.TestCase):
self.client.close()
if self.server.running:
self.server.stop()
+ self.server = None # allow garbage collection
def test_send_whole_file(self):
# normal send
@@ -501,21 +516,6 @@ def test_main():
atexit.register(cleanup)
- def has_large_file_support():
- # taken from Python's Lib/test/test_largefile.py
- f = open(TESTFN, 'wb', buffering=0)
- try:
- f.seek(BIGFILE_SIZE)
- # seeking is not enough of a test: you must write and flush too
- f.write(_bytes('x'))
- f.flush()
- except (IOError, OverflowError):
- f.close()
- return False
- else:
- f.close()
- return True
-
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(TestSendfile))
if has_large_file_support():
@@ -523,8 +523,7 @@ def test_main():
#test_suite.addTest(unittest.makeSuite(TestLargeFile))
pass
else:
- atexit.register(warnings.warn, "couldn't run large file test because "
- "filesystem does not have largefile support.", RuntimeWarning)
+ atexit.register(warnings.warn, "large files unsupported", RuntimeWarning)
cleanup()
with open(TESTFN, "wb") as f:
f.write(DATA)