diff options
author | Robey Pointer <robey@lag.net> | 2004-06-10 17:35:30 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2004-06-10 17:35:30 +0000 |
commit | 1144a5d3d9232535d722d9ccded40ad28dbf341d (patch) | |
tree | 0912fe9209b997d5e726903ffc5743562f0aa4d4 /tests/test_sftp.py | |
parent | 9baa2b361eb5dce72f80bac5936615853d0b2fbb (diff) |
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-57]
more unit tests
add a unit test for sending a large (1MB) file with line buffering but no
linefeeds (this triggered several bugs and inefficiencies), and another test
to verify that the write buffer is flushed on seek.
Diffstat (limited to 'tests/test_sftp.py')
-rwxr-xr-x | tests/test_sftp.py | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/test_sftp.py b/tests/test_sftp.py index b5145eaa..3ff74ed5 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -27,6 +27,7 @@ do test file operations in (so no existing files will be harmed). import sys, os import random +import logging # need a host and private-key where we have acecss HOST = os.environ.get('TEST_HOST', 'localhost') @@ -309,7 +310,29 @@ class SFTPTest (unittest.TestCase): except: pass - def test_A_lots_of_files(self): + def test_A_flush_seek(self): + """ + verify that buffered writes are automatically flushed on seek. + """ + f = sftp.open(FOLDER + '/happy.txt', 'w', 1) + try: + f.write('full line.\n') + f.write('partial') + f.seek(9, f.SEEK_SET) + f.write('?\n') + f.close() + + f = sftp.open(FOLDER + '/happy.txt', 'r') + self.assertEqual(f.readline(), 'full line?\n') + self.assertEqual(f.read(7), 'partial') + f.close() + finally: + try: + sftp.remove(FOLDER + '/happy.txt') + except: + pass + + def test_B_lots_of_files(self): """ create a bunch of files over the same session. """ @@ -326,7 +349,6 @@ class SFTPTest (unittest.TestCase): numlist = range(numfiles) while len(numlist) > 0: r = numlist[random.randint(0, len(numlist) - 1)] - print r, f = sftp.open('%s/file%d.txt' % (FOLDER, r)) self.assertEqual(f.readline(), 'this is file #%d.\n' % r) f.close() @@ -337,3 +359,22 @@ class SFTPTest (unittest.TestCase): sftp.remove('%s/file%d.txt' % (FOLDER, i)) except: pass + + def test_C_big_file(self): + """ + write a 1MB file, with no linefeeds, using line buffering. + FIXME: this is slow! what causes the slowness? + """ + kblob = (1024 * 'x') + try: + f = sftp.open('%s/hongry.txt' % FOLDER, 'w', 1) + for n in range(1024): + f.write(kblob) + if n % 128 == 0: + sys.stderr.write('.') + f.close() + sys.stderr.write(' ') + + self.assertEqual(sftp.stat('%s/hongry.txt' % FOLDER).st_size, 1024 * 1024) + finally: + sftp.remove('%s/hongry.txt' % FOLDER) |