From 4d30633457015d53baebb95d3945e1e72618e85a Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Sat, 29 May 2004 18:58:11 +0000 Subject: [project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-55] add an sftp unit test for making 100 files create 100 files on the remote server, set their mode with chmod, then verify that they're all there and contain the right data. valeriy is reporting that sometimes he's getting stuck after 20 and though i'm not seeing it, i want to add a test to try to pin it down. --- tests/test_sftp.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 5085d7a1..b5145eaa 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -26,6 +26,7 @@ do test file operations in (so no existing files will be harmed). """ import sys, os +import random # need a host and private-key where we have acecss HOST = os.environ.get('TEST_HOST', 'localhost') @@ -307,3 +308,32 @@ class SFTPTest (unittest.TestCase): sftp.remove(FOLDER + '/original.txt') except: pass + + def test_A_lots_of_files(self): + """ + create a bunch of files over the same session. + """ + numfiles = 100 + try: + for i in range(numfiles): + f = sftp.open('%s/file%d.txt' % (FOLDER, i), 'w', 1) + f.write('this is file #%d.\n' % i) + f.close() + sftp.chmod('%s/file%d.txt' % (FOLDER, i), 0660) + + # now make sure every file is there, by creating a list of filenmes + # and reading them in random order. + 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() + numlist.remove(r) + finally: + for i in range(numfiles): + try: + sftp.remove('%s/file%d.txt' % (FOLDER, i)) + except: + pass -- cgit v1.2.3